導航:首頁 > 文件處理 > python實現linux解壓rar

python實現linux解壓rar

發布時間:2022-04-04 08:25:01

Ⅰ 如何在linux下用命令解壓rar文件

1.解壓rar文件需要unrar命令,要使用這種命令我們必須安裝rarlinux,我們可以在終端使用yum install rar;

python 3.2版本 解壓rar/zip到指定目錄

#!/usr/bin/env python3
import os,zipfile
def Zip(target_dir):
target_file=os.path.basename(os.getcwd())+'.zip'
zip_opt=input("Will you zip all the files in this dir?(Choose 'n' you should add files by hand)y/n: ")
while True:
if zip_opt=='y': #compress all the files in this dir
filenames=os.listdir(os.getcwd()) #get the file-list of this dir
zipfiles=zipfile.ZipFile(os.path.join(target_dir,target_file),'w',compression=zipfile.ZIP_DEFLATED)
for files in filenames:
zipfiles.write(files)
zipfiles.close()
print("Zip finished!")
break
elif zip_opt=='n': #compress part of files of this dir
filenames=list(input("Please input the files' name you wanna zip:"))
zipfiles=zipfile.ZipFile(os.path.join(target_dir,target_file),'w',compression=zipfile.ZIP_DEFLATED)
for files in filenames:
zipfiles.write(files)
zipfiles.close()
print("Zip finished!")
break
else:
print("Please in put the character 'y' or 'n'")
zip_opt=input("Will you zip all the files in this dir?(Choose 'n' you should add files by hand)y/n: ")
def Unzip(target_dir):
target_name=input("Please input the file you wanna unzip:")
zipfiles=zipfile.ZipFile(target_name,'r')
zipfiles.extractall(os.path.join(target_dir,os.path.splitext(target_name)[0]))
zipfiles.close()
print("Unzip finished!")
def main():
opt=input("What are you gonna do?Zip choose 'y',unzip choose 'n'.y/n: ")
while True:
if opt=='y': #compress files
zip_dir=input("Please input the absdir you wanna put the zip file in:")
Zip(zip_dir)
break
elif opt=='n': #unzip files
unzip_dir=input("Please input the absdir you wanna put the zip file in(Nothing should be done if you wann unzip files in the current dir):")
if unzip_dir=='':
Unzip(os.getcwd())
else:
Unzip(unzip_dir)
break
else:
print("Please input the character 'y' or 'n'")
opt=input("What are you gonna do?Zip choose 'y',unzip choose 'n'.y/n: ")
if __name__=='__main__':
main()
解壓和壓縮都有,自己稍微改改解壓的文件名就行了

Ⅲ linux怎樣解壓rar

Linux下如何解壓.zip和.rar文件,對於Window下的常見壓縮文件.zip和.rar,Linux也有相應的方法來解壓它們:
1)對於zip linux下提供了zip和unzip程序,zip是壓縮程序,unzip是解壓程序。它們的參數選項很多,這里只做簡單介紹,舉例說明一下其用法:
# zip all.zip *.jpg 這條命令是將所有.jpg的文件壓縮成一個zip包
# unzip all.zip
這條命令是將all.zip中的所有文件解壓出來
2)對於.rar要在linux下處理.rar文件,需要安裝RAR for Linux,可以從網上下載,但要記住,RAR for Linux 不是免費的;可從http://www.rarsoft.com/download.htm下載RAR 3。60 for Linux ,然後安裝:
# tar -xzpvf rarlinux-3.2.0.tar.gz
# cd rar
# make
這樣就安裝好了,安裝後就有了rar和unrar這兩個程序,rar是壓縮程序,unrar是解壓程序。它們的參數選項很多,舉例說明一下其用法:
# rar a all *.jpg
這條命令是將所有.jpg的文件壓縮成一個rar包,名為all.rar,該程序會將.rar 擴展名將自動附加到包名後。
# unrar e all.rar
這條命令是將all.rar中的所有文件解壓出來
總結
1、*.tar 用 tar –xvf 解壓
2、*.gz 用 gzip -d或者gunzip 解壓
3、*.tar.gz和*.tgz 用 tar –xzf 解壓
4、*.bz2 用 bzip2 -d或者用bunzip2 解壓
5、*.tar.bz2用tar –xjf 解壓
6、*.Z 用 uncompress 解壓
7、*.tar.Z 用tar –xZf 解壓
8、*.rar 用 unrar e解壓
9、*.zip 用 unzip 解壓

