2014-03-03 38 views
1

我在文件夾中有幾個* .txt文件。我想算,並添加到deleted_files_count.log文件之前,使用此命令刪除文件:如何計算並添加到文件之前刪除* .txt文件在Linux中?

find ./*.txt -type f -mmin +10 -exec rm {} \; 

例如文件夾中有3個* .txt文件和deleted_files_count.log文件的內容是5,deleted_files_count.log的內容刪除後應該是8。有誰能夠幫助我? 謝謝。

回答

0

你可以試試這個:

cnt=`cat deleted_files_count.log` ; for i in `find ./*.txt -type f -mmin +10` ; do rm "$i" ; cnt=$(($cnt+1)) ; done ; echo $cnt > deleted_files_count.log 

這並不檢查日誌文件的內容,也不如它在所有存在。如果你想妥善處理可能出現的錯誤,你必須稍微改進一下,但只要你知道deleted_files_count.log存在幷包含一個數字,它就可以實現。

相關問題