This is the 28th day of my participation in the August Text Challenge.More challenges in August

The tar command

Tar creates files for files and directories. With tar, users can create files for a particular file (backup files), change files within the file, or add new files to the file.

Tar was originally used to create files on magnetic tape. Now, users can create files on any device, such as a floppy disk.

Using tar, you can package a large number of files and directories into a single file, which is useful for backing up files or combining several files into a single file for easy network transfer.

Tar on Linux is the GNU version.

Syntax: tar [primary + secondary] file or directory

When using this command, the primary option is mandatory and tells tar what to do, and the secondary option is auxiliary and optional.

Primary option:

  • C Create new archive files. Select this option if the user wants to back up a directory or files.
  • R Appends the file to be archived to the end of the file. For example, after you have backed up files, you can use this option to add the forgotten directories or files to the backup files.
  • T Lists the contents of the archive file to see which files have been backed up.
  • U Update files. That is, replace the original backup file with the new file, and if the file to be updated is not found in the backup file, append it to the end of the backup file.
  • X frees files from archive files.

Auxiliary options:

  • B This parameter is set for tape drives. This is followed by a number indicating the size of the block. The default value is 20 (20 x 512 bytes).
  • F Use archive files or devices. This option is usually mandatory.
  • K Saves existing files. For example, when we restore a certain file, we will not overwrite the same file during the restoration process.
  • When restoring files, M sets the modification time of all files to now.
  • M Creates multivolume archive files that can be stored on several disks.
  • V Reports the file information processed by the TAR in detail. Without this option, tar does not report file information.
  • W Ask for confirmation at every step.
  • Z Use gzip to compress/uncompress files. This option can be used to compress files, but must be used to uncompress files during restoration.

Gzip command

Reducing file size has two obvious benefits. One is that it reduces storage space, and the other is that when transferring files over the network, it reduces transfer time.

Gzip is a command used to compress and decompress files in Linux. It is convenient and easy to use.

Syntax: gzip [option] File name for compression (uncompression)

The meaning of each choice:

  • C writes output to standard output and keeps the original file.
  • D Decompress the compressed file.
  • L For each compressed file, display the following fields:
    • Size of compressed file
    • Size of an uncompressed file
    • Compression ratio
    • Name of the uncompressed file
  • R recursively finds the specified directory and compresses or uncompresses all files in it.
  • T test to check whether the compressed file is complete.
  • V displays file name and compression ratio for each compressed and uncompressed file.
  • Num Specifies the number num to adjust the compression speed. -1 or –fast indicates the fastest compression method (low compression ratio), and -9 or –best indicates the slowest compression method (high compression ratio). The default value is 6.

The uniq command

A file may be processed with duplicate lines in its output file.

For example, after merging two files using the cat command and then sorting them using the sort command, duplicate lines may occur. You can then use the uniq command to remove these duplicate lines from the output file, leaving only a unique sample of each record.

Syntax: uniq [option] file

Description: This command reads the input file and compares adjacent lines. Under normal circumstances, the second and subsequent repeated lines are deleted, and line comparisons are made according to the collating sequence of the character set used. The result of the command is written to the output file. The input and output files must be different. If the input file is represented by a “-“, it is read from standard input.

The meanings of the options in the command are as follows:

  • C Displays the output by adding the number of times the line appears in the file to the beginning of each line. It replaces the -u and -d options.
  • D displays only duplicate lines.
  • U Only lines that do not repeat in a file are displayed.
  • N The first n fields are ignored along with the whitespace before each field. A field is a non-space, non-tab string separated by tabs and Spaces (the fields are numbered from 0). +n The first n characters are ignored and the preceding characters are skipped (characters are numbered from 0).
  • F n is the same as -n, where n is the number of fields.
  • S n is the same as +n, where n is the number of characters.

Tar -cvf tutorial.tar tutorial/ // Create an archive C: C is short for create, "create". V: V is short for verbose, indicating redundancy. Details of the operation are displayed. F: F is short for file. Specify archive files. TXT file e2. TXT file e3. TXT -rvf: adds files to the archive -xvf: unzips archive gzip and bzip2 Command: compresses archive gzip: is commonly used. Bzip2: Not that often. Bzip2 has a higher compression rate than GZIP, but is more time consuming. Gz tutorial/ /-zcvf: archive, then archive with gzip. Tar -zxvf tutorial.tar.gz //-jcvf: archive, then archive with gzip. Zcat, zmore, zless: Directly displays the contents of files compressed with gzip unzip and unrar commands: Sudo apt-get install unzip unzip archive.zip unzip -l archive.zip sudo apt-get install zip zip -r Archive.zip archive/unrar: Sudo apt-get install unrar unrar e archive.rar // e This option does not start with - unrar L archive.rar //Copy the code