linux中怎么找到系統(tǒng)里的重復(fù)文件并快速釋放磁盤空間

這篇文章主要介紹linux中怎么找到系統(tǒng)里的重復(fù)文件并快速釋放磁盤空間,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到鄂爾多斯網(wǎng)站設(shè)計(jì)與鄂爾多斯網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都網(wǎng)站制作、做網(wǎng)站、外貿(mào)營(yíng)銷網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、空間域名、網(wǎng)絡(luò)空間、企業(yè)郵箱。業(yè)務(wù)覆蓋鄂爾多斯地區(qū)。

1. 使用 diff 命令比較文件

在我們平常操作當(dāng)中,比較兩個(gè)文件的差異最簡(jiǎn)單的方法可能就是使用 diff 命令。diff 命令的輸出將使用 < 和 >  符號(hào)顯示兩個(gè)文件之間的差異,利用這個(gè)特性我們可以找到相同的文件。

當(dāng)兩個(gè)文件有差異時(shí),diff 命令將輸出差異點(diǎn):

$ diff index.html backup.html 2438a2439,2441 > <pre> > That's all there is to report. > </pre>

如果你的 diff 命令沒(méi)有輸出,則表示兩個(gè)文件相同:

$ diff home.html index.html $

但是, diff 命令的缺點(diǎn)是它一次只能比較兩個(gè)文件,如果我們要比較多個(gè)文件,這樣兩個(gè)兩個(gè)比較效率肯定非常低下。

2. 使用校驗(yàn)和

校驗(yàn)和命令 cksum 會(huì)根據(jù)一定的算法將文件的內(nèi)容計(jì)算成一個(gè)很長(zhǎng)的數(shù)字(如2819078353  228029)。雖然算出的結(jié)果不是絕對(duì)唯一,但是內(nèi)容不相同的文件導(dǎo)致校驗(yàn)和相同的可能性跟中國(guó)男足進(jìn)世界杯差不多。

$ cksum *.html 2819078353 228029 backup.html 4073570409 227985 home.html 4073570409 227985 index.html

在我們上面的操作中,我們可以看到第二個(gè)和第三個(gè)文件校驗(yàn)和是相同的,所以我們可以認(rèn)為這兩個(gè)文件是一樣的。

3. 使用 find 命令

雖然 find 命令沒(méi)有查找重復(fù)文件的選項(xiàng),但是它卻可用于按名稱或類型搜索文件并運(yùn)行cksum 命令。具體操作如下。

$ find . -name "*.html" -exec cksum {} \; 4073570409 227985 ./home.html 2819078353 228029 ./backup.html 4073570409 227985 ./index.html

4. 使用 fslint 命令

fslint  命令可以用來(lái)專門查找重復(fù)文件。但是這里有個(gè)注意事項(xiàng),就是我們需要給它一個(gè)起始位置。如果我們需要運(yùn)行大量文件,該命令可能需要相當(dāng)長(zhǎng)的時(shí)間才能完成查找。

$ fslint . -----------------------------------file name lint -------------------------------Invalid utf8 names -----------------------------------file case lint ----------------------------------DUPlicate files    <== home.html index.html -----------------------------------Dangling links --------------------redundant characters in links ------------------------------------suspect links --------------------------------Empty Directories ./.gnupg ----------------------------------Temporary Files ----------------------duplicate/conflicting Names ------------------------------------------Bad ids -------------------------Non Stripped executables

Tips:我們必須在系統(tǒng)上安裝 fslint ,還需要將它添加到搜索路徑中:

$ export PATH=$PATH:/usr/share/fslint/fslint

5. 使用 rdfind 命令

rdfind  命令還將尋找重復(fù)的(相同內(nèi)容的)文件。被稱為“冗余數(shù)據(jù)查找”,該命令可以根據(jù)文件日期確定哪些文件是原始文件,這對(duì)我們選擇刪除重復(fù)項(xiàng)很有幫助,因?yàn)樗鼤?huì)刪除較新的文件。

