最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

在Linux上識(shí)別同樣內(nèi)容的文件詳解

 更新時(shí)間:2019年06月10日 11:23:54   作者:Sandra Henry-stocker  
這篇文章主要給大家介紹了關(guān)于如何在Linux上識(shí)別同樣內(nèi)容的文件的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Linux具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

前言

有時(shí)文件副本相當(dāng)于對(duì)硬盤空間的巨大浪費(fèi),并會(huì)在你想要更新文件時(shí)造成困擾。以下是用來(lái)識(shí)別這些文件的六個(gè)命令。

在最近的帖子中,我們看了 如何識(shí)別并定位硬鏈接的文件 (即,指向同一硬盤內(nèi)容并共享 inode)。在本文中,我們將查看能找到具有相同 內(nèi)容 ,卻不相鏈接的文件的命令。

硬鏈接很有用是因?yàn)樗鼈兡軌蚴刮募娣旁谖募到y(tǒng)內(nèi)的多個(gè)地方卻不會(huì)占用額外的硬盤空間。另一方面,有時(shí)文件副本相當(dāng)于對(duì)硬盤空間的巨大浪費(fèi),在你想要更新文件時(shí)也會(huì)有造成困擾之虞。在本文中,我們將看一下多種識(shí)別這些文件的方式。

用 diff 命令比較文件

可能比較兩個(gè)文件最簡(jiǎn)單的方法是使用 diff 命令。輸出會(huì)顯示你文件的不同之處。 < 和 > 符號(hào)代表在當(dāng)參數(shù)傳過(guò)來(lái)的第一個(gè)( < )或第二個(gè)( > )文件中是否有額外的文字行。在這個(gè)例子中,在 backup.html 中有額外的文字行。

$ 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è)文件并且你必須指定用來(lái)比較的文件,這篇帖子中的一些命令可以為你找到多個(gè)重復(fù)文件。

使用校驗(yàn)和

cksum (checksum) 命令計(jì)算文件的校驗(yàn)和。校驗(yàn)和是一種將文字內(nèi)容轉(zhuǎn)化成一個(gè)長(zhǎng)數(shù)字(例如2819078353 228029)的數(shù)學(xué)簡(jiǎn)化。雖然校驗(yàn)和并不是完全獨(dú)有的,但是文件內(nèi)容不同校驗(yàn)和卻相同的概率微乎其微。

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

在上述示例中,你可以看到產(chǎn)生同樣校驗(yàn)和的第二個(gè)和第三個(gè)文件是如何可以被默認(rèn)為相同的。

使用 find 命令

雖然 find 命令并沒(méi)有尋找重復(fù)文件的選項(xiàng),它依然可以被用來(lái)通過(guò)名字或類型尋找文件并運(yùn)行 cksum 命令。例如:

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

使用 fslint 命令

fslint 命令可以被特地用來(lái)尋找重復(fù)文件。注意我們給了它一個(gè)起始位置。如果它需要遍歷相當(dāng)多的文件,這就需要花點(diǎn)時(shí)間來(lái)完成。注意它是如何列出重復(fù)文件并尋找其它問(wèn)題的,比如空目錄和壞 ID。

$ 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

你可能需要在你的系統(tǒng)上安裝 fslint 。你可能也需要將它加入你的命令搜索路徑:

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

使用 rdfind 命令

rdfind 命令也會(huì)尋找重復(fù)(相同內(nèi)容的)文件。它的名字意即“重復(fù)數(shù)據(jù)搜尋”,并且它能夠基于文件日期判斷哪個(gè)文件是原件——這在你選擇刪除副本時(shí)很有用因?yàn)樗鼤?huì)移除較新的文件。

$ rdfind ~
Now scanning "/home/shark", 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)行這個(gè)命令 (換句話說(shuō),僅僅匯報(bào)可能會(huì)另外被做出的改動(dòng))。

