請問 find 排除某些檔案的方式 - Linux

Donna avatar
By Donna
at 2017-06-30T02:59

Table of Contents


小弟想要每日刪除在/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 排除某些特定檔案一次殺光其他檔案嗎??

感恩~

--
(。 。) (。 。) (。 。) (。 。)
︴︴︴︴ ︴︴︴︴ ︴︴︴︴ ︴︴︴︴
(。 。) (。 。) (。 。) (。 。)
︴︴︴︴ ︴︴︴︴ ︴︴︴︴ ︴︴︴︴
(。 。) (。 。) (。 。) (。 。)
︴︴︴︴ ︴︴︴︴ ︴︴︴︴ ︴︴︴︴

--
Tags: Linux

All Comments

Hazel avatar
By Hazel
at 2017-07-01T23:24
find /opt/123/log/* -not -type l -delete
Ophelia avatar
By Ophelia
at 2017-07-03T06:54
這樣會排除掉 symbol link 的檔案
Olive avatar
By Olive
at 2017-07-04T21:51
不過資料夾下如果只有 regular file 要刪的話建議
find /opt/123/log/* -type f -delete
Andy avatar
By Andy
at 2017-07-08T09:20
謝謝 那symbol link 指向的檔案也要一起排除呢?
Kumar avatar
By Kumar
at 2017-07-11T17:49
find /opt/123/log/ -type l | \
(sed 's/^/! -samefile /;s/$/ -a/';echo ' -type f') | \
xargs find -L | xargs rm

使用Gnome-terminal,如何儲存記錄檔?

Catherine avatar
By Catherine
at 2017-06-28T14:51
Hi 各位Linux高手 小弟最近在使用linux上,遇到的一個困難, 就是我在使用iperf的程式時, 我透過gnome-terminal的方式, 開新視窗跑資料,但是資料一直在流, 想要把流過的資料都儲存下來, 我應該用什麼方法儲存這些資料? 我下的command如下 rootat~: gnome-ter ...

CentOS(1611)安裝時GPT設定

Christine avatar
By Christine
at 2017-06-28T10:20
請問版上大大, 我想要拿4TB x 2做 CentOS(1611)系統碟, 但發現安裝介面無法辨識到4TB硬碟。 爬文之後得知需要在安裝頁面輸入Tab, 並加入強制使用 GPT 分割表的安裝參數如下: vmlinuz initrd=initrd.img inst.stage2=hd:LABEL=Ce ...

hwclock設定時間

Kama avatar
By Kama
at 2017-06-28T09:01
如果CMOS Battery沒有電的話 預設時間會是19xx年 如果進去Linux透過NTP或是hwclock設定時間 譬如說設定2017 會發現系統時間是對的 但是bios時間卻變成1917 做幾次測試發現linux還真的只會sync 2017年中的17回hardware clock (RTC) 前面的2 ...

關於MySQL跟mariaDB雙向同步問題

Liam avatar
By Liam
at 2017-06-28T08:50
因為一直搜尋不到相關資訊,想麻煩各位先進 Mysql可以跟maria雙向同步嗎? 也就是雙master. a_WEB連結寫入MySQL b_WEB連結寫入mariaDB(galera cluster) 想讓MySQL與mariaDB被寫入的資料可以即時同步互抄寫MySQLandlt;--andgt;mari ...

登入輸入密碼 跳回登入畫面

Donna avatar
By Donna
at 2017-06-27T04:45
https://youtu.be/Smc_QtbCMUs 再登入畫面輸入密碼就一直跳會登入畫面 有試過重新安裝顯卡驅動 有試過進入文字模式 可以登入 很正常 有試過訪客模式,可以正常圖形登入 有試過update upgrade 都更新完成 但還是這樣 顯卡是gt650m Ubuntu 16.04 ...