Ⅳ linux操作系統下怎樣解壓rar文件

1、首先解壓rar文件需要unrar命令,要使用這種命令我們必須安裝rarlinux,我們可以在終端使用yum install rar,如果沒有可安裝的程序包,我們可以自行下載,上網搜搜就能搜到。

注意事項

Ⅳ linux中如何解壓rar壓縮包

缺少 unrar 這個包,你把它裝上,
可聯網的
1.若是redhat 系列的,可用yum install unrar解決。
2.debian系列的.可用
apt-get install unrar
aptitude install unrar
3.suse系列的 在軟體中心處可以直接打名稱找。
4.mandriva系列的。urpmi unrar
不能聯網的。直接下載,忘記了網站,google unrar rpm 或google unrar deb

Ⅵ 在 LINUX中用命令 解壓縮RAR格式

到http://www.rarlab.com/download.htm下載一個用於解壓rar文件 的包,解壓後做以下事情
1,解壓掉tar.gz包 解壓到一個文件夾下(此處以/home為例)
2,打開終端 輸入 su
然後輸入你的root密碼
此時變成[root@username ~]$後輸入
cp -rf /home/rar /bin
執行後輸入
cp -rf /home/unrar /bin
3.測試;輸入
rar
出現一大堆命令:說明rar正常能用了
4.輸入 rar -help
出現ra的命令幫助,學習之
5,解壓rar文件,直接用歸檔管理器就可以解壓
(對於壓縮文件,建議壓成zip格式,以便各種系統不需要任何額外程序的安裝就能打開)
額外說明:本人系統fedora16並且不斷更新,
上述原理:因為每個命令(如ping,su,cp等)都會對應一個2進制文件,我們之所以能執行這些命令是應為在 /bin 內都有這些文件,要執行命令就需要將執行這些命令對應的二進制文件(控制台程序)移到終端對應的文件夾(/bin)中(類比於不太熟悉的windows下的system32文件夾);之所以要獲取root許可權,是應為/bin是root級的
3,剛剛這樣做了,並且成功了,若你操作成功,請採納為最佳答案 以供初接觸fedora的童鞋參考

Ⅶ python腳本如何解壓指定路徑下的所有rar文件有沒有rar的模塊用

有個unrar模塊
https://pypi.python.org/pypi/unrar/0.2

Ⅷ 在Linux下如何解壓rar文件(hmkart)

下載rar for Linux 3.2.0,解壓開後make
然後可以用unrar e youfilename.rar解壓rar文件
可以多關.注《Linux就該這么學》這本書,我都是從這裡面學到的
"

Ⅸ linux解壓rar

沒搞過linux手機,一般linux解壓都用個叫unrar的軟體,你找找有沒有針對你的手機系統做好的。不知道手機里怎麼搞。unrar應該是可以獲得源代碼的,google去看看能不能自己編譯一個。

閱讀全文

與python實現linux解壓rar相關的資料

熱點內容
歌詞滾動效果android 瀏覽:14
程序員一天的六場戰斗 瀏覽:797
自製壓縮泵的做法 瀏覽:622
androidstring變數 瀏覽:247
數學乘法速演算法 瀏覽:986
壓縮包製作後照片順序怎麼改 瀏覽:680
fibonacci數列演算法 瀏覽:775
產品經理要和程序員吵架嗎 瀏覽:252
grub2命令行 瀏覽:618
無法獲取加密卡信息 瀏覽:774
雲伺服器網卡充值 瀏覽:509
編程就是軟體 瀏覽:49
伺服器如何添加許可權 瀏覽:437
引用指針編程 瀏覽:851
手機加密日記本蘋果版下載 瀏覽:64
命令行括弧 瀏覽:176
java程序升級 瀏覽:490
排序演算法之插入類 瀏覽:227
gcccreate命令 瀏覽:73
海爾監控用什麼app 瀏覽:65