$ rdfind -dryrun true ~
(DRYRUN MODE) Now scanning "/home/shark", 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 )的功能。查看 man 頁(yè)面獲取解釋。

-ignoreempty    ignore empty files
-minsize    ignore files smaller than speficied size
-followsymlinks   follow symbolic links
-removeidentinode  remove files referring to identical inode
-checksum    identify checksum type to be used
-deterministic   determiness how to sort files
-makesymlinks    turn duplicate files into symbolic links
-makehardlinks   replace duplicate files with hard links
-makeresultsfile  create a results file in the current directory
-outputname   provide name for results file
-deleteduplicates  delete/unlink duplicate files
-sleep     set sleep time between reading files (milliseconds)
-n, -dryrun   display what would have been done, but don't do it

注意 rdfind 命令提供了 -deleteduplicates true 的設(shè)置選項(xiàng)以刪除副本。希望這個(gè)命令語(yǔ)法上的小問(wèn)題不會(huì)惹惱你。;-)

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

你將可能需要在你的系統(tǒng)上安裝 rdfind 命令。試驗(yàn)它以熟悉如何使用它可能是一個(gè)好主意。

使用 fdupes 命令

fdupes 命令同樣使得識(shí)別重復(fù)文件變得簡(jiǎn)單。它同時(shí)提供了大量有用的選項(xiàng)——例如用來(lái)迭代的 -r 。在這個(gè)例子中,它像這樣將重復(fù)文件分組到一起:

$ fdupes ~
/home/shs/UPGRADE
/home/shs/mytwin

/home/shs/lp.txt
/home/shs/lp.man

/home/shs/penguin.png
/home/shs/penguin0.png
/home/shs/hideme.png

