How to use the tar command correctly under Linux system

  

The tar command in Linux system packs files, and several different files are collected in the same file, which is similar to the function of compression software. Here's how to use the tar command correctly under Linux.

tar [-cxtzjvfpPN] files and directories

-c: to create a compressed file -x: unlock a compressed file -t: what file name to view the compressed files are < Br>

-j : Compress or decompress with bzip2, the file name is *.tar.bz2.

-z : Compress or decompress with gzip, the file name is *.tar.gz

-v : Display file name during compression

-f : The name of the file to be processed after the solution can only be placed at the end of the parameter

-p : use the original The original attribute of the file (the attribute does not change depending on the user)

-P : Keep the absolute path

-N : newer than the following date (yyyy/mm/dd) Will be packaged into the newly created file!

First, compression, decompression, query

Compression: tar -zcvf filename.tar.gz File or directory name to be compressed

Query: tar -ztvf filename .tar.gz

Unzip: tar -zxvf filename.targz -C directory you want to compress

Second, add files to the archive

to existing ones Add files to the archive file, append options -r

tar-rvf original.tar new filename

Third, splicing two compressed files

Combining multiple with -A option Tar file

tar -Af file1.tar file2.tar

IV. Excluding some files in the archive file

Excluding files matching wildcards with --exclude[PATTETN]

Excluding all .txt files

tar -cf xiao.tar* --exclude “*.txt“

The above is the correct use of the tar command under Linux. The method, it should be noted that the file formed by packing with the tar file is not a compressed file, so it cannot be opened with compression software. For more information on how to use the tar command, you can click on the summary of the tar command in the Linux system.

Copyright © Windows knowledge All Rights Reserved