Linux常用命令--解压缩

来源:互联网 发布:超级碧业生 知乎 编辑:程序博客网 时间:2024/06/14 13:57
1、使用tar解压缩

-c :建立一个压缩文件的参数指令(create 的意思);
-x :解开一个压缩文件的参数指令!
-t :查看 tarfile 里面的文件!
特别注意,在参数的下达中, c/x/t 仅能存在一个!不可同时存在!因为不可能同时压缩与解压缩。

-z :是否同时具有 gzip 的属性?亦即是否需要用 gzip 压缩?
-j :是否同时具有 bzip2 的属性?亦即是否需要用 bzip2 压缩?
-v :压缩的过程中显示文件!这个常用,但不建议用在背景执行过程!
-f :使用档名,请留意,在 f 之后要立即接档名喔!不要再加参数!
   例如使用『 tar -zcvfP tfile sfile』就是错误的写法,要写成
   『 tar -zcvPf tfile sfile』才对喔!
-p :使用原文件的原来属性(属性不会依据使用者而变)
-P :可以使用绝对路径来压缩!
-N :比后面接的日期(yyyy/mm/dd)还要新的才会被打包进新建的文件中!
--exclude FILE:在压缩的过程中,不要将 FILE 打包!

解压:tar -zxvf xxx.tar.gz /usr/local 如果不指定解压目则加压至当前目录
压缩:tar -zcvf /tmp/xxx.tar.gz /tem/xxx 前面是文件名 后面是要压缩的文件或路径
查看:tar -ztvf /tmp/xxx.tar.gz

2、使用zip和unzip解压缩

在做网站迁移的时候,由于网站目录内的文件太多会导致耗费许多时间,所以需要用压缩和解压的命令,列如,我需要备份/home/wwwroot文件夹,但是由于wwwroot里面文件数目有几万个甚至更多,这个时候就需要用zip命令,先把wwwroot文件压缩后在传输:

cd /wwwroot

zip -r wwwroot.zip wwwroot

OK,将wwwroot文件压缩成了wwwroot.zip格式了,这是上传下载就很快了。同样的道理,将压缩文件传到centos里面时,可以用unzip解压文件;列如,将/home/wwwroot.zip解压,就可以用如下命令:

cd /home

unzip wwwroot.zip

===============================

还有更多相关的命令如下:

1. 我想把一个文件abc.txt和一个目录dir1压缩成为yasuo.zip:

# zip -r yasuo.zip abc.txt dir1

2.我下载了一个yasuo.zip文件,想解压缩:

# unzip yasuo.zip

3.我当前目录下有abc1.zip,abc2.zip和abc3.zip,我想一起解压缩它们:

# unzip abc\?.zip

注释:?表示一个字符,如果用*表示任意多个字符。

4.我有一个很大的压缩文件large.zip,我不想解压缩,只想看看它里面有什么:

# unzip -v large.zip

5.我下载了一个压缩文件large.zip,想验证一下这个压缩文件是否下载完全了

# unzip -t large.zip

6.我用-v选项发现music.zip压缩文件里面有很多目录和子目录,并且子目录中其实都是歌曲mp3文件,我想把这些文件都下载到第一级目录,而不是一层一层建目录:

# unzip -j music.zip


3、使用rar和unrar解压缩

一、下载并安装rar软件

2.1 下载
mkdir -p  /home/oldboy/tools
cd /home/oldboy/tools
wget http://www.rarlab.com/rar/rarlinux-3.8.0.tar.gz

2.2 安装
tar zxvf rarlinux-3.8.0.tar.gz
cd rar
make
make install 

二、rar命令语法

将/etc 目录压缩为etc.rar 命令为:

rar a etc.rar /etc

将etc.rar 解压 命令为:
rar x etc.rar 
unrar -e etc.tar

三、语法详情
RAR 5.11   Copyright (c) 1993-2014 Alexander Roshal   27 Aug 2014
Trial version             Type RAR -? for help
Usage:     rar <command> -<switch 1> -<switch N> <archive> <files...>
               <@listfiles...> <path_to_extract\>
