iT邦幫忙

0

[Linux shell] 自動刪除幾天前的檔案是要用-mtime 還是-ctime

Hi 大家好

想請教一個自動刪檔案的腳本問題
我有兩個shell
shell a: 每天dump db data output成csv
shell b: 每天去跑刪除3天前shell a 產生的檔案
有參考http://n.sfs.tw/content/index/10905
裏頭有寫到:
-ctime 檔案的狀態資訊最後修改的時間到find 的執行時間差
-mtime 檔案的最後修改時間到find 的執行時間差

我依照定義寫:
find ./ -mtime +3d -exec rm {} ;

但是檔案一直都沒被刪除,請問該如何修改?
謝謝

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

3
Ray
iT邦大神 1 級 ‧ 2021-09-02 15:08:09

你最後面少了反斜線, 導致指令無法解析:

find ./ -mtime +3d -exec rm {} \;

如果不喜歡那個 \ 號的話, 其實可以讓 find 自己刪就好:

find ./ -mtime +3d -delete
熊大叔 iT邦新手 2 級 ‧ 2021-09-02 15:40:31 檢舉

/images/emoticon/emoticon41.gif筆記

Kert iT邦研究生 5 級 ‧ 2021-09-03 15:25:04 檢舉

我習慣用第一種 原來還有第二種 學習了

我要發表回答

立即登入回答