1. 程式人生 > >Linux基本命令(六)

Linux基本命令(六)

Linux壓縮和解壓工具

1、tar.gz

      -- 壓縮:tar -zcvf  壓縮後的包名 .tar.gz 壓縮的目標

      --解壓:tar -zxvf  壓縮後的包名.tar.gz [-C 目標目錄]

     --檢視:tar -ztvf 檢視包名.tar.gz中包含的檔案和目錄

壓縮 :

[[email protected] tmp]$ tar -zcvf varlog.tar.gz  /var/log/
tar: Removing leading `/' from member names
/var/log/
tar: /var/log/cron-20181001: Cannot open: Permission denied
/var/log/vmware-install.log
tar: /var/log/audit: Cannot open: Permission denied
tar: /var/log/maillog-20180911: Cannot open: Permission denied
tar: /var/log/redis: Cannot open: Permission denied
/var/log/sa/
/var/log/sa/sa10
/var/log/sa/sar01
/var/log/sa/sa11
/var/log/sa/sa21
/var/log/sa/sa02
/var/log/sa/sa17
/var/log/sa/sa30
/var/log/sa/sa01
/var/log/sa/sa27
tar: /var/log/anaconda.log: Cannot open: Permission denied
/var/log/wpa_supplicant.log
tar: /var/log/messages-20180911: Cannot open: Permission denied
tar: /var/log/anaconda.syslog: Cannot open: Permission denied
/var/log/mongodb/
tar: /var/log/mongodb/mongod.log: Cannot open: Permission denied
/var/log/Xorg.0.log.old
tar: /var/log/httpd: Cannot open: Permission denied
tar: /var/log/cron: Cannot open: Permission denied
tar: /var/log/ppp: Cannot open: Permission denied
/var/log/cups/
tar: /var/log/maillog-20180917: Cannot open: Permission denied
tar: /var/log/spooler: Cannot open: Permission denied
tar: /var/log/yum.log: Cannot open: Permission denied
tar: /var/log/secure: Cannot open: Permission denied
/var/log/prelink/
/var/log/prelink/prelink.log
/var/log/dracut.log
tar: /var/log/anaconda.yum.log: Cannot open: Permission denied
/var/log/pm-powersave.log
tar: /var/log/secure-20180911: Cannot open: Permission denied
tar: /var/log/anaconda.xlog: Cannot open: Permission denied
tar: /var/log/maillog-20181001: Cannot open: Permission denied
tar: /var/log/anaconda.ifcfg.log: Cannot open: Permission denied
tar: /var/log/anaconda.program.log: Cannot open: Permission denied
/var/log/boot.log
/var/log/ntpstats/
tar: /var/log/tallylog: Cannot open: Permission denied
tar: /var/log/spooler-20180911: Cannot open: Permission denied
tar: /var/log/samba: Cannot open: Permission denied
tar: /var/log/spooler-20181001: Cannot open: Permission denied
/var/log/vmware-tools-upgrader.log
tar: /var/log/messages-20181001: Cannot open: Permission denied
tar: /var/log/messages-20180917: Cannot open: Permission denied
/var/log/vmware-vmsvc.log
/var/log/vmware-caf/
/var/log/vmware-caf/pme/
/var/log/vmware-caf/pme/ma-log4cpp_rolling.log
/var/log/vmware-caf/pme/CommAmqpListener-log4cpp.log
/var/log/vmware-caf/pme/ma-log4cpp.log
/var/log/vmware-caf/pme/CommAmqpListener-log4cpp_rolling.log
tar: /var/log/btmp-20181001: Cannot open: Permission denied
/var/log/ConsoleKit/
/var/log/ConsoleKit/history-20180911.gz
/var/log/ConsoleKit/history
/var/log/ConsoleKit/history-20181001
/var/log/Xorg.0.log
tar: /var/log/secure-20180917: Cannot open: Permission denied
/var/log/wtmp
tar: /var/log/gdm: Cannot open: Permission denied
/var/log/dmesg.old
/var/log/lastlog
tar: /var/log/anaconda.storage.log: Cannot open: Permission denied
tar: /var/log/spice-vdagent.log: Cannot open: Permission denied
tar: /var/log/cron-20180911: Cannot open: Permission denied
tar: /var/log/cron-20180917: Cannot open: Permission denied
tar: /var/log/mysqld.log: Cannot open: Permission denied
tar: /var/log/spooler-20180917: Cannot open: Permission denied
tar: /var/log/maillog: Cannot open: Permission denied
/var/log/dmesg
tar: /var/log/secure-20181001: Cannot open: Permission denied
tar: /var/log/messages: Cannot open: Permission denied
tar: /var/log/btmp: Cannot open: Permission denied
tar: Exiting with failure status due to previous errors
[
[email protected]
tmp]$ ls gconfd-dalianmao keyring-gQeNTc mongodb-27017.sock passwd pulse-vInFYkGgfmE4 vgauthsvclog.txt.0 gconfd-gdm keyring-IFVYje orbit-gdm pulse-ItXdIXRwuB1N varlog.tar.gz vmware-root

解壓:

[[email protected] tmp]$ tar -zxvf varlog.tar.gz -C  ./wzc
var/log/
var/log/vmware-install.log
var/log/sa/
var/log/sa/sa10
var/log/sa/sar01
var/log/sa/sa11
var/log/sa/sa21
var/log/sa/sa02
var/log/sa/sa17
var/log/sa/sa30
var/log/sa/sa01
var/log/sa/sa27
var/log/wpa_supplicant.log
var/log/mongodb/
var/log/Xorg.0.log.old
var/log/cups/
var/log/prelink/
var/log/prelink/prelink.log
var/log/dracut.log
var/log/pm-powersave.log
var/log/boot.log
var/log/ntpstats/
var/log/vmware-tools-upgrader.log
var/log/vmware-vmsvc.log
var/log/vmware-caf/
var/log/vmware-caf/pme/
var/log/vmware-caf/pme/ma-log4cpp_rolling.log
var/log/vmware-caf/pme/CommAmqpListener-log4cpp.log
var/log/vmware-caf/pme/ma-log4cpp.log
var/log/vmware-caf/pme/CommAmqpListener-log4cpp_rolling.log
var/log/ConsoleKit/
var/log/ConsoleKit/history-20180911.gz
var/log/ConsoleKit/history
var/log/ConsoleKit/history-20181001
var/log/Xorg.0.log
var/log/wtmp
var/log/dmesg.old
var/log/lastlog
var/log/dmesg

檢視:

[[email protected] tmp]$ tar -ztvf varlog.tar.gz 
drwxr-xr-x root/root         0 2018-10-01 21:41 var/log/
-rw-r--r-- root/root      5361 2018-07-11 07:56 var/log/vmware-install.log
drwxr-xr-x root/root         0 2018-10-02 00:00 var/log/sa/
-rw-r--r-- root/root     11124 2018-09-10 17:20 var/log/sa/sa10
-rw-r--r-- root/root     33971 2018-10-01 23:53 var/log/sa/sar01
-rw-r--r-- root/root     12036 2018-09-11 09:10 var/log/sa/sa11
-rw-r--r-- root/root     30572 2018-09-21 11:30 var/log/sa/sa21
-rw-r--r-- root/root      6252 2018-10-02 22:20 var/log/sa/sa02
-rw-r--r-- root/root     21676 2018-09-17 03:50 var/log/sa/sa17
-rw-r--r-- root/root      9356 2018-09-30 23:40 var/log/sa/sa30
-rw-r--r-- root/root     35172 2018-10-01 23:50 var/log/sa/sa01
-rw-r--r-- root/root     17916 2018-09-27 09:20 var/log/sa/sa27
-rw-r--r-- root/root         0 2018-07-11 07:53 var/log/wpa_supplicant.log
drwxr-xr-x mongod/mongod     0 2018-07-11 09:55 var/log/mongodb/
-rw-r--r-- root/root     38399 2018-09-27 20:06 var/log/Xorg.0.log.old
drwxr-xr-x lp/sys            0 2018-06-19 08:25 var/log/cups/
drwxr-xr-x root/root         0 2018-07-11 08:36 var/log/prelink/
-rw-r--r-- root/root     43547 2018-10-01 21:41 var/log/prelink/prelink.log
-rw-r--r-- root/root    546944 2018-07-11 09:48 var/log/dracut.log
-rw-r--r-- root/root        89 2018-09-30 22:50 var/log/pm-powersave.log
-rw-r--r-- root/root      2955 2018-09-30 22:50 var/log/boot.log
drwxr-xr-x ntp/ntp           0 2018-01-25 18:18 var/log/ntpstats/
-rw-r--r-- root/root    364531 2018-07-11 07:56 var/log/vmware-tools-upgrader.log
-rw-r--r-- root/root     17882 2018-10-02 22:19 var/log/vmware-vmsvc.log
drwxr-xr-x root/root         0 2018-07-11 07:55 var/log/vmware-caf/
drwxr-xr-x root/root         0 2018-09-30 22:49 var/log/vmware-caf/pme/
-rw-r--r-- root/root     21114 2018-09-30 22:49 var/log/vmware-caf/pme/ma-log4cpp_rolling.log
-rw-r--r-- root/root      1015 2018-09-30 22:49 var/log/vmware-caf/pme/CommAmqpListener-log4cpp.log
-rw-r--r-- root/root         0 2018-07-11 07:56 var/log/vmware-caf/pme/ma-log4cpp.log
-rw-r--r-- root/root      5908 2018-09-30 22:49 var/log/vmware-caf/pme/CommAmqpListener-log4cpp_rolling.log
drwxr-xr-x root/root         0 2018-10-01 21:41 var/log/ConsoleKit/
-rw-r--r-- root/root       665 2018-10-01 21:41 var/log/ConsoleKit/history-20180911.gz
-rw-r--r-- root/root         0 2018-10-01 21:41 var/log/ConsoleKit/history
-rw-r--r-- root/root      4671 2018-09-30 22:50 var/log/ConsoleKit/history-20181001
-rw-r--r-- root/root     36548 2018-10-02 22:20 var/log/Xorg.0.log
-rw-rw-r-- root/utmp     39168 2018-10-02 22:20 var/log/wtmp
-rw-r--r-- root/root     91151 2018-09-27 08:59 var/log/dmesg.old
-rw-r--r-- root/root    146876 2018-10-02 22:20 var/log/lastlog
-rw-r--r-- root/root     90507 2018-09-30 22:49 var/log/dmesg

2、tar.bz2

      --壓縮:  tar  -jcvf  壓縮後的包名.tar.bz2  壓縮的目標

      --解壓:  tar -jxvf   壓縮後的包名.tar.bz2 [-C  目標目錄]

     --檢視:tar -ztvf 檢視包名.tar.bz2中包含的檔案和目錄

3、zip

     --壓縮:zip  壓縮的目標

    --解壓:unzip 壓縮包

4、引數解釋:

j/z :對應檔案型別bz2/gz

c:建立壓縮包

x:解壓

v:顯示過程

t:檢視tarfile裡面的檔案

-f:使用檔名,請留意,在f之後要立即接檔名!不要再加引數