<Commands>
  a             Add files to archive
  c             Add archive comment
  ch            Change archive parameters
  cw            Write archive comment to file
  d             Delete files from archive
  e             Extract files without archived paths
  f             Freshen files in archive
  i[par]=<str>  Find string in archives
  k             Lock archive
  l[t[a],b]     List archive contents [technical[all], bare]
  m[f]          Move to archive [files only]
  p             Print file to stdout
  r             Repair archive
  rc            Reconstruct missing volumes
  rn            Rename archived files
  rr[N]         Add data recovery record
  rv[N]         Create recovery volumes
  s[name|-]     Convert archive to or from SFX
  t             Test archive files
  u             Update files in archive
  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
  as            Synchronize archive contents
  c-            Disable comments show
  cfg-          Disable read configuration
  cl            Convert names to lower case
  cu            Convert names to upper case
  df            Delete files after archiving
  dh            Open shared files
  ds            Disable name sort for solid archive
  dw            Wipe files after archiving
  e[+]<attr>    Set file exclude and include attributes
  ed            Do not add empty directories
  en            Do not put 'end of archive' block
  ep            Exclude paths from names
  ep1           Exclude base directory from names
  ep3           Expand paths to full including the drive letter
  f             Freshen files
  hp[password]  Encrypt both file data and headers
  ht[b|c]       Select hash type [BLAKE2,CRC32] for file checksum
  id[c,d,p,q]   Disable messages
  ierr          Send all messages to stderr
  ilog[name]    Log errors to file (registered versions only)
  inul          Disable all messages
  isnd          Enable sound
  k             Lock archive
  kb            Keep broken extracted files
  log[f][=name] Write names to log file
  m<0..5>       Set compression level (0-store...3-default...5-maximal)
  ma[4|5]       Specify a version of archiving format
  mc<par>       Set advanced compression parameters
  md<n>[k,m,g]  Dictionary size in KB, MB or GB
  ms[ext;ext]   Specify file types to store
  mt<threads>   Set the number of threads
  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
  oh            Save hard links as the link instead of the file
  oi[0-4][:min] Save identical files as references
  ol            Save symbolic links as the link instead of the file
  or            Rename files automatically
  ow            Save or restore file owner and group
  p[password]   Set password
  p-            Do not query password
  qo[-|+]       Add quick open information [none|force]
  r             Recurse subdirectories
  r-            Disable recursion
  r0            Recurse subdirectories for wildcard names only
  rr[N]         Add data recovery record
  rv[N]         Create recovery volumes
  s[<N>,v[-],e] Create solid archive
  s-            Disable solid archiving
  sc<chr>[obj]  Specify the character set
  sfx[name]     Create SFX archive
  si[name]      Read data from standard input (stdin)
  sl<size>      Process files with size less than specified
  sm<size>      Process files with size more than specified
  t             Test files after archiving
  ta<date>      Process files modified after <date> in YYYYMMDDHHMMSS format
  tb<date>      Process files modified before <date> in YYYYMMDDHHMMSS format
  tk            Keep original archive time
  tl            Set archive time to latest file
  tn<time>      Process files newer than <time>
  to<time>      Process files older than <time>
  ts<m,c,a>[N]  Save or restore file time (modification, creation, access)
  u             Update files
  v<size>[k,b]  Create volumes with size=<size>*1000 [*1024, *1]
  ver[n]        File version control
  vn            Use the old style volume naming scheme
  vp            Pause before each volume
  w<path>       Assign work directory
  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
  z[file]       Read archive comment from file


UNRAR 5.11 freeware      Copyright (c) 1993-2014 Alexander Roshal
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
  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>[N]  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


文章整理自网络,如有雷同纯属正常。如果本人侵犯到了您的权益,请联系我
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 360n5返回键不好用怎么办 魅族手机锁屏怎么办 魅族手机锁住了怎么办 手机己锁定怎么办魅族 魅蓝u10触屏没反应怎么办 魅蓝e2手机锁定怎么办 苹果手机声音键坏了怎么办 一加6的屏幕问题怎么办 魅蓝note6卡顿怎么办 苹果4s内屏坏了怎么办 魅族mx6一直重启怎么办 魅族充电慢了怎么办啊 笔记本玩游戏掉帧怎么办 psv玩游戏掉帧怎么办 ipad玩游戏掉帧怎么办 手机玩游戏严重掉帧怎么办 苹果7p掉电快怎么办 努比亚z11手机总是开关机怎么办 努比亚手机不能保存图片怎么办 小米8拍照和努比亚怎么办 oppor7手机开不了机怎么办 vivox5m手机开不开机怎么办 步步高x7图案解锁忘记怎么办 手机机锁定怎么办魅族 衣服买完降价了怎么办 在淘宝上不发货怎么办 一加3t吃鸡卡怎么办 小米max打游戏反应慢怎么办 小米max2手机玩游戏卡怎么办 魅蓝metal开不了机怎么办 魅蓝e手机信号差怎么办 魅蓝metal手机已锁定怎么办 魅族not3卡开了怎么办 魅族metal手机好卡怎么办 魅蓝手机锁机了怎么办 魅族note2屏坏了怎么办 魅族mx3开不开机怎么办 魅蓝max3充电慢怎么办? 魅族手机home键失灵怎么办 魅族开关键坏了怎么办 魅族开关键不灵怎么办