因為后臺錄入的同事,上傳文件的時候,給文件取了相同的名字,但不同的后綴名,由于文件路徑非常深,大概十層左右,每一層又有幾十個文件,所以人工找起來非常麻煩,所以寫了個腳本,幫他們實現(xiàn)查找指定目錄下所有子目錄及文件,找出相同文件名,不同后綴的文件,然后,手動保留其中一個。
模擬測試:
linux-8hij:/tmp/test # ll
total 4
-rw-r--r-- 1 root root 0 Mar 9 02:04 1.png
-rw-r--r-- 1 root root 0 Mar 9 02:04 1.txt
drwxr-xr-x 2 root root 4096 Mar 9 02:05 test1
linux-8hij:/tmp/test/test1 # ll
total 0
-rw-r--r-- 1 root root 0 Mar 9 02:05 11.jpg
-rw-r--r-- 1 root root 0 Mar 9 02:05 11.log
-rw-r--r-- 1 root root 0 Mar 9 02:05 2.log
運行結(jié)果:
linux-8hij:/tmp # ./find_name.sh /tmp
The directory /tmp including same name file:
The directory /tmp/.ICE-unix including same name file:
The directory /tmp/.X11-unix including same name file:
The directory /tmp/gconfd-root including same name file:
The directory /tmp/gconfd-root/lock including same name file:
The directory /tmp/gpg-PIEU09 including same name file:
The directory /tmp/test including same name file:
/tmp/test/1.txt
/tmp/test/1.png
The directory /tmp/test/test1 including same name file:
/tmp/test/test1/11.jpg
/tmp/test/test1/11.log
查看記錄:
linux-8hij:/tmp # cat /tmp/samefile.txt
/tmp/test/1.txt /tmp/test/1.png
/tmp/test/test1/11.jpg /tmp/test/test1/11.log
通過這個腳本可以實現(xiàn)指定目錄下同名但不同后綴名的查找,可以拓展為刪除指定的文件的腳本,覺得很實用,分享一下
標(biāo)簽:泰安 昌都 臨滄 ???/a> 南京 西寧 宿遷 營口
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《查找目錄下同名但不同后綴名文件的shell腳本代碼》,本文關(guān)鍵詞 查找,目,錄下,同名,但,不同,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。