【Linux】操作 - 解压

Posted by 西维蜀黍 on 2021-06-09, Last Modified on 2022-04-01

Install

unzip

$ sudo apt install unzip -y

Achieve

tar

# [c]reate an archive and write it to a [f]ile:
$ tar cf target.tar file1 file2 file3

# [c]reate a g[z]ipped archive and write it to a [f]ile:
$ tar czf target.tar.gz file1 file2 file3

# [c]reate a g[z]ipped archive from a directory using relative paths:
$ tar czf target.tar.gz --directory=<path/to/directory> .

Unzip

.tar

# Lis[t] the contents of a tar [f]ile [v]erbosely:
$ tar tvf source.tar

.gz

$ gzip -d file.gz

tar.gz

$ tar -xf archive.tar.gz

# E[x]tract a (compressed) archive [f]ile into the current directory [v]erbosely:
$ tar xvf source.tar[.gz|.bz2|.xz]

# E[x]tract a (compressed) archive [f]ile into the target directory:
$ tar xf source.tar[.gz|.bz2|.xz] --directory=directory    

.zip

$ unzip latest.zip

Unzip a ZIP File to a Different Directory

$ unzip filename.zip -d </path/to/directory>

$ unzip v2sitedat_linux_amd64.zip
Archive:  v2sitedat_linux_amd64.zip
   skipping: geosite.dat             need PK compat. v6.3 (can do v4.6)
   skipping: LICENSE                 need PK compat. v6.3 (can do v4.6)
   skipping: main.go                 need PK compat. v6.3 (can do v4.6)
   skipping: README.md               need PK compat. v6.3 (can do v4.6)
   skipping: sites/cn                need PK compat. v6.3 (can do v4.6)
   skipping: sites/proxy             need PK compat. v6.3 (can do v4.6)
   skipping: sites/reject            need PK compat. v6.3 (can do v4.6)
   skipping: v2sitedat               need PK compat. v6.3 (can do v4.6)
   
# how to solve
$ sudo apt-get install p7zip-full; 7z x v2sitedat_linux_amd64.zip

.tgz

$ tar zxvf fileNameHere.tgz

Reference