摘要:本文主要学习了Linux的打包命令和压缩命令。学习
tar命令能够用来进行打包和解打包,压缩和解压缩。测试
打包和压缩的语法:spa
1 [root@localhost ~]# tar [选项] 源文件或目录
解打包和解压缩的语法:code
1 [root@localhost ~]# tar [选项] 压缩包
打包和压缩的选项:blog
1 -c:将多个文件或目录进行打包。 2 -v:显示打包文件的过程。 3 -f name:name是文件名,指定打包的文件名。 4 -z:压缩和解压缩.tar.gz格式。 5 -j:压缩和解压缩.tar.bz2格式。
解打包和解压缩的选项:递归
1 -x:对tar包作解打包操做。 2 -v:显示解打包的过程。 3 -f name:name是文件名,指定要解压的文件名。 4 -z:压缩和解压缩.tar.gz格式。 5 -j:压缩和解压缩.tar.bz2格式。 6 -t:只查看包中有哪些文件或目录,不作解打包操做。 7 -C name:name是目录名,指定解打包位置。
打包和压缩:ip
1 [root@localhost home]# ls 2 hello hello-hard hello-soft test test-soft 3 [root@localhost home]# tar -cvf hello.tar hello hello-hard hello-soft 4 hello 5 hello-hard 6 hello-soft 7 [root@localhost home]# ls 8 hello hello-hard hello-soft hello.tar test test-soft 9 [root@localhost home]# tar -zcvf test.tar.gz test test-soft 10 test/ 11 test-soft 12 [root@localhost home]# ls 13 hello hello-hard hello-soft hello.tar test test-soft test.tar.gz 14 [root@localhost home]#
解打包和解压缩:class
1 [root@localhost home]# ls 2 hello.tar test.tar.gz 3 [root@localhost home]# tar -xvf hello.tar 4 hello 5 hello-hard 6 hello-soft 7 [root@localhost home]# ls 8 hello hello-hard hello-soft hello.tar test.tar.gz 9 [root@localhost home]# tar -zxvf test.tar.gz 10 test/ 11 test-soft 12 [root@localhost home]# ls 13 hello hello-hard hello-soft hello.tar test test-soft test.tar.gz 14 [root@localhost home]#
zip命令相似于Windows系统中的winzip压缩程序。test
1 [root@localhost ~]# zip [选项] 压缩包名 源文件或源目录列表
1 -r:递归压缩目录,及将指定目录下的全部文件以及子目录所有压缩。 2 -m:将文件压缩以后,删除原始文件,至关于把文件移到压缩文件中。 3 -v:显示详细的压缩过程信息。 4 -q:在压缩的时候不显示命令的执行过程。 5 -n:n表示数字,压缩级别是从1~9的数字,-1表明压缩速度更快,-9表明压缩效果更好。 6 -u:更新压缩文件,即往压缩文件中添加新文件。
1 [root@localhost home]# ls 2 hello hello-hard hello-soft test test-soft 3 [root@localhost home]# zip hello.zip hello hello-hard 4 adding: hello (deflated 99%) 5 adding: hello-hard (deflated 99%) 6 [root@localhost home]# ls 7 hello hello-hard hello-soft hello.zip test test-soft 8 [root@localhost home]# zip test.zip test test-soft 9 adding: test/ (stored 0%) 10 adding: test-soft/ (stored 0%) 11 [root@localhost home]# ls 12 hello hello-hard hello-soft hello.zip test test-soft test.zip 13 [root@localhost home]#
unzip命令能够查看和解压缩zip文件。打包
1 [root@localhost ~]# unzip [选项] 压缩包名
1 -d name:name是目录名,将压缩文件解压到指定目录下。 2 -n:解压时并不覆盖已经存在的文件。 3 -o:解压时覆盖已经存在的文件,而且无需用户确认。 4 -v:查看压缩文件的详细信息,包括压缩文件中包含的文件大小、文件名以及压缩比等,但并不作解压操做。 5 -t:测试压缩文件有无损坏,但并不解压。 6 -x name:name是文件列表,解压文件,但不包含文件列表中指定的文件。
1 [root@localhost home]# ls 2 hello.zip test.zip 3 [root@localhost home]# unzip -v hello.zip 4 Archive: hello.zip 5 Length Method Size Cmpr Date Time CRC-32 Name 6 -------- ------ ------- ---- ---------- ----- -------- ---- 7 10240 Defl:N 99 99% 07-11-2019 01:28 dda39bf9 hello 8 10240 Defl:N 99 99% 07-11-2019 01:28 dda39bf9 hello-hard 9 -------- ------- --- ------- 10 20480 198 99% 2 files 11 [root@localhost home]# unzip hello.zip 12 Archive: hello.zip 13 inflating: hello 14 inflating: hello-hard 15 [root@localhost home]# ls 16 hello hello-hard hello.zip test.zip 17 [root@localhost home]# unzip -d zip test.zip 18 Archive: test.zip 19 creating: zip/test/ 20 creating: zip/test-soft/ 21 [root@localhost home]# ls 22 hello hello-hard hello.zip test.zip zip 23 [root@localhost home]# ls zip 24 test test-soft 25 [root@localhost home]#