. 找出 . 底下的 php 檔案

01
02
03
#
#
find . -name "*.php"

 

2. 找出 . 底下非 php 副檔名檔案

01
02
03
#
#
find . -not -name "*.php"

3. 刪除 . 底下 php 檔案,有兩種作法

01
02
03
04
05
06
07
08
09
#
# 系統詢問之後才刪除
# 先把 -exec 後面的東西先清掉, 用 -print 來先確認輸出
# rm 可以多用 -i 的參數來加以確認
find . -name "*.php" -exec rm -i {} \;
#
# 系統直接刪除
find . -delete -name "*.php"
find . -name "*.php" | xargs /bin/rm -rf

4. 如何刪除 7 天前之料呢?

01
02
03
find /path_name -type f -mtime +7 -exec rm '{}' \;
find /path_name -type f -mtime +7  | xargs /bin/rm -rf
find /path_name -delete -type f -mtime +7

5. 找出7天以內修改的資料

01
02
03
#
#
find . -type f -mtime -7 -name "*.php"

6. find 後只顯示目錄名稱不顯示路徑

01
02
03
find . -maxdepth 1 -type d  -exec basename {} \;
find . -maxdepth 1 -type d | awk -F"/" '{print $NF}'
find . -maxdepth 1 -type d | sed 's!.*\/\([^\/]*\).*!\1!g'

7. find 後只顯示目錄名稱不顯示路徑,也不顯示第一個 . 目錄

01
02
03
#
#
find . -maxdepth 1 -mindepth 1 -type d -exec basename {} \;

8. -mmin (minutes) or -mtime (24 hour periods, starting from now) For example:

01
02
03
04
05
06
07
08
09
find . -mtime 0   # find files modified between now and 1 day ago
                  # (i.e., within the past 24 hours)
find . -mtime -1  # find files modified less than 1 day ago
                  # (i.e., within the past 24 hours, as before)
find . -mtime 1   # find files modified between 24 and 48 hours ago
find . -mtime +1  # find files modified more than 48 hours ago
 
find . -mmin +5 -mmin -10 # find files modifed between
                          # 6 and 9 minutes ago

9. find 指定多種檔案類型與相對應的名稱

find . \( \( -type f -a -name "*.htm*" \) -o \
          \( -type d -name "*.js*" \) -o \
          \( -type l -name "*.txt" \) \
       \) -a -print

10. find後,刪除105天前資料,檔案名稱的附檔名為sql

第一種 : find -type f -name '*.sql' -mtime +15 -print0 | xargs -0 rm
第二種 : find -type f -name '*.sql' -mtime +15 -delete

 

 

 

arrow
arrow
    全站熱搜

    忽倫 發表在 痞客邦 留言(0) 人氣()