作者s8454158 (′‧ω‧‵)
看板Linux
標題[問題] 請問 find 排除某些檔案的方式
時間Fri Jun 30 02:59:11 2017
小弟想要每日刪除在/opt/123/log 內的所有檔案,但是要排除連結指向的檔案...
以下是目錄底下的資料:
/opt/123/log/aaa.ERROR -> ERROR20170622-091436.1204
/opt/123/log/aaa.WARNING -> ERROR20170622-211432.4204
/opt/123/log/aaa.INFO -> INFO20170622-221431.1927
/opt/123/log/bbb.ERROR -> ERROR20170622-091432.1477
/opt/123/log/bbb.WARNING -> ERROR20170622-111432.8437
/opt/123/log/bbb.INFO -> INFO20170622-091438.1277
其餘還有一大堆類似的檔案,上面六個檔案檔名會變動也不能搬移 = =
有方法可以寫 shell script 用 find 排除某些特定檔案一次殺光其他檔案嗎??
感恩~
--
(。 。) (。 。) (。 。) (。 。)
︴︴︴︴ ︴︴︴︴ ︴︴︴︴ ︴︴︴︴
(。 。) (。 。) (。 。) (。 。)
︴︴︴︴ ︴︴︴︴ ︴︴︴︴ ︴︴︴︴
(。 。) (。 。) (。 。) (。 。)
︴︴︴︴ ︴︴︴︴ ︴︴︴︴ ︴︴︴︴
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.34.54.25
※ 文章網址: https://www.ptt.cc/bbs/Linux/M.1498762767.A.2BE.html
→ dododavid006: find /opt/123/log/* -not -type l -delete 06/30 10:41
→ dododavid006: 這樣會排除掉 symbol link 的檔案 06/30 10:42
→ dododavid006: 不過資料夾下如果只有 regular file 要刪的話建議 06/30 10:43
→ dododavid006: find /opt/123/log/* -type f -delete 06/30 10:43
→ s8454158: 謝謝 那symbol link 指向的檔案也要一起排除呢? 06/30 12:25
推 yvb: find /opt/123/log/ -type l | \ 06/30 21:49
→ yvb: (sed 's/^/! -samefile /;s/$/ -a/';echo ' -type f') | \ 06/30 21:49
→ yvb: xargs find -L | xargs rm 06/30 21:49