Linux Compression Command Utility Edition

A packaging command tar
tar -cvf package filename source file
Options:
-c: package
-v: show process
-f: Specify the packaged file name
E.g
tar -cvf abc.tar abc
tar -xvf package filename
-x: unpack
E.g
tar -xvf abc.tar
 
Two actual combat
[root@localhost test]# tar -cvf dirtest.tar dirtst
dirt/
dirtst / ert
[root@localhost test]# ls
abc cdf dirtest.tar dirtst
[root@localhost test]# gzip dirtest.tar
[root@localhost test]# ls
abc cdf dirtest.tar.gz dirtst
[root@localhost test]# gzip -d dirtest.tar.gz
[root@localhost test]# ls
abc cdf dirtest.tar dirtst
[root@localhost test]# bzip2 dirtest.tar
[root@localhost test]# ls
abc cdf dirtest.tar.bz2 dirtst
[root@localhost test]# bzip2 -d dirtest.tar.bz2
[root@localhost test]# ls
abc cdf dirtest.tar dirtst
[root@localhost test]# rm -rf dirtst
[root@localhost test]# ls
abc cdf dirtest.tar
[root@localhost test]# tar -xvf dirtest.tar
dirt/
dirtst / ert
[root@localhost test]# ls
abc cdf dirtest.tar dirtst
 
Three .tar.gz compression format and .tar.bz2 format
In fact, the .tar.gz format is first packaged into .tar format, and then compressed into .gz format
tar -zcvf archive name.tar.gz source file
Options:
-z: Compress to .tar.gz format
tar -zxvf archive name.tar.gz
Options:
-x: decompress .tar.gz format
tar -jcvf archive name.tar.bz2 source file
Options:
-j: Compress to .tar.bz2 format
tar -jxvf archive name.tar.bz2
Options:
-x: decompress .tar.bz2 format
 
Four actual combat
[root@localhost test]# ls
abc cdf dirtst
[root@localhost test]# tar -zcvf dirtst.tar.gz dirtst
dirt/
dirtst / ert
[root@localhost test]# ls
abc cdf dirtst dirtst.tar.gz
[root@localhost test]# rm -rf dirtst
[root@localhost test]# tar -zxvf dirtst.tar.gz
dirt/
dirtst / ert
[root@localhost test]# ls
abc cdf dirtst dirtst.tar.gz
[root@localhost test]# tar -jcvf dirtst.tar.bz2 dirtst
dirt/
dirtst / ert
[root@localhost test]# ls
abc cdf dirtst dirtst.tar.bz2 dirtst.tar.gz
[root@localhost test]# tar -jxvf dirtst.tar.bz2 -C /tmp
dirt/
dirtst / ert
[root@localhost test]# ls /tmp
ab.soft qwert
cakin2425 systemd-private-6e910d9981134563a908c77bd50f6f7e-colord.service-LQ5tBA
dirtst systemd-private-6e910d9981134563a908c77bd50f6f7e-cups.service-XJLpHa
japan systemd-private-6e910d9981134563a908c77bd50f6f7e-rtkit-daemon.service-Lf9PxO
[root@localhost test]# ls
abc cdf dirtst
[root@localhost test]# tar -zcvf test.tar.gz abc dirtst
abc
dirt/
dirtst / ert
[root@localhost test]# ls
abc cdf dirtst test.tar.gz
[root@localhost test]# tar -zcvf /tmp/test.tar.gz abc dirtst
abc
dirt/
dirtst / ert
[root@localhost test]# ls /tmp
ab.soft systemd-private-6e910d9981134563a908c77bd50f6f7e-colord.service-LQ5tBA
cakin2425 systemd-private-6e910d9981134563a908c77bd50f6f7e-cups.service-XJLpHa
dirtst systemd-private-6e910d9981134563a908c77bd50f6f7e-rtkit-daemon.service-Lf9PxO
japan test.tar.gz
qwert
[root@localhost test]# cd /tmp
[root@localhost tmp]# tar -zxvf test.tar.gz
abc
dirt/
dirtst / ert
[root@localhost tmp]# ls
abc dirtst systemd-private-6e910d9981134563a908c77bd50f6f7e-colord.service-LQ5tBA test.tar.gz
ab.soft japan systemd-private-6e910d9981134563a908c77bd50f6f7e-cups.service-XJLpHa
cakin2425 qwert systemd-private-6e910d9981134563a908c77bd50f6f7e-rtkit-daemon.service-Lf9PxO
[root@localhost tmp]# tar -ztvf test.tar.gz
-rw-r--r-- root/root 4 2017-07-15 07:52 abc
drwxr-xr-x root/root 0 2017-07-15 08:18 dirtst/
-rw-r--r-- root/root 0 2017-07-15 07:55 dirtst/ert
 
Five for loops to achieve decompression
#!/bin/bash
 
cd /root/test/
ls * .tar.gz> ls.log
ls * .tgz >> ls.log
 
for i in $(cat ls.log)
do
tar -zxf $i &>/dev/null
done
rm -rf ls.log

Guess you like

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