我有一個類似(幾乎相同)的問題,如(Keep latest file and delete all other) 除了我的文件列表不同,我不知道Python(試圖做到這一點在bash)的搜索類似的重複文件名(不同的日期戳文件末尾)
該目錄包含文件像這樣的例子:
mysql-2016-01-24/ *<-- dirname*
adsoglasi-2016-01-24-05.35.gz
adsoglasi-2016-01-24-09.35.gz
adsoglasi-2016-01-24-13.35.gz
adsoglasi-2016-01-24-17.35.gz
adsoglasi-2016-01-24-21.35.gz
ehoplit-2016-01-24-05.35.gz
ehoplit-2016-01-24-09.35.gz
ehoplit-2016-01-24-13.35.gz
ehoplit-2016-01-24-17.35.gz
ehoplit-2016-01-24-21.35.gz
posavje-2016-01-24-05.35.gz
posavje-2016-01-24-09.35.gz
posavje-2016-01-24-13.35.gz
posavje-2016-01-24-17.35.gz
posavje-2016-01-24-21.35.gz
export-mysql-baze-2016-01-24-05.35.log
export-mysql-baze-2016-01-24-09.35.log
export-mysql-baze-2016-01-24-13.35.log
export-mysql-baze-2016-01-24-17.35.log
export-mysql-baze-2016-01-24-21.35.log
flora-2016-01-24-05.35.gz
flora-2016-01-24-09.35.gz
flora-2016-01-24-13.35.gz
flora-2016-01-24-17.35.gz
flora-2016-01-24-21.35.gz
karcher-2016-01-24-05.35.gz
karcher-2016-01-24-09.35.gz
karcher-2016-01-24-13.35.gz
karcher-2016-01-24-17.35.gz
karcher-2016-01-24-21.35.gz
knjigarna-2016-01-24-05.35.gz
knjigarna-2016-01-24-09.35.gz
knjigarna-2016-01-24-13.35.gz
knjigarna-2016-01-24-17.35.gz
knjigarna-2016-01-24-21.35.gz
mysql-2016-01-24-05.35.gz
mysql-2016-01-24-09.35.gz
mysql-2016-01-24-13.35.gz
mysql-2016-01-24-17.35.gz
mysql-2016-01-24-21.35.gz
mysqlshow_grants-2016-01-24-05.36.49.gz
mysqlshow_grants-2016-01-24-09.36.50.gz
mysqlshow_grants-2016-01-24-13.36.48.gz
mysqlshow_grants-2016-01-24-17.36.48.gz
mysqlshow_grants-2016-01-24-21.36.49.gz
pohistvo-2016-01-24-05.35.gz
pohistvo-2016-01-24-09.35.gz
pohistvo-2016-01-24-13.35.gz
pohistvo-2016-01-24-17.35.gz
pohistvo-2016-01-24-21.35.gz
akord-2016-01-24-05.36.gz
akord-2016-01-24-09.36.gz
akord-2016-01-24-13.36.gz
akord-2016-01-24-17.36.gz
akord-2016-01-24-21.36.gz
ekomprof-2016-01-24-05.36.gz
ekomprof-2016-01-24-09.36.gz
ekomprof-2016-01-24-13.36.gz
ekomprof-2016-01-24-17.36.gz
ekomprof-2016-01-24-21.36.gz
gume-2016-01-24-05.36.gz
gume-2016-01-24-09.36.gz
gume-2016-01-24-13.36.gz
gume-2016-01-24-17.36.gz
gume-2016-01-24-21.36.gz
orchestra_test-2016-01-24-05.36.gz
orchestra_test-2016-01-24-09.36.gz
orchestra_test-2016-01-24-13.36.gz
orchestra_test-2016-01-24-17.36.gz
orchestra_test-2016-01-24-21.36.gz
,這是每天都在做單獨迪爾斯
mysql-2015-11-16/
mysql-2015-11-19/
-- || --
mysql-2016-01-18/
mysql-2016-01-19/
mysql-2016-01-20/
mysql-2016-01-21/
mysql-2016-01-22/
mysql-2016-01-23/
mysql-2016-01-24/
...
我在尋找什麼該目錄將只保留最新的日期&時間的文件名,和每一個「重複」類似的文件刪除(他們雜亂的空間),
我希望得到的輸出:
mysql-2015-11-16/
adsoglasi-2016-01-16-21.35.gz
ehoplit-2016-01-16-21.35.gz
posavje-2016-01-16-21.35.gz
export-mysql-baze-2016-01-16-21.35.log
flora-2016-01-16-21.35.gz
karcher-2016-01-16-21.35.gz
knjigarna-2016-01-16-21.35.gz
mysql-2016-01-16-21.35.gz
mysqlshow_grants-2016-01-16-21.36.49.gz
pohistvo-2016-01-16-21.35.gz
akord-2016-01-16-21.36.gz
ekomprof-2016-01-16-21.36.gz
gume-2016-01-16-21.36.gz
orchestra_test-2016-01-16-21.36.gz
-- || --
mysql-2015-11-19/
....filenames with date ...2015-11-19...
-- || --
mysql-2016-01-24/
adsoglasi-2016-01-24-21.35.gz
ehoplit-2016-01-24-21.35.gz
posavje-2016-01-24-21.35.gz
export-mysql-baze-2016-01-24-21.35.log
flora-2016-01-24-21.35.gz
karcher-2016-01-24-21.35.gz
knjigarna-2016-01-24-21.35.gz
mysql-2016-01-24-21.35.gz
mysqlshow_grants-2016-01-24-21.36.49.gz
pohistvo-2016-01-24-21.35.gz
akord-2016-01-24-21.36.gz
ekomprof-2016-01-24-21.36.gz
gume-2016-01-24-21.36.gz
orchestra_test-2016-01-24-21.36.gz
...現在是不是一個更好的名單:-)
但因爲我沒有與一些「工具」像fdupes或任何類似的成功,我要求向專家求助。
TY, 最好的問候。
爲什麼有多個'出口的mysql-baze'?這裏的「只有最新的」規則不適用嗎? –
@Benjamin W.:......應該是,我正在手動編輯(刪除)這些行。列表已更正。 –