File archiving, compression, and decompression of Linux commands - tar, gzip, gunzip, bzip2, bunz

  
        

tar create archive file

[syntax] tar [option] tarfile filename

[command description]

The file name must follow the -f parameter, and As the last item of the parameter;

[Parameter Description]

-c Create a new archive file;

-f Specify the file name;

-r Append files to the archive;

-x Extract files from archive files;

-v,-vv Display progress information;

-t List Archive file information (not extracted);

-C specifies the directory to extract files;

-A merges multiple tar files;

--totals After archiving is completed, Print the total number of archive bytes;

--delete Delete the specified file from the archive;

--exclude Exclude files of the specified style when archiving;

- j When the archive file is generated, it is compressed using the bunzip2 format;

-z When the archive file is generated, it is compressed using the gzip format;

--lzma When the archive file is generated, it is compressed using the lzma format. ;

-a When the archive file is generated, it is automatically compressed according to the extension;


[General usage]

#打tar包, the name is all.tar

$ tar -cvf all.tar *.text;

#Add file b.doc

$ tar -rvf all.tar b.doc;

#List the contents of the archive

$ tar -tvf All.tar;

#Extract all files in the archive

$ tar -xvf all.tar;

$ tar -xvf all.tar -C /opt/App/tool_dir;

#Extract the specified file in the archive file

$ tar -xvf all.tar file_one file_two

#merge two tar files

$ tar -Af file_one.tar file_two.tar

# Delete the specified file

$ tar -f all.tar --delete file_one file_two

#Archive, Exclude log files

$ tar -cf all.tar * --exclude ”*.log”

gzip/gunzip for compression/decompression

[syntax] Br>

gzip [options] file;

gunzip [options] file;

[command description]

gzip can only compress a single file, if multiple File, will generate multiple separate compressed files;

gzip will delete the source file after generating the compressed file!!!!

gu Nzip will delete the source file after the decompression is completed!!!

[Parameter Description]

-l,--list List the attribute information of the compressed file;

--fast specifies the lowest compression ratio;

--best specifies the highest compression ratio;

-n specifies the compression ratio (n is a number and 1<=n<=9);

-v displays progress information;

bzip2/bunzip2 for compression/decompression

[syntax]

bzip2 file;

bunzip2 file ;

[Command Description]

bzip2 can usually generate files with higher compression ratio than gzip; default bzip2 will delete the source file, and use -k parameter to retain the source file;

[Parameter Description]

-k keeps the source file;

-n specifies the compression ratio (n is a number, and 1<=n<=9);

Zip/unzip for compression/decompression

Syntax zip [options] file file dirs

[command description]

After zip compression/decompression, it will not be deleted Source file;

[Parameter description]

-r Recursion; used when compressing directories;

-l List compressed file contents;

-d Delete the specified file from the compressed file;

-u Update the inside of the compressed file Capacity;

[General usage]

#压缩文件

$ zip all.zip file;

$ zip all.zip file_one file_two;

$ zip -r all.zip dir_name;

#update compressed file

$ zip all.zip -u log.text

# Delete the specified content

$ zip -d all.zip log.text;

# unpacking files

$ unzip all.zip;

# listing compressed file contents

$ unzip -l all.zip;

Copyright © Windows knowledge All Rights Reserved