PTT
Submit
Submit
選擇語言
正體中文
简体中文
PTT
Linux
[問題] 請問 find 排除某些檔案的方式
作者:
s8454158
(′‧ω‧‵)
2017-06-30 02:59:11
小弟想要每日刪除在/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 排除某些特定檔案一次殺光其他檔案嗎??
感恩~
作者:
dododavid006
(朔雪)
2017-06-30 10:41:00
find /opt/123/log/* -not -type l -delete這樣會排除掉 symbol link 的檔案不過資料夾下如果只有 regular file 要刪的話建議find /opt/123/log/* -type f -delete
作者: s8454158 (′‧ω‧‵)
2017-06-30 12:25:00
謝謝 那symbol link 指向的檔案也要一起排除呢?
作者: yvb
2017-06-30 21:49:00
find /opt/123/log/ -type l | \(sed 's/^/! -samefile /;s/$/ -a/';echo ' -type f') | \xargs find -L | xargs rm
繼續閱讀
[問題] mac terminal 2>&1 導向的問題
TJrose
[問題] 使用Gnome-terminal,如何儲存記錄檔?
marx625001
[問題] CentOS(1611)安裝時GPT設定
jog199
[問題] 關於時間設定
shinchun
[問題] 關於MySQL跟mariaDB雙向同步問題
peterh05
[問題] 登入輸入密碼 跳回登入畫面
johnny9667
[問題] SourceExplorer亂跳
blueguan
[問題] snmp在raspbian上安裝遇到的問題
losttype
[問題] Ubuntu系統和軟體更新卡住?
dharma
Re: [問題] Linux desktop的某個評價?
bced
Links
booklink
Contact Us: admin [ a t ] ucptt.com