linux压缩命令常用的有:tar,tgz,gzip,zip,rar
一,tar
(一) tar压缩命令
tar -cvf examples.tar files|dir#说明:-c, --create create a new archive 创建一个归档文件-v, --verbose verbosely list files processed 显示创建归档文件的进程-f, --file=ARCHIVE use archive file or device ARCHIVE 后面要立刻接被处理的档案名,比如--file=examples.tar#举例:tar -cvf file.tar file1 #file1文件tar -cvf file.tar file1 file2 #file1,file2文件tar -cvf file.tar dir #dir目录
(二) tar 解压命令
tar -xvf examples.tar (解压至当前目录下)tar -xvf examples.tar -C /path (/path 解压至其它路径)#说明:-x, --extract, extract files from an archive 从一个归档文件中提取文件#举例:tar -xvf file.tartar -xvf file.tar -C /temp #解压到temp目录下
二,tgz
tar可以通过参数 -z 同时调用gzip对tar包进行压缩。
(一) tgz压缩命令(tar.gz,tgz格式是相同的,命名不同而已)
tar -zcvf examples.tgz examples (examples当前执行路径下的目录)说明:-z, --gzip filter the archive through gzip 通过gzip压缩的形式对文件进行归档举例:tar -zcvf file.tgz dir #dir目录
(二) tgz 解压命令
tar -zxvf examples.tar (解压至当前执行目录下)tar -zxvf examples.tar -C /path (/path 解压至其它路径)举例:tar -zxvf file.tgztar -zxvf file.tgz -C /temp
三,gzip
(一)gzip压缩:
注意gzip只能压缩文件不能打包,并不会将某一目录打包为xxx.gz,而是将该目录下的所有文件分别压缩为.gz
说明:
-z, --gzip filter the archive through gzip 通过gzip压缩的形式对文件进行归档
-6 指定压缩效率,默认为6,范围1到9,1的压缩效率最小压缩速度最快,9反之
gzip -r -6 examples.gz examples
(二)gunzip解压:
gzip -dr examples.gzgunzip -r examples.gz
四,zip
zip 格式是开放且免费的,所以广泛使用在 Windows、Linux、MacOS 平台,要说 zip有什么缺点的话,就是它的压缩率并不是很高,不如 rar及 tar.gz 等格式。
(一)zip压缩
说明 -r 递归处理,将指定目录下的所有文件和子目录一并处理。zip -r examples.zip examples (examples为目录)
(一)unzip 解压
unzip examples.zip