Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

CentOS 安裝 rar 完整教學與常用命令用法詳解

以下為在 CentOS 系統上安裝 rar 並掌握其用法的完整步驟。

1、下載 rar 安裝包
官方下載頁面為 https://www.rarsoft.com/download.htm,請依據自己的操作系統架構選擇對應的二進位安裝包。以本例的 64 位 CentOS 為例,下載的檔案為 rarlinux-x64-5.4.b2.tar.gz。

2、安裝 rar

 [root@localhost Downloads]# tar -zxvf rarlinux-x64-5.4.b2.tar.gz rar/ rar/order.htm rar/acknow.txt rar/readme.txt rar/rar_static rar/default.sfx rar/license.txt rar/rarfiles.lst rar/whatsnew.txt rar/makefile rar/rar rar/unrar rar/rar.txt [root@localhost Downloads]# cd rar [root@localhost rar]# ls acknow.txt license.txt order.htm rarfiles.lst rar.txt unrar default.sfx makefile rar rar_static readme.txt whatsnew.txt [root@localhost rar]# make mkdir -p /usr/local/bin mkdir -p /usr/local/lib cp rar unrar /usr/local/bin cp rarfiles.lst /etc cp default.sfx /usr/local/lib [root@localhost rar]# rar RAR 5.40 beta 2 Copyright (c) 1993-2016 Alexander Roshal 30 May 2016 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>[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

3、rar 命令用法
例1:使用 a 命令將檔案或目錄加入壓縮檔。例如把 file1 加入 abc.rar,可用 a 或 m 命令。a 命令會把 file1 加入 abc.rar 並保留原檔,m 命令則是移動(壓縮完成後刪除原檔,注意 m 僅針對檔案操作)。

 [root@localhost ~]# rar a abc.rar file1

說明:若 abc.rar 不存在,會自動建立;若已存在,則把 file1 壓縮進去;若壓縮檔中已有同名 file1,則會更新它,而原檔仍保留於當前目錄。若改用 m 命令,則會把 file1 移動進壓縮檔。目錄也能套用相同操作。
注意:如果只輸入「rar a file1.rar」而未接檔名或目錄名,會把當前目錄下所有檔案與資料夾一併壓縮進 file1.rar,這一點務必留意。
例2:解壓 abc.rar 的內容,可用 e 或 x 命令。假設 abc.rar 內含 file1 與一個 test 目錄,test 目錄裡又有 file2:

 [root@localhost ~]# rar e abc.rar #不推薦

說明:使用 e 命令會把 file1 與 test 目錄下的 file2 全部解壓到當前目錄,且會打散原有的目錄結構。若想保留目錄結構,請改用 x 命令。

 [root@localhost ~]# rar x abc.rar #推薦

說明:此時會把 file1 與 test 目錄完整解壓到當前資料夾。
例3:為整個壓縮檔加上註解。

 [root@localhost ~]# rar c abc.rar

說明:執行後畫面下方會顯示

 Processing archive test. rarReading comment from stdin

並出現閃爍游標,在游標位置輸入註解內容,輸入完畢後按 Ctrl+D 結束。
例4:使用 cw 命令把整個檔案的註解寫入檔案。例如把 abc.rar 的註解寫進 test.txt:

 [root@localhost ~]# rar cw abc.rar test.txt

說明:若當前目錄沒有 test.txt,會自動建立並寫入註解;若已存在同名檔案,系統會詢問是否覆蓋,選擇 Yes 或 All 便會清空原內容再寫入 abc.rar 的註解。
例5:使用 d 命令刪除壓縮檔中的檔案或目錄。例如刪除 abc.rar 中的 file1:

 [root@localhost ~]# rar d abc.rar file1

說明:該命令會刪除 abc.rar 中的 file1,對目錄同樣有效。

解壓命令 unrar 的使用:

 [root@localhost ~]# unrar --help

用法:

 unrar 
 
- - <@listfiles...> <命令>
 e 解壓文件到當前目錄 l[t,b] 列出壓縮文檔信息[technical, bare] p 打印文件到標准輸出 t 測試壓縮我俄當 v[t,b] 列出壓縮文檔的詳細信息[technical,bare] x 解壓文件到完整路徑

