Linux常用命令(5)--压缩解压命令



Linux常用命令(5)--压缩解压命令
 
1、命令名称:gzip
  www.2cto.com  
  执行权限:所有用户
 
  功能描述:压缩文件
 
  语法:gzip 选项 [文件]
 
  压缩后格式:.gz
 
  gzip只能压缩文件,不能压缩目录;
 
  gzip压缩后不保留原文件
 
[root@localhost abc]# ls
afile  issue.hard  issue.soft  prem  test
[root@localhost abc]# gzip afile
[root@localhost abc]# ls
afile.gz  issue.hard  issue.soft  prem  test
[root@localhost abc]# 
 
2、命令名称:gunzip
 
  执行权限:所有用户
 
  功能描述:解压.gz格式的压缩文件
 
  语法:gunzip 选项 [压缩文件]
 
[root@localhost abc]# gunzip afile.gz
[root@localhost abc]# ls
afile  issue.hard  issue.soft  prem  test
[root@localhost abc]# 
  或者使用: gzip -d 压缩文件
 
[root@localhost abc]# ls
afile.gz  issue.hard  issue.soft  prem  test
[root@localhost abc]# gzip -d afile.gz
[root@localhost abc]# ls
afile  issue.hard  issue.soft  prem  test
[root@localhost abc]# 
 
  www.2cto.com  
3、命令名称:tar
 
  执行权限:所有用户
 
  功能描述:打包目录
 
  语法:tar [cvf] [目录]
 
      -c  产生.tar打包文件
 
      -v  显示详细信息
 
      -f  指定压缩后的文件名
 
      -z  打包同时压缩
 
  打包压缩后格式:.tar.gz
 
将test目录打包并压缩
[root@localhost abc]# tar -zcvf test.tar.gz test
test/
[root@localhost abc]# ls
afile  issue.hard  issue.soft  prem  test  test.tar.gz
[root@localhost abc]# 
 
 
将adir目录先打包,再压缩
[root@localhost abc]# tar -cvf adir.tar adir
adir/
[root@localhost abc]# ls
adir  adir.tar  afile  issue.hard  issue.soft  prem  test  test.tar.gz
[root@localhost abc]# gzip adir.tar
[root@localhost abc]# ls
adir  adir.tar.gz  afile  issue.hard  issue.soft  prem  test  test.tar.gz
[root@localhost abc]# 
 
  
 
  使用tar命令解压缩:
 
    -x  解包.tar文件
 
    -v  显示详细信息
 
    -f  指定解压文件
 
    -z  解压缩
 
 
解压缩test.tar.gz
 
[root@localhost abc]# ls
adir.tar.gz  afile  issue.hard  issue.soft  prem  test.tar.gz
[root@localhost abc]# tar -zxvf test.tar.gz
test/
[root@localhost abc]# ls
adir.tar.gz  afile  issue.hard  issue.soft  prem  test  test.tar.gz
[root@localhost abc]# 
 
先解压,再解包adir.tar.gz
 
[root@localhost abc]# ls
adir.tar.gz  afile  issue.hard  issue.soft  prem  test  test.tar.gz
[root@localhost abc]# gunzip adir.tar.gz
[root@localhost abc]# ls
adir.tar  afile  issue.hard  issue.soft  prem  test  test.tar.gz
[root@localhost abc]# tar -xvf adir.tar
 
4、命令名称:zip
 
  执行权限:所有用户
 
  功能描述:压缩文件或目录
 
  语法:zip [-r] [压缩后文件名称] [文件或目录]
 
    -r  压缩目录
 
  压缩后格式:.zip
 
 
压缩afile文件
[root@localhost abc]# ls
adir  adir.tar  afile  issue.hard  issue.soft  prem  test  test.tar.gz
[root@localhost abc]# zip afile.zip afile
  adding: afile (stored 0%)
[root@localhost abc]# ls
adir      afile      issue.hard  prem  test.tar.gz
adir.tar  afile.zip  issue.soft  test
[root@localhost abc]# 
 
压缩test目录
[root@localhost abc]# ls
adir      afile      issue.hard  prem  test.tar.gz
adir.tar  afile.zip  issue.soft  test
[root@localhost abc]# zip -r test.zip test
  adding: test/ (stored 0%)
[root@localhost abc]# ls
adir      afile      issue.hard  prem  test.tar.gz
adir.tar  afile.zip  issue.soft  test  test.zip
[root@localhost abc]#
 
 
5、命令名称:unzip
 
  执行权限:所有用户
 
  功能描述:解压.zip格式的压缩文件
 
  语法:unzip [压缩文件]
 
解压test.zip
[root@localhost abc]# unzip test.zip
Archive:  test.zip
   creating: test/
[root@localhost abc]#
 
6、命令名称:bzip2
 
  执行权限:所有用户
 
  功能描述:压缩文件
 
  语法:bzip2 [-k] [文件]
 
    -k 产生压缩文件后保留原文件 
 
  压缩后格式:.bz2
 
  只能压缩文件
 
  压缩比很大,适合压缩很大的文件
 
压缩afile
[root@localhost abc]# bzip2 -k afile
[root@localhost abc]# ls
adir      afile      afile.zip   issue.soft  test         test.zip
adir.tar  afile.bz2  issue.hard  prem        test.tar.gz
[root@localhost abc]# 
 
7、命令名称:bunzip2
 
  执行权限:所有用户
 
  功能描述:解压文件
 
  语法:bunzip2 [-k] [压缩文件]
 
    -k 解压后保留原文件 
 
解压afile.bz2
[root@localhost abc]# bunzip2 -k afile.bz2
 
8、查看文件类型命令 file
 
  如果不知道文件的类型,可以使用:file 文件
 
[root@localhost abc]# file /etc/sysconfig
/etc/sysconfig: directory
[root@localhost abc]# 
 

相关内容

    暂无相关文章