zip compression tool, tar package, package and compress

zip compression tool

zip can compress a directory without deleting the original file after compression.

First install the zip package, run the command yum install -y zip

Compressed file zip [compressed file name] [specify compressed file]

[root@g_linux01 tmp]# zip 123 1.txt
  adding: 1.txt (deflated 37%)
[root@g_linux01 tmp]# ls
123.zip         systemd-private-cfeb657afc1f4ee3922e516bced89173-chronyd.service-0KXk3k   systemd-private-d49d765ffa054e279ee7df6a586b6eb0-vgauthd.service-3sA0lH
1.txt           systemd-private-cfeb657afc1f4ee3922e516bced89173-vgauthd.service-Q2kZn0   systemd-private-d49d765ffa054e279ee7df6a586b6eb0-vmtoolsd.service-IDX3Dr
2018-02-27.log  systemd-private-cfeb657afc1f4ee3922e516bced89173-vmtoolsd.service-thaBHF
shell           systemd-private-d49d765ffa054e279ee7df6a586b6eb0-chronyd.service-76UyZy

Compress directory file zip -r [compressed file name] [specified file or directory can be multiple]

[root@g_linux01 tmp]# zip -r gg.zip 1.txt shell 
  adding: 1.txt (deflated 37%)
  adding: shell/ (stored 0%)
  adding: shell/lx1.sh (stored 0%)

Unzip unzip [unzip file], if unzip in the same directory, it will ask whether to overwrite

install yum install -y unzip

[root@g_linux01 tmp]# unzip 123.zip
Archive:  123.zip
replace 1.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
  inflating: 1.txt     

unzip 123.zip -d /tmp/test Unzip the 123.zip file to /tmp/test

View the file list: unzip -l [file name] but cannot directly view the file content

[root@g_linux01 tmp]# unzip -l gg.zip
Archive:  gg.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
       35  02-27-2018 13:45   1.txt
        0  02-27-2018 11:48   shell/
       45  02-27-2018 11:48   shell/lx1.sh
---------                     -------
       80                     3 files


tar packaging

tar -cvf [packaged file name] [packaged file 1] [packaged file 2]

-c create v visualization f specify the package file name

[root@g_linux01 test]# ls
1.txt  2.txt  lianxi
[root@g_linux01 test]# tar -cvf 12.tar 1.txt 2.txt
1.txt
2.txt
[root@g_linux01 test]# ls
12.tar  1.txt  2.txt  lianxi

Unzip tar -xvf [packed file] (the same file in the same directory will be overwritten after unzipping)

View the list of packaged files: tar -tf [packaged file]

[root@g_linux01 test]# tar -tf 12.tar
1.txt
2.txt

Filter out the specified files when packaging

tar -cvf 123.tar --exclude 1.txt --exclude 2.txt lianxi 1.txt 2.txt(也可以写成--exclude "*.txt")

[root@g_linux01 test]# tar -cvf 123.tar --exclude 1.txt --exclude 2.txt lianxi 1.txt 2.txt
lianxi/
[root@g_linux01 test]# ls
123.tar  12.tar  1.txt  2.txt  lianxi


pack and compress

tar -zcvf 123.tar.gz 123 Compress and pack gzip  

tar -zxvf 123.tar.gz decompress

tar -jcvf 123.tar.bz2 123 Compress bz2

tar -jxvf 123.tar.bz2

tar -Jcvf 123.tar.xz 123 compressed package xz

tar -Jxvf 123.tar.xz

In general, gzip bz2 xz compression is getting better and better, and the speed is getting slower and slower

tar -tf 123.gz/123.bz2/123.xz View the list of packed compressed files

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325114206&siteId=291194637