Linux下tar解压到当前目录,zip压缩,tar压缩,tar解压

2019/07/06 Linux 共 1098 字,约 4 分钟

Linux下tar解压tar.gz文件到当前目录 很多时候我们需要把文件解压到当前目录,命令如下:

tar -zxvf vscode-server-linux-x64.tar.gz -C ./

有时候很讨厌,因为tar.gz的包里就存在一个与压缩包同名的目录,这种情况的话需要先解压,再拷贝:

tar -zxvf vscode-server-linux-x64.tar.gz -C ./
mv vscode-server-linux-x64/* .

zip压缩的方法:How do I zip/unzip on the unix command line? - Unix & Linux Stack Exchange

zip squash.zip file1 file2 file3
# or to zip a directory
zip -r squash.zip directory

tar压缩:

tar -zcvf myfile.tgz file1 file2

tar解压:

tar -zxvf myfile.tgz
tar -xvzf community_images.tar.gz
tar jxxf filename.tar.bz2

f: this must be the last flag of the command, and the tar file must be immediately after. It tells tar the name and path of the compressed file. z: tells tar to decompress the archive using gzip x: tar can collect files or extract them. x does the latter. v: makes tar talk a lot. Verbose output shows you all the files being extracted.


tar -zxvf filename.tar.gz

其中zxvf含义分别如下

z:   gzip          压缩格式

x:   extract         解压

v:   verbose        详细信息

f:   file(file=archieve)    文件

tar -jxvf filename.tar.bz2
tar -Jxvf filename.tar.xz
tar -Zxvf filename.tar.Z

事实上, 从1.15版本开始tar就可以自动识别压缩的格式,故不需人为区分压缩格式就能正确解压

tar -xvf filename.tar.gz
tar -xvf filename.tar.bz2
tar -xvf filename.tar.xz
tar -xvf filename.tar.Z

有个使用jar进行解压的奇淫技巧:

jar -xf file.zip

文档信息

Table of Contents