Linux system management and maintenance - tar command

  
 

1. Function Description tar is an archiving tool that is often used under Linux. It is a file or directory that is packaged and archived into one file, but it is not compressed. The format is as follows: tar [main option + auxiliary options] file or directory tar command options are many, here are some of the main options that are often used, as shown in Table 4.31. Table 4.31 Main Options and Descriptions of the tar Command

Main Option Meaning -c Create a new file -r Append the file to be archived to the end of the archive file -t List the archived files in the archive file -x Restores a file from a packaged archive file -u Updates the archive file. The details of the original file accessibility options in the file are replaced with the new file as shown in Table 4.32. Table 4.32 Auxiliary Options and Descriptions of the tar Command

Auxiliary Options Meaning -z Invoke the gzip command to compress/decompress files during file packaging -w When restoring files, set the modification time of all files For the current time -j call the bzip2 command to compress/decompress the file during the file packaging process -Z call the compress command to filter the file -f “-f” option followed by the file storage device, the default is the disk, you need to specify the file File name; if it is a tape, just specify the tape device name. Note that you can't follow any other options after the "-f” option, that is, “-f” must be the last option of the tar command -v specifies the name of each archive file to be displayed during the creation of the archive file - p During the file archiving process, keep the properties of the file unchanged -N “yyyy/mm/dd” Files after the specified date will be packaged into the archive file --exclude file During the packaging process, will not Specify file file packaging 2. For example, (1) package all the files in the /etc directory, and display the packaged detailed files. Set the package file name to etc.tar and save the file to the /opt directory. [root@dbbackup oracle]#tar -cvf /opt/etc.tar /etc The file name here is "etc.tar"; the name is taken by ourselves, and the archive file packaged by tar command on Linux is generally used. Tar is used as the logo. (2) Package and compress all the files in the /etc directory, then display the packaged detailed file, set the package file name to etc.tar.gz, and save the file to the /opt directory. [root@dbbackup oracle]# tar -zcvf /opt/etc.tar.gz /etc[root@dbbackup oracle]#tar -jcvf /opt/etc.tar.bz2 /etc“zcvf”Options are called after the package is complete The gzip command compresses the archive file. The file name here is “etc.tar.gz”, which is also taken by us. “.tar” indicates that it is packaged with the tar command. “.gz” means that the gzip command is called. Compressed. Similarly, the “jcvf” option indicates that the bzip2 command is used to compress the archive file after the package is completed. The file naming identifier “<quo;.bz2” indicates that the bzip2 command was invoked for compression. There is no hard and fast rule for the name of the archive file. The naming rules used above can easily let us know the type of the file and the corresponding decompression method. Because the compression method is different, the decompression method is different. At the same time, this rule is also a hidden rule that everyone has acquiesced. If you don't like this rule, you can name the file as you like. (3) Check the contents of the /opt/etc.tar.gz archive above. [root@dbbackup oracle]#tar -ztvf /opt/etc.tar.gz[root@dbbackup oracle]#tar -jtvf /opt/etc.tar.gz

Note“etc.tar.gz&rdquo There may be many files, and one screen cannot be displayed. You can use the more command, for example, tar –zxvf /opt/etc.tar.gz

Copyright © Windows knowledge All Rights Reserved