4

linux下rar文件常用操作

 2 years ago
source link: https://www.lujun9972.win/blog/2018/06/07/linux%E4%B8%8Brar%E6%96%87%E4%BB%B6%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

linux下rar文件常用操作

安装rar命令

sudo pacman -S rar --noconfirm
resolving dependencies...
looking for conflicting packages...

Packages (1) rar-5.5.0-1

Total Installed Size:  0.72 MiB
Net Upgrade Size:      0.00 MiB

:: Proceed with installation? [Y/n] 
(0/1) checking keys in keyring                     [----------------------]   0%
(1/1) checking keys in keyring                     [######################] 100%
(0/1) checking package integrity                   [----------------------]   0%
(1/1) checking package integrity                   [######################] 100%
(0/1) loading package files                        [----------------------]   0%
(1/1) loading package files                        [######################] 100%
(0/1) checking for file conflicts                  [----------------------]   0%
(1/1) checking for file conflicts                  [######################] 100%
(0/1) checking available disk space                [----------------------]   0%
(1/1) checking available disk space                [######################] 100%
:: Processing package changes...
(1/1) reinstalling rar                             [----------------------]   0%
(1/1) reinstalling rar                             [######################] 100%
:: Running post-transaction hooks...
(1/1) Arming ConditionNeedsUpdate...

rar命令常见操作

直接运行 rar 命令就会列出所有可用的操作及其说明

rar
RAR 5.50   Copyright (c) 1993-2017 Alexander Roshal   11 Aug 2017
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
  iver          Display the version number
  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[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
  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]     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

创建rar压缩包

使用 a 子命令来生成rar压缩包,其语法为(注意不要在a前面加上"-")

rar a ${rar_file} ${files_or_folds}
RAR 5.50   Copyright (c) 1993-2017 Alexander Roshal   11 Aug 2017
Trial version             Type 'rar -?' for help

Evaluation copy. Please register.

Creating archive ahk.rar

Adding    我的AHK/DesktopSwitch.ahk                                          0%  OK 
Adding    我的AHK/scripts/DesktopSwitch.ahk                                  1%  OK 
Adding    我的AHK/scripts/winautohide.ahk                                    2%  OK 
Adding    我的AHK/scripts/hotStringHelper.ahk                                2%  OK 
Adding    我的AHK/scripts/ScriptSetting v1.0.3.ahk                           3%  OK 
Adding    我的AHK/scripts/AHK-gVim-by-sfufoet.ahk                            4%  OK 
Adding    我的AHK/Recorder.zip                                               5%  OK 
Adding    我的AHK/resources/ahk.ico                                         94%  OK 
Adding    我的AHK/AHK_Script_Manager.ahk                                    95%  OK 
Adding    我的AHK/includes/LibINI.ahk                                       97%  OK 
Adding    我的AHK/template.ahk                                              97%  OK 
Adding    我的AHK/scripts                                                    OK 
Adding    我的AHK/resources                                                  OK 
Adding    我的AHK/includes                                                   OK 
Adding    我的AHK                                                            OK 
Done

查看压缩包的内容

使用 l 子命令可以查看rar压缩包中的内容,其语法为

rar l ${rar_file}
RAR 5.50   Copyright (c) 1993-2017 Alexander Roshal   11 Aug 2017
Trial version             Type 'rar -?' for help

Archive: ahk.rar
Details: RAR 5

 Attributes      Size     Date    Time   Name
----------- ---------  ---------- -----  ----
 -rw-r--r--      5244  2017-05-22 22:16  我的AHK/DesktopSwitch.ahk
 -rw-r--r--      5244  2017-05-22 22:16  我的AHK/scripts/DesktopSwitch.ahk
 -rw-r--r--      4661  2008-06-15 15:35  我的AHK/scripts/winautohide.ahk
 -rw-r--r--      2068  2012-10-10 17:39  我的AHK/scripts/hotStringHelper.ahk
 -rw-r--r--      9035  2012-10-10 19:31  我的AHK/scripts/ScriptSetting v1.0.3.ahk
 -rw-r--r--       665  2010-03-15 22:13  我的AHK/scripts/AHK-gVim-by-sfufoet.ahk
 -rw-r--r--      6792  2017-05-22 22:16  我的AHK/Recorder.zip
 -rw-r--r--    588486  2009-02-25 23:00  我的AHK/resources/ahk.ico
 -rw-r--r--      5740  2012-10-12 16:11  我的AHK/AHK_Script_Manager.ahk
 -rw-r--r--     12521  2008-10-01 00:57  我的AHK/includes/LibINI.ahk
 -rw-r--r--      1599  2013-06-15 12:49  我的AHK/template.ahk
 drwxr-xr-x         0  2017-05-22 22:16  我的AHK/scripts
 drwxr-xr-x         0  2017-05-22 22:16  我的AHK/resources
 drwxr-xr-x         0  2017-05-22 22:16  我的AHK/includes
 drwx------         0  2017-05-22 22:16  我的AHK
----------- ---------  ---------- -----  ----
               642055                    15

压缩包解压

使用 x 子命令可以将压缩包内容解压到当前目录中,比如

cd /tmp/
rar x ~/${rar_file}
ls -l
RAR 5.50   Copyright (c) 1993-2017 Alexander Roshal   11 Aug 2017
Trial version             Type 'rar -?' for help


Extracting from /home/lujun9972/ahk.rar

Creating    我的AHK                                                     OK
Extracting  我的AHK/DesktopSwitch.ahk                                        1%  OK 
Creating    我的AHK/scripts                                             OK
Extracting  我的AHK/scripts/DesktopSwitch.ahk                                3%  OK 
Extracting  我的AHK/scripts/winautohide.ahk                                  4%  OK 
Extracting  我的AHK/scripts/hotStringHelper.ahk                              5%  OK 
Extracting  我的AHK/scripts/ScriptSetting v1.0.3.ahk                         7%  OK 
Extracting  我的AHK/scripts/AHK-gVim-by-sfufoet.ahk                          7%  OK 
Extracting  我的AHK/Recorder.zip                                            13%  OK 
Creating    我的AHK/resources                                           OK
Extracting  我的AHK/resources/ahk.ico                                       95%  OK 
Extracting  我的AHK/AHK_Script_Manager.ahk                                  96%  OK 
Creating    我的AHK/includes                                            OK
Extracting  我的AHK/includes/LibINI.ahk                                     98%  OK 
Extracting  我的AHK/template.ahk                                            99%  OK 
All OK
总用量 2040
drwx------ 2 lujun9972 lujun9972      60 6月   7 15:42 babel-eM2BUh
drwx------ 2 lujun9972 lujun9972      60 6月   7 10:01 emacs1000
-rw------- 1 lujun9972 lujun9972       0 6月   7 15:42 emacsS37kuE
-rw-r--r-- 1 lujun9972 lujun9972   22010 6月   7 10:01 error.log
srw------- 1 lujun9972 lujun9972       0 6月   7 09:48 fcitx-socket-:0
drwxr-xr-x 2 lujun9972 lujun9972      60 6月   7 09:48 hsperfdata_lujun9972
-rw-r--r-- 1 lujun9972 lujun9972    4794 6月   7 09:55 info.log
drwxr-xr-x 2 lujun9972 lujun9972      60 6月   7 12:46 NutstoreTmp0xyz
-rw------- 1 lujun9972 lujun9972     147 6月   7 09:48 serverauth.5GIpkFqfHm
drwx------ 2 lujun9972 lujun9972      40 6月   7 10:01 Temp-42f248da-c89b-4663-b10a-1303fed599b9
-rw-r--r-- 1 lujun9972 lujun9972  533160 6月   7 12:53 tmp-2kn.xpi
-rw-r--r-- 1 lujun9972 lujun9972 1350380 6月   7 12:53 tmp-4dq.xpi
-rw-r--r-- 1 lujun9972 lujun9972  159994 6月   7 12:53 tmp-7xz.xpi
srwx------ 1 root      root            0 6月   7 09:34 wpa_ctrl_475-1
drwx------ 5 lujun9972 lujun9972     180 5月  22 2017 我的AHK

当想创建带密码保护的压缩包或需要解压带密码保护的压缩包时,就需要在 a / x 子命令后再接上 -p 选项

你可以直接使用 -p<password> 的方式来直接指定密码,也可以只使用 -p ,这种情况下rar会提示用户手工输入密码

设置压缩级别

使用 -m0-m5 来设置压缩级别,其中0级表示只打包不压缩,这种压缩速度很快,而5表示最大级别的压缩,但压缩速度会很慢,默认为3级


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK