自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

如何找到系統(tǒng)里的重復(fù)文件,快速釋放磁盤空間?

存儲 存儲軟件
不管是 Windows 電腦還是 Linux 電腦,在使用的過程中,或多或少都會留下很多重復(fù)的文件。這些文件不僅會占用我們的磁盤,還會拖累我們的系統(tǒng),所以,很有必要干掉這些重復(fù)的文件。

 不管是 Windows 電腦還是 Linux 電腦,在使用的過程中,或多或少都會留下很多重復(fù)的文件。這些文件不僅會占用我們的磁盤,還會拖累我們的系統(tǒng),所以,很有必要干掉這些重復(fù)的文件。

[[282959]]

本文將介紹 6 種方法找到系統(tǒng)里的重復(fù)文件,讓你快速釋放硬盤空間!

1. 使用 diff 命令比較文件

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

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

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

 

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

 

  1. $ diff home.html index.html 

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

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

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

 

  1. $ cksum *.html 
  2. 2819078353 228029 backup.html 
  3. 4073570409 227985 home.html 
  4. 4073570409 227985 index.html 

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

3. 使用 find 命令

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

 

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

4. 使用 fslint 命令

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

 

  1. $ fslint . 
  2. -----------------------------------file name lint 
  3. -------------------------------Invalid utf8 names 
  4. -----------------------------------file case lint 
  5. ----------------------------------DUPlicate files    <== 
  6. home.html 
  7. index.html 
  8. -----------------------------------Dangling links 
  9. --------------------redundant characters in links 
  10. ------------------------------------suspect links 
  11. --------------------------------Empty Directories 
  12. ./.gnupg 
  13. ----------------------------------Temporary Files 
  14. ----------------------duplicate/conflicting Names 
  15. ------------------------------------------Bad ids 
  16. -------------------------Non Stripped executables 

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

 

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

5. 使用 rdfind 命令

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

 

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

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

 

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

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

 

 

 

 

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

 

  1. $ rdfind -deleteduplicates true . 
  2.  
  3. ... 
  4.  
  5. Deleted 1 files.    <== 

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

6. 使用 fdupes 命令

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

 

  1. $ fdupes ~ 
  2. /home/alvin/UPGRADE 
  3. /home/alvin/mytwin 
  4.  
  5. /home/alvin/lp.txt 
  6. /home/alvin/lp.man 
  7.  
  8. /home/alvin/penguin.png 
  9. /home/alvin/penguin0.png 
  10. /home/alvin/hideme.png 

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

 

  1. # fdupes -r /home 
  2. /home/shark/home.html 
  3. /home/shark/index.html 
  4.  
  5. /home/dory/.bashrc 
  6. /home/eel/.bashrc 
  7.  
  8. /home/nemo/.profile 
  9. /home/dory/.profile 
  10. /home/shark/.profile 
  11.  
  12. /home/nemo/tryme 
  13. /home/shs/tryme 
  14.  
  15. /home/shs/arrow.png 
  16. /home/shs/PNGs/arrow.png 
  17.  
  18. /home/shs/11/files_11.zip 
  19. /home/shs/ERIC/file_11.zip 
  20.  
  21. /home/shs/penguin0.jpg 
  22. /home/shs/PNGs/penguin.jpg 
  23. /home/shs/PNGs/penguin0.jpg 
  24.  
  25. /home/shs/Sandra_rotated.png 
  26. /home/shs/PNGs/Sandra_rotated.png 

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

 

 

 

 

小結(jié)

Linux 系統(tǒng)為我們提供了很多用于定位和刪除重復(fù)文件的工具,使用這些工具將快速找到磁盤里的重復(fù)文件并刪除它們。希望本次分享能給大家?guī)韼椭鷡

責(zé)任編輯:華軒 來源: 良許Linux
相關(guān)推薦

2019-11-20 10:24:43

Linux重復(fù)文件磁盤

2023-03-03 00:07:24

2022-11-06 19:34:53

UbuntuLinux

2023-03-05 22:11:20

刪除文件磁盤

2020-01-10 16:00:16

Windows 10更新磁盤空間

2023-04-18 23:31:59

Linux磁盤系統(tǒng)

2022-08-07 12:17:21

Snap磁盤

2018-07-24 08:50:40

Linux磁盤空間磁盤利用率

2010-04-08 15:24:36

Windows磁盤空間

2020-11-17 11:19:48

Linux磁盤空間

2020-04-09 16:29:40

Windows 10系統(tǒng)更新微軟

2011-01-18 10:25:19

Linux磁盤分區(qū)

2018-01-03 08:42:40

Linux命令磁盤空間

2020-11-25 08:41:56

Windows

2015-11-25 13:37:52

磁盤空間LinuxUbuntu

2020-11-04 18:32:30

APTapt命令Linux

2010-05-27 17:51:55

Linux查看磁盤空間

2009-08-21 10:22:37

Linux系統(tǒng)磁盤空間管理工具

2021-02-11 08:11:50

Window10Docker容器

2024-11-28 13:16:47

Linux磁盤
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號