Linux:压缩解压

Linux mint 15

将Desktop文件打包为Desktop.tar:

tar -cvf Desktop.tar ~/Desktop/
-c表示建立一个压缩包(create),-v表示在压缩的过程中显示文件,-f表示使用档案名,注意-f必须是最后的一个参数,之后是档案的名字(Desktop.tar)。

查看Desktop.tar中的文件:
tar -tvf Desktop.tar
-t(--list)即列出档案中的文件。通过查看档案,可以看到,所有的文件均是以 home/user/Desktop开头,注意没有home前面没有/,所以在解压时不必担心会覆盖原先目录(除非你指定了解压到/home下)。

解包Desktop.tar:
tar -xvf Desktop.tar
-x为解压的意思,解压后当前目录中会多出一个home目录。
也可以指定解压的目标目录:
mkdir tmp
tar -xvf Desktop.tar -C tmp
tar加密压缩、解压:
http://blog.csdn.net/guolb57/article/details/6697812

使用gzip压缩:
tar -zcvf Desktop.tar.gz ~/Desktop
-z表示gzip属性,查看和解压时候都要加上-z参数。

使用bzip2压缩:
tar -jcvf Desktop.tar.bz2 ~/Desktop
-j表示bzip2属性,查看和解压时候都要加上-z参数。

使用zip压缩:
zip -r Desktop.zip ~/Desktop
-r表示递归。下面是一个更实际的例子:
bash >> touch 你好.txt
bash >> touch hello.txt
bash >> zip text.zip 你好.txt hello.txt 
  adding: 你好.txt (stored 0%)
  adding: hello.txt (stored 0%)
bash >> zip -sf text.zip 
Archive contains:
  你好.txt
  hello.txt
Total 2 entries (0 bytes)
bash >> vim hello.txt 
bash >> zip text.zip 你好.txt hello.txt 
updating: 你好.txt (stored 0%)
updating: hello.txt (deflated 14%)
bash >> zip -sf text.zip 
Archive contains:
  你好.txt
  hello.txt
Total 2 entries (22 bytes)
-sf选项为show files之意。unzip也可以列出文件:
bash >> unzip -l text.zip
Archive:  text.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2013-07-18 09:50   ??????.txt
       22  2013-07-18 09:51   hello.txt
---------                     -------
       22                     2 files
但是有乱码,不过解压后的文件没什么问题。

加密zip:
bash >> zip -e text.zip 你好.txt hello.txt 
Enter password: 
Verify password: 
updating: 你好.txt (stored 0%)
updating: hello.txt (deflated 14%)
解压zip:
bash >> unzip  text.zip
Archive:  text.zip
[text.zip] ??????.txt password: 
replace ??????.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
 extracting: ??????.txt              
replace hello.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
  inflating: hello.txt
也可以指定目录:
bash >> unzip  text.zip -d tmp
Archive:  text.zip
[text.zip] ??????.txt password: 
 extracting: tmp/??????.txt          
  inflating: tmp/hello.txt
zip乱码问题:
在windows下压缩的文件在linux下解压后中文文件名可能会乱码,这时候要指定一下编码:
unzip -O GBK text.zip
rar压缩:
rar a Desktop.rar ~/Desktop
rar a text.rar 你好.txt  hello.txt
a表示add files to archive。
加密使用-hp参数。
查看rar包中的文件:
rar l text.rar
解压rar:
rar x text.rar
不建议使用e参数,因为不会生成子目录,则会把所有文件解压到当前目录,会很凌乱的。
当然,也有unrar命令。也可以指定解压目录:
rar x text.rar tmp/
7z压缩:
7z a Desktop.7z ~/Desktop
7z a text.7z 你好.txt  hello.txt
可以使用-p参数进行加密:
7z a -p123 text.7z 你好.txt  hello.txt
设置密码为123,在解压时候会提示输入密码。
查看7z包中的文件:
7z l text.7z
解压7z:
7z x text.7z
解压到指定目录:
7z x text.7z -otmp
上面是将其解压到tmp目录,注意-o参数与tmp之间没有空格。

转载于:https://my.oschina.net/letiantian/blog/145301

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值