Home > Article > System Tutorial > Linux tar usage introduction
First we need to understand two concepts: packaging and compression. Packaging refers to turning a large number of files or directories into a total file; compression means turning a large file into a small file through some compression algorithms.
Why should we distinguish these two concepts? This is due to the fact that many compression programs in Linux can only compress one file, so when you want to compress a large number of files, you have to first package the large number of files into a package (tar command), and then use Compression program (gzip bzip2 command).
tar (选项) (参数)
Options
-A or --catenate: Add files to existing backup files;
-B: Set block size;
-c or --create: Create a new backup file;
-C : This option is used for decompression. If you want to decompress in a specific directory, you can use this option.
-d: Record file differences;
-x or --extract or --get: Restore files from backup files;
-t or --list: List the contents of the backup file;
-z or --gzip or --ungzip: Process backup files through the gzip command;
-Z or --compress or --uncompress: process backup files through the compress command;
-f or --file=: Specify the backup file;
-v or --verbose: display the instruction execution process;
-r: Add files to already compressed files;
-u: Add changed and existing files to the existing compressed file;
-j: Support bzip2 decompression files;
-v: Display the operation process;
-l: File system boundary setting;
-k: Keep the original files without overwriting;
-m: Keep files from being overwritten;
-w: Confirm the correctness of the compressed file;
-p or --same-permissions: Restore the file with the original file permissions;
-P or --absolute-names: use absolute names for file names and do not remove the "/" sign before the file name;
-N or --newer=: Only save files newer than the specified date to the backup file;
--exclude=: Exclude files that match the template style.
Pack the files into a tar package:
tar -cvf log.tar log2012.log
Only packaging, not compression!
tar -zcvf log.tar.gz log2012.log
After packaging, compress with gzip
tar -jcvf log.tar.bz2 log2012.log
After packaging, compress with bzip2
In the folder, only files newer than a certain date are backed up:
tar -N "2018/3/1" -zcvf log.tar.gz test
If you use tar in the simplest way, you only need to remember the following three methods:
Compression:
tar -jcv -f filename.tar.bz2
The name of the file or directory to be compressed
Inquire:
tar -jtv -f filename.tar.bz2
unzip:
tar -jxv -f filename.tar.bz2 -C
Directory to be decompressed
The above is the detailed content of Linux tar usage introduction. For more information, please follow other related articles on the PHP Chinese website!