本文总结了常用的 Ubuntu / Linux下压缩和解压命令

.tar 文件

仅打包,并非压缩

tar -xvf FileName.tar         # 解压文件FileName.tar 
tar -cvf FileName.tar DirName # 将DirName和其下所有文件(夹)压缩为FileName.tar

查看tar usage

$ tar --help

.tar.gz文件

打包并压缩

# .tar.gz 和 .tgz
tar -zxvf FileName.tar.gz               # 解压文件FileName.tar.gz 
tar -zcvf FileName.tar.gz DirName       # 将DirName和其下所有文件(夹)压缩
tar -C DesDirName -zxvf FileName.tar.gz # 解压到指定路径DesDirName

.rar文件

在Windows系统下常用的rar文件不能直接使用,推荐安装支持软件unrar.

$ sudo apt-get install unrar

使用如下:

unrar e FileName.rar      # 解压文件FileName.rar到当前文件夹
unrar x FileName.rar DesDirName # 解压文件FileName.rar到指定路径DesDirName

unrar usage:

Usage:     unrar <command> -<switch 1> -<switch N> <archive> <files...>
               <@listfiles...> <path_to_extract\>

<Commands>
  e             Extract files without archived paths
  l[t[a],b]     List archive contents [technical[all], bare]
  p             Print file to stdout
  t             Test archive files
  v[t[a],b]     Verbosely list archive contents [technical[all],bare]
  x             Extract files with full path

<Switches>
  -             Stop switches scanning
  @[+]          Disable [enable] file lists
  ad            Append archive name to destination path
  ag[format]    Generate archive name using the current date
  ai            Ignore file attributes
  ap<path>      Set path inside archive
  c-            Disable comments show
  cfg-          Disable read configuration
  cl            Convert names to lower case
  cu            Convert names to upper case
  dh            Open shared files
  ep            Exclude paths from names
  ep3           Expand paths to full including the drive letter
  f             Freshen files
  id[c,d,p,q]   Disable messages
  ierr          Send all messages to stderr
  inul          Disable all messages
  kb            Keep broken extracted files
  n<file>       Additionally filter included files
  n@            Read additional filter masks from stdin
  n@<list>      Read additional filter masks from list file
  o[+|-]        Set the overwrite mode
  ol[a]         Process symbolic links as the link [absolute paths]
  or            Rename files automatically
  ow            Save or restore file owner and group
  p[password]   Set password
  p-            Do not query password
  r             Recurse subdirectories
  sc<chr>[obj]  Specify the character set
  sl<size>      Process files with size less than specified
  sm<size>      Process files with size more than specified
  ta<date>      Process files modified after <date> in YYYYMMDDHHMMSS format
  tb<date>      Process files modified before <date> in YYYYMMDDHHMMSS format
  tn<time>      Process files newer than <time>
  to<time>      Process files older than <time>
  ts[m|c|a]     Save or restore file time (modification, creation, access)
  u             Update files
  v             List all volumes
  ver[n]        File version control
  vp            Pause before each volume
  x<file>       Exclude specified file
  x@            Read file names to exclude from stdin
  x@<list>      Exclude files listed in specified list file
  y             Assume Yes on all queries

.zip文件

.zip也是最常用的压缩格式之一。

unzip FileName.zip          # 解压文件FileName.zip
zip FileName.zip DirName    # 将DirName本身压缩为FileName.zip
zip -r FileName.zip DirName # 将DirName和其下所有文件(夹)压缩为FileName.zip

zip usage:

zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list]
  The default action is to add or replace zipfile entries from list, which
  can include the special name - to compress standard input.
  If zipfile and list are omitted, zip compresses stdin to stdout.
  -f   freshen: only changed files  -u   update: only changed or new files
  -d   delete entries in zipfile    -m   move into zipfile (delete OS files)
  -r   recurse into directories     -j   junk (don't record) directory names
  -0   store only                   -l   convert LF to CR LF (-ll CR LF to LF)
  -1   compress faster              -9   compress better
  -q   quiet operation              -v   verbose operation/print version info
  -c   add one-line comments        -z   add zipfile comment
  -@   read names from stdin        -o   make zipfile as old as latest entry
  -x   exclude the following names  -i   include only the following names
  -F   fix zipfile (-FF try harder) -D   do not add directory entries
  -A   adjust self-extracting exe   -J   junk zipfile prefix (unzipsfx)
  -T   test zipfile integrity       -X   eXclude eXtra file attributes
  -y   store symbolic links as the link instead of the referenced file
  -e   encrypt                      -n   don't compress these suffixes
  -h2  show more help
分类: Ubuntu

0 条评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注