linux压缩到最小命令,Linux压缩打包命令

一、压缩命令:

1、compress:最为古老的压缩命令,现在基本不用了

解压:uncompress

2、gzip:会替换源文件

解压:-d或gunzip

]$ gzip cdp_w_picpath.iso

$ ll cdp_w_picpath.iso.gz

-rw-r--r--. 1 bill.ding it 12462 10月 10 18:13 cdp_w_picpath.iso.gz

3、bzip2:压缩率比gzip更高,也会替换源文件

解压:-d或bunzip2

]$ bzip2 cdp_w_picpath.iso

]$ ll cdp_w_picpath.iso.bz2

-rw-r--r--. 1 bill.ding it 11650 10月 10 18:13 cdp_w_picpath.iso.bz2

4、zip:压缩

unzip解压

二、tar命令:

1、tar cvf /tmp/root.tar .       打包但并没有压缩

$ tar cvf /tmp/tar/bill.tar .

$ ls /tmp/tar/bill.tar -l

-rw-r--r--. 1 bill.ding it 1054720 12月 20 16:41 /tmp/tar/bill.tar

2、tar rvf /tmp/root.tar /etc/passwd /etc/shadow  追加这2个文件,打包到root.tar文件中

]$ tar rvf /tmp/tar/bill.tar /tmp/passwd

tar: 从成员名中删除开头的“/”

/tmp/passwd

3、tar xvf /tmp/root.tar

]$ tar xvf bill.tar

4、tar xvf /tmp/root.tar -C /tmp/dir       解压到指定目录

]$ tar xvf bill.tar -C /tmp/ttt/

5、tar tvf /tmp/root.tar  查看包的内容

]$ tar tvf bill.tar | less

drwxrwxrwt bill.ding/it 0 2013-12-20 16:04 ./

-rw-r--r-- bill.ding/it 307 2013-10-08 16:19 ./multi-read.sh

-rw-r--r-- bill.ding/it 5 2013-10-14 17:35 ./kk2

-rw-r--r-- bill.ding/it 322 2013-11-11 16:45 ./avoid-subshell.sh

-rw-r--r-- bill.ding/it 327 2013-10-31 17:55 ./wf2.sh.uppercase

-rw-r--r-- bill.ding/it 395 2013-12-12 17:30 ./ex24-1.sh

6、tar cvfz /tmp/root.tar.gz /root 打包压缩成gzip格式,解压时会多个root目录如:你现在在tmp目录下解压时会出现:

/tmp/root/1....abc.*

如果是用tar cvfz /tmp/root.tar.gz . 打包解压时没有root目录,直接在/tmp下生成文件

]$ ll

总用量 1312

-rw-r--r--. 1 bill.ding it 1054720 12月 20 16:53 bill.tar

-rw-r--r--. 1 bill.ding it 285827 12月 20 16:59 bill.tar.gz

r]$ pwd

/tmp/tar

[bill.ding@ns1 tar]$tar cvf bill.tar ~bill.ding/bin2/

[bill.ding@ns1 tar]$ tar xvf bill.tar -C /tmp/ttt/

$ ls /tmp/ttt/

home

[bill.ding@ns1 tar]$ ls /tmp/ttt/home/bill.ding/

bin2

[bill.ding@ns1 tar]$ ls /tmp/ttt/home/bill.ding/bin2/

1.data fc4upd.sh quote-fetch.sh

如果打包是用.来代替的话:

]$ pwd

/home/bill.ding/bin2

]$ tar cvf /tmp/tar/bill.tar .

]$ tar xvf /tmp/tar/bill.tar -C /tmp/ttt/

]$ ls /tmp/ttt/

1.data fibo.sh ra2ogg.sh  -----直接就是文件内容,没有目录了

7、tar zxvf /tmp/root.tar.gz:解压

$ tar zxvf bill.tar.gz

$ ls -R

.:

bill.tar bill.tar.gz home

./home:

bill.ding

./home/bill.ding:

bin2

./home/bill.ding/bin2:

1.data fc4upd.sh quote-fetch.sh

8、tar zxvf /tmp/root.tar.gz -C /tmp:解压时指定目录位置

$ pwd

/tmp/tar

[bill.ding@ns1 tar]$ tar zxvf bill.tar.gz -C /tmp/ttt/

]$ ls /tmp/ttt/

home

[bill.ding@ns1 tar]$ ls /tmp/ttt/home/

bill.ding

[bill.ding@ns1 tar]$ ls /tmp/ttt/home/bill.ding/

bin2

[bill.ding@ns1 tar]$ ls /tmp/ttt/home/bill.ding/bin2/

1.data fc4upd.sh quote-fetch.sh

9、tar tzvf /tmp/root.tar.gz:查看包内容

]$ tar tzvf bill.tar.gz | less

drwxrwxrwt bill.ding/it 0 2013-12-20 16:04 home/bill.ding/bin2/

-rw-r--r-- bill.ding/it 307 2013-10-08 16:19 home/bill.ding/bin2/multi-read.sh

10、tar cvfj /tmp/root.tar.gz /root:打包并压缩成bzip2格式,其它选项与7-9命令一样,只是将z替换成j而已

$ tar cvfj bill.tar.bz2 ~bill.ding/bin2/

$ ll

总用量 1464

-rw-r--r--. 1 bill.ding it 1054720 12月 20 16:53 bill.tar

-rw-r--r--. 1 bill.ding it 151906 12月 20 17:04 bill.tar.bz2

-rw-r--r--. 1 bill.ding it 285827 12月 20 16:59 bill.tar.gz

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值