use the tar command

tarIt is one of the very commonly used commands in Unix and Linux systems. It can pack multiple files and directories into an archive file, and supports compression and decompression functions. In this article, we'll cover tarcommon usage and parameters of the command.

Pack files and directories as .tar archives

To pack files or directories into an archive, use the following command:

tar -cvf archive.tar file1 file2 dir/ 

Among them -c, means to create an archive file, -vmeans to display detailed information, -fmeans to specify the archive file name. The above command will pack all the files and subdirectories under file1the , file2and directory into a file named .dirarchive.tar

unpack

To unpack an archive, use the following command:

tar -xvf archive.tar 

This command will archive.tarunpack the file into the current directory. If you want to unpack the archive to a specified directory, you can use -Cthe parameter:

tar -xvf archive.tar -C /path/to/directory 

The above command will archive.tarunpack the file into /path/to/directorythe directory.

Compress files or directories in gzip format

To compress the archive into gzip format, the following command can be used:

tar -czvf archive.tar.gz file1 file2 dir/ 

Among them, -zmeans to use the gzip compression algorithm. The above command will pack all the files and subdirectories under the file1, file2and directory into a compressed file named .dirarchive.tar.gz

unzip

To uncompress a gzip-formatted archive, use the following command:

tar -xzvf archive.tar.gz 

This command will archive.tar.gzextract the file to the current directory.

List archive contents

To list the files and directories contained in the archive, the following command can be used:

tar -tvf archive.tar 

This command will list archive.tarall files and directories contained in the file.

Add files to archive

To add a file to an existing archive, the following command can be used:

tar -rvf archive.tar file3 

This command will file3append the file to archive.tarthe end of the file.

Delete files from archive

To remove a file from an existing archive, the following command can be used:

tar -dvf archive.tar file2 

This command will archive.tardelete file2the file from the file.

Guess you like

Origin blog.csdn.net/MrTeacher/article/details/129864975