久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

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

162次閱讀
沒有評論

共計 4299 個字符,預計需要花費 11 分鐘才能閱讀完成。

自動寫代碼機器人,免費開通

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

1. 使用 diff 命令比較文件

在我們平常操作當中,比較兩個文件的差異最簡單的方法可能就是使用 diff 命令。diff 命令的輸出將使用 和   符號顯示兩個文件之間的差異,利用這個特性我們可以找到相同的文件。

當兩個文件有差異時,diff 命令將輸出差異點:

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

如果你的 diff 命令沒有輸出,則表示兩個文件相同:

$ diff home.html index.html $

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

2. 使用校驗和

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

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

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

3. 使用 find 命令

雖然 find 命令沒有查找重復文件的選項,但是它卻可用于按名稱或類型搜索文件并運行 cksum 命令。具體操作如下。

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

4. 使用 fslint 命令

fslint   命令可以用來專門查找重復文件。但是這里有個注意事項,就是我們需要給它一個起始位置。如果我們需要運行大量文件,該命令可能需要相當長的時間才能完成查找。

$ 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   命令還將尋找重復的 (相同內(nèi)容的) 文件。被稱為“冗余數(shù)據(jù)查找”,該命令可以根據(jù)文件日期確定哪些文件是原始文件,這對我們選擇刪除重復項很有幫助,因為它會刪除較新的文件。

$ 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 中運行。

$ 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) 和跟隨符號鏈接 (-followsymlinks) 之類的選項。下面詳細解釋它的常用選項。

這里需要我們注意一下,rdfind 命令提供了使用 -deleteduplicates true   設置刪除重復文件的選項。顧名思義,使用這個選項它將自動刪重復的文件。

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

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

6. 使用 fdupes 命令

fdupes 命令也可以很容易地識別重復文件,并提供了大量有用的選項。在最簡單的操作中,它會把重復文件放在一起,如下所示:

$ 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 選項代表遞歸,表示它將在各個目錄下面使用遞歸的方式來查找重復文件。但是,Linux 下有許多重復文件是很重要的(比如用戶的 .bashrc 和  .profile 文件),如果被刪除將導致系統(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 命令的常用選項如下表所示:

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

向 AI 問一下細節(jié)

丸趣 TV 網(wǎng) – 提供最優(yōu)質(zhì)的資源集合!

正文完
 
丸趣
版權(quán)聲明:本站原創(chuàng)文章,由 丸趣 2023-12-07發(fā)表,共計4299字。
轉(zhuǎn)載說明:除特殊說明外本站除技術(shù)相關(guān)以外文章皆由網(wǎng)絡搜集發(fā)布,轉(zhuǎn)載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 黔西| 宜城市| 萨迦县| 曲阳县| 永和县| 格尔木市| 晋城| 墨江| 卢湾区| 阜南县| 昭苏县| 廊坊市| 永年县| 崇阳县| 瓦房店市| 宝清县| 麻江县| 汾西县| 瑞安市| 山阴县| 读书| 从化市| 大悟县| 江津市| 安庆市| 渝中区| 崇文区| 象州县| 紫阳县| 曲阳县| 张家界市| 江津市| 揭阳市| 彭州市| 鹤壁市| 城市| 蕉岭县| 永和县| 兴业县| 陵川县| 南丹县|