這是使用迭代的一個(gè)例子,注意許多重復(fù)文件是重要的(用戶的 .bashrc 和 .profile 文件)并且不應(yī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

fdupe 命令的許多選項(xiàng)列如下。使用 fdupes -h 命令或者閱讀 man 頁(yè)面獲取詳情。

-r --recurse   recurse
-R --recurse:  recurse through specified directories
-s --symlinks  follow symlinked directories
-H --hardlinks  treat hard links as duplicates
-n --noempty   ignore empty files
-f --omitfirst  omit the first file in each set of matches
-A --nohidden  ignore hidden files
-1 --sameline  list matches on a single line
-S --size    show size of duplicate files
-m --summarize  summarize duplicate files information
-q --quiet    hide progress indicator
-d --delete   prompt user for files to preserve
-N --noprompt  when used with --delete, preserve the first file in set
-I --immediate  delete duplicates as they are encountered
-p --permissions don't soncider files with different owner/group or
         permission bits as duplicates
-o --order=WORD order files according to specification
-i --reverse   reverse order while sorting
-v --version   display fdupes version
-h --help    displays help

fdupes 命令是另一個(gè)你可能需要安裝并使用一段時(shí)間才能熟悉其眾多選項(xiàng)的命令。

總結(jié)

Linux 系統(tǒng)提供能夠定位并(潛在地)能移除重復(fù)文件的一系列的好工具,以及能讓你指定搜索區(qū)域及當(dāng)對(duì)你所發(fā)現(xiàn)的重復(fù)文件時(shí)的處理方式的選項(xiàng)。

好了,以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。

via: https://www.networkworld.com/article/3390204/how-to-identify-same-content-files-on-linux.html#tk.rss_all

作者: Sandra Henry-Stocker 選題: lujun9972 譯者: tomjlw 校對(duì): wxy

相關(guān)文章

  • ubuntu20.04設(shè)置靜態(tài)ip地址(包括不同版本)

    ubuntu20.04設(shè)置靜態(tài)ip地址(包括不同版本)

    這篇文章主要介紹了ubuntu20.04設(shè)置靜態(tài)ip地址,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-06-06
  • vim編輯器常用命令總結(jié)

    vim編輯器常用命令總結(jié)

    這篇文章介紹了vim編輯器的常用命令,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-06-06
  • Linux下一個(gè)智能重啟Apache服務(wù)器的腳本分享

    Linux下一個(gè)智能重啟Apache服務(wù)器的腳本分享

    這篇文章主要介紹了Linux下一個(gè)智能重啟Apache服務(wù)器的腳本分享,當(dāng)檢測(cè)到腳本中所設(shè)定的服務(wù)器異常情況下便可執(zhí)行自動(dòng)重啟,需要的朋友可以參考下
    2015-07-07
  • Linux常用命令last的使用方法詳解

    Linux常用命令last的使用方法詳解

    最近在學(xué)習(xí)linux命令,學(xué)習(xí)到了last命令,發(fā)現(xiàn)很多同學(xué)對(duì)last命令不是很熟悉,last命令的功能列出目前與過(guò)去登入系統(tǒng)的用戶相關(guān)信息,下面這篇文章主要給大家介紹了關(guān)于Linux常用命令last的使用方法,需要的朋友可以參考借鑒。
    2017-08-08
  • Centos7 Mysql 5.6 多主一從 解決方案與詳細(xì)配置

    Centos7 Mysql 5.6 多主一從 解決方案與詳細(xì)配置

    這篇文章主要介紹了Centos7 Mysql 5.6 多主一從 解決方案與詳細(xì)配置,需要的朋友可以參考下
    2016-04-04
  • ubuntu開(kāi)機(jī)后使用使用終端運(yùn)行應(yīng)用程序的設(shè)置方法

    ubuntu開(kāi)機(jī)后使用使用終端運(yùn)行應(yīng)用程序的設(shè)置方法

    這篇文章主要給大家介紹了關(guān)于ubuntu開(kāi)機(jī)后使用使用終端運(yùn)行應(yīng)用程序的設(shè)置方法,文中通過(guò)圖文介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Mubuntu具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09
  • Linux上使用Docker下載和運(yùn)行Redis的完整步驟

    Linux上使用Docker下載和運(yùn)行Redis的完整步驟

    這篇文章主要介紹了Linux上使用Docker下載和運(yùn)行Redis的完整步驟,文中通過(guò)代碼示例給大家講解的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下
    2024-10-10
  • Linux命令?移動(dòng)/復(fù)制文件/目錄到指定目錄下的實(shí)現(xiàn)

    Linux命令?移動(dòng)/復(fù)制文件/目錄到指定目錄下的實(shí)現(xiàn)

    這篇文章主要介紹了Linux命令?移動(dòng)/復(fù)制文件/目錄到指定目錄下的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • Apache JMeter 5.5 下載安裝及設(shè)置中文圖文教程

    Apache JMeter 5.5 下載安裝及設(shè)置中文圖文教程

    這篇文章主要介紹了Apache JMeter 5.5 下載安裝以及設(shè)置中文教程,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-02-02
  • Linux系統(tǒng)設(shè)置PATH環(huán)境變量(3種方法)

    Linux系統(tǒng)設(shè)置PATH環(huán)境變量(3種方法)

    這篇文章主要介紹了Linux系統(tǒng)設(shè)置PATH環(huán)境變量(3種方法),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11

最新評(píng)論

武宁县| 宕昌县| 凌海市| 清水河县| 萨迦县| 平定县| 澎湖县| 铁岭市| 民权县| 田东县| 南岸区| 九寨沟县| 筠连县| 年辖:市辖区| 平武县| 安溪县| 耿马| 星子县| 肥东县| 江西省| 小金县| 随州市| 开封县| 进贤县| 晋中市| 呼图壁县| 平遥县| 博乐市| 光山县| 靖州| 五寨县| 鹿邑县| 玉屏| 青海省| 南宁市| 内丘县| 永嘉县| 壤塘县| 寻甸| 古蔺县| 托克托县|