Linux文件打包压缩与解压

Tar

打包:Tar -cvf 包名.tar 源文件目录等

[alice@localhost alice1]$ tar -cvf test.tar alice2 rename.txt rfn1

查看包内容:tar -tvf 包

[alice@localhost alice1]$ tar -tvf test.tar

解包:tar -xvf test.tar -C 目录(目录已存在)

[alice@localhost alice1]$ tar -xvf test.tar -C ./test

打包并压缩:tar -zcvf 包名.tar 源文件

[alice@localhost alice1]$ tar -zcvf ztest.tgz alice2 rename.txt

查看压缩包内容:tar -ztvf 包名.tar

[alice@localhost alice1]$ tar -ztvf ztest.tgz

解压缩包:tar -zxvf 包名.tar -C

[alice@localhost alice1]$ tar -zxvf ./ztest.tgz -C ./ztest

Gzip

压缩文件:gzip filename
自动生成.gz的源文件

[alice@localhost alice1]$ gzip ./rename.txt 
[alice@localhost alice1]$ ls
alice2  rename.txt.gz  rfn1  test  ztest  ztest.tgz

解压缩文件:gzip -d 包

[alice@localhost alice1]$ gzip -d rename.txt.gz
[alice@localhost alice1]$ ls
alice2  rename.txt  rfn1  test  ztest  ztest.tar

Zip

压缩一个或多个文件

[alice@localhost alice1]$ zip rename.zip rename.txt
  adding: rename.txt (deflated 93%)
[alice@localhost alice1]$ ls
alice2  rename.txt  rename.zip  rfn1  test  zfile.zip  ztest  ztest.tar

解压 unzip 压缩文件名
[alice@localhost alice1]$ unzip rename.zip
Archive: rename.zip
replace rename.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: y #是否覆盖已经存在的文件
inflating: rename.txt
命令的详细解释都可通过man 命令查看详细。以上只是把重要的写出来。

[alice@localhost alice1]$ man zip
ZIP(1L)                                                                ZIP(1L)

NAME
       zip - package and compress (archive) files

SYNOPSIS
       zip  [-aABcdDeEfFghjklLmoqrRSTuvVwXyz!@$] [--longoption ...]  [-b path]
       [-n suffixes] [-t date] [-tt date] [zipfile [file ...]]  [-xi list]

       zipcloak (see separate man page)

       zipnote (see separate man page)

       zipsplit (see separate man page)

       Note:  Command line processing in zip has been changed to support  long
       options  and  handle all options and arguments more consistently.  Some
       old command lines that depend on command line  inconsistencies  may  no
       longer work.

你可能感兴趣的:(Linux)