$ rdfind ~ Now scanning "/home/alvin", found 12 files. Now have 12 files in total. Removed 1 files due to nonunique device and inode. Total size is 699498 bytes or 683 KiB Removed 9 files due to unique sizes from list.2 files left. Now eliminating candidates based on first bytes:removed 0 files from list.2 files left. Now eliminating candidates based on last bytes:removed 0 files from list.2 files left. Now eliminating candidates based on sha1 checksum:removed 0 files from list.2 files left. It seems like you have 2 files that are not unique Totally, 223 KiB can be reduced. Now making results file results.txt

我們還可以在 dryrun 中運(yùn)行。

$ rdfind -dryrun true ~ (DRYRUN MODE) Now scanning "/home/alvin", found 12 files. (DRYRUN MODE) Now have 12 files in total. (DRYRUN MODE) Removed 1 files due to nonunique device and inode. (DRYRUN MODE) Total size is 699352 bytes or 683 KiB Removed 9 files due to unique sizes from list.2 files left. (DRYRUN MODE) Now eliminating candidates based on first bytes:removed 0 files from list.2 files left. (DRYRUN MODE) Now eliminating candidates based on last bytes:removed 0 files from list.2 files left. (DRYRUN MODE) Now eliminating candidates based on sha1 checksum:removed 0 files from list.2 files left. (DRYRUN MODE) It seems like you have 2 files that are not unique (DRYRUN MODE) Totally, 223 KiB can be reduced. (DRYRUN MODE) Now making results file results.txt

rdfind  命令還提供一些忽略空文件(-ignoreempty)和跟隨符號(hào)鏈接(-followsymlinks)之類的選項(xiàng)。下面詳細(xì)解釋它的常用選項(xiàng)。

linux中怎么找到系統(tǒng)里的重復(fù)文件并快速釋放磁盤空間

這里需要我們注意一下,rdfind命令提供了使用 -deleteduplicates true  設(shè)置刪除重復(fù)文件的選項(xiàng)。顧名思義,使用這個(gè)選項(xiàng)它將自動(dòng)刪重復(fù)的文件。

$ rdfind -deleteduplicates true . ... Deleted 1 files.    <==

當(dāng)然,前提是我們也必須在系統(tǒng)上安裝 rdfind 命令。

6. 使用 fdupes 命令

fdupes 命令也可以很容易地識(shí)別重復(fù)文件,并提供了大量有用的選項(xiàng)。在最簡(jiǎn)單的操作中,它會(huì)把重復(fù)文件放在一起,如下所示:

$ fdupes ~ /home/alvin/UPGRADE /home/alvin/mytwin  /home/alvin/lp.txt /home/alvin/lp.man  /home/alvin/penguin.png /home/alvin/penguin0.png /home/alvin/hideme.png

-r 選項(xiàng)代表遞歸,表示它將在各個(gè)目錄下面使用遞歸的方式來(lái)查找重復(fù)文件。但是,Linux 下有許多重復(fù)文件是很重要的(比如用戶的 .bashrc 和  .profile 文件),如果被刪除將導(dǎo)致系統(tǒng)異常。

# fdupes -r /home /home/shark/home.html /home/shark/index.html  /home/dory/.bashrc /home/eel/.bashrc  /home/nemo/.profile /home/dory/.profile /home/shark/.profile  /home/nemo/tryme /home/shs/tryme  /home/shs/arrow.png /home/shs/PNGs/arrow.png  /home/shs/11/files_11.zip /home/shs/ERIC/file_11.zip  /home/shs/penguin0.jpg /home/shs/PNGs/penguin.jpg /home/shs/PNGs/penguin0.jpg  /home/shs/Sandra_rotated.png /home/shs/PNGs/Sandra_rotated.png

fdupes 命令的常用選項(xiàng)如下表所示:

linux中怎么找到系統(tǒng)里的重復(fù)文件并快速釋放磁盤空間

以上是“l(fā)inux中怎么找到系統(tǒng)里的重復(fù)文件并快速釋放磁盤空間”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

網(wǎng)站標(biāo)題:linux中怎么找到系統(tǒng)里的重復(fù)文件并快速釋放磁盤空間
網(wǎng)站URL:http://muchs.cn/article48/jpgdhp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營(yíng)銷型網(wǎng)站建設(shè)、關(guān)鍵詞優(yōu)化、網(wǎng)站改版、品牌網(wǎng)站建設(shè)、網(wǎng)站制作、做網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)