unrar 的命令與 rar 效果一致,可看出 unrar 只涵蓋了 rar 的一部分功能,因此只要熟悉 rar 就能完成所有操作。

參數如下:
<命令>

 a 添加文件到壓縮檔案 c 添加壓縮檔案注釋(注釋的大小最大不能超過62000字節) cf 添加文件備注( 當使用'v'參數時顯示文件備注,最大不能超過32767字節) ch 改變壓縮檔案參數 cw 向指定文件寫入檔案備注 d 從檔案中刪除文件 e 解壓縮文件到當前目錄(不創建任何子目錄) f 刷新檔案中的文件(更新這些文件自它們被打包之後產生的變化,不在壓縮檔案中增加新的) i[par]= 在檔案中查找特定字符 k 鎖定檔案(任何試圖改變壓縮檔案中內容的命令都會被忽略) l[t,b] 列出檔案[technical, bare] m[f] 移動到壓縮檔案中[只針對文件] p 打印文件到標准輸出 r 修補壓縮檔案 rc 重建丟失的分卷 rn 重命名壓縮檔案中的文件 rr[N] 添加數據恢復記錄 rv[N] 創建恢復卷 s[name|-] 壓縮檔案與SFX(自解壓文檔)之間的轉換 t 測試壓縮檔案文件 u 更新壓縮檔案中的文件 v[t,b] 列出壓縮檔案的詳細信息[technical,bare] x 解壓縮到完整路徑 <選項> - 停止對選項的掃描 ad 追加檔案名稱到目標路徑 ag[format] 使用當前數據生成壓縮檔案名 ap 在檔案內部設置路徑 as 同步檔案內目錄 av 設置認證檢測(只有注冊版提供此功能) av- 關閉認證檢測 c- 關閉備注顯示 cfg- 關閉讀取設置 cl 轉換名稱為小寫字母 cu 轉換名稱為大寫字母 df 壓縮後刪除原文件 dh 打開共享文件 ds 關閉針對於穩固檔案的名稱排序 dw 壓縮後擦除文件 e[+] 設置文件排除與包含屬性 ed 不添加空目錄 en 不設置檔案結束塊 ep 名稱中不包含路徑 ep1 名稱中不包含基本文件目錄 ep3 展開路徑到完整包含的驅動器名 f 刷新文件 hp[password] 加密文件數據和文件頭部 id[c,d,p,q] 關閉消息 ierr 發送所有消息到標准錯誤輸出 ilog[name] 記錄錯誤日志到文件中(只有注冊版提供此功能) inul 關閉所有消息 isnd 打開聲音 k 鎖定壓縮檔案 kb 保持被解壓過的已損壞的文件 m<0..5> 設置壓縮等級(0-存儲...3-默認...5-最大) mc 設置高級壓縮參數 md Dictionary size in KB (64,128,256,512,1024,2048,4096 or A-G) ms[ext;ext] 存儲指定的文件類型 n 僅包含指定的文件 n@ 從標准輸入讀取文件名到包含內容中 n@ 在指定列表文件中包含文件 o[+|-] 設置重寫模式 ol 替文件保存符號連接作為連接 or 自動重命名文件 ow 保存活存儲文件的擁有者與群組 p[password] 設置密碼 p- 不詢問密碼 r 對子目錄進行遞歸操作 r0 僅用通配符名稱對子目錄進行遞歸操作 rr[N] 添加數據恢復記錄 rv[N] 創建恢復 s[,v[-],e] 創建穩固檔案壓縮 s- 關閉穩固檔案壓縮 sc[obj] 設置指定的字符串 sfx[name] 創建SFX檔案 si[name] 從標准輸入讀取數據 sl 處理文件的大小小於指定的值 sm 處理文件的大小大於指定的值 t 壓縮後測試文件 ta 處理修改日期為指定日期之後的文件,格式: YYYYMMDDHHMMSS tb 處理修改日期為指定日期之前的文件,格式: YYYYMMDDHHMMSS tk 保持檔案最初的時間 tl 設置檔案時間為據現在最近的文件時間 tn
Copyright © Linux教程網 All Rights Reserved