Linux解压/压缩命令详解
0. 背景
- linux系统:Centos 7
1.unzip命令
- 解压:unzip FileName.zip
- 解压至指定目录
-d
:unzip -d /data/software/ pdi-ce-8.1.0.0-365.zip
[-d exdir]
An optional directory to which to extract files. By default, all files and
subdirectories are recreated in the current directory; the -d option allows
extraction in an arbitrary directory (always assuming one has permission to write
to the directory). This option need not appear at the end of the command line;
it is also accepted before the zipfile specification (with the normal options),
immediately after the zipfile specification, or between the file(s) and the -x
option. The option and directory may be concatenated without any white space
between them, but note that this may cause normal shell behavior to be
suppressed. In particular, ``-d ~'' (tilde) is expanded by Unix C shells into
the name of the user's home directory, but ``-d~'' is treated as a literal
subdirectory ``~'' of the current directory.
特殊情况下,’-d '中的在Unix C shells中被视为用户home目录的名字。但是’-d’却被视为一个叫做的当前目录。
[root@cdh202 software]# ll -h
total 629M
drwxr-xr-x. 4 guaishou guaishou 42 Jul 26 11:42 azkaban
-rw-r--r--. 1 gs gs 628M Jul 27 15:16 pdi-ce-8.1.0.0-365.zip
[root@cdh202 software]# unzip pdi-ce-8.1.0.0-365.zip
Archive: pdi-ce-8.1.0.0-365.zip
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of pdi-ce-8.1.0.0-365.zip or
pdi-ce-8.1.0.0-365.zip.zip, and cannot find pdi-ce-8.1.0.0-365.zip.ZIP, period.
[root@cdh202 software]#
原因是:下载的.zip包不对。
unzip: 不能找到zipfile目录inpdi-ce-8.1.0.0-365.zip(.zip)。这就是说,.zip文件损坏
2.zip命令
- 压缩:
zip FileName.zip DirName
- 文件夹压缩:
zip -r fileName filePath/*
3.tar命令
3.1 将某文件夹压缩成tar包并压缩
tar -zcvf hbase-1.4.0.tar.gz hbase-1.4.0/
-
-z
:filter the archive through gzip
将tar包压缩成.gz
文件 -
-c
:创建一个新的.tar
文件 -
-v
:冗余输出 -
-f
:指定文件名
[root@littlelawson local]# ll
total 110360
drwxr-xr-x. 8 root root 4096 Jul 7 15:14 hbase-1.4.0
-rw-r--r--. 1 root root 112925362 Jul 7 15:14 hbase-1.4.0.tar.gz