日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

Linux文件查找命令總結(下篇)

瀏覽:650日期:2023-03-07 14:40:35
目錄
  • 前言
  • find 命令的參數詳解
    • 使用name選項
    • 用perm選項
    • 忽略某個目錄
    • 使用find查找文件的時候怎么避開某個文件目錄
      • 在test 目錄下查找不在test4子目錄之內的所有文件
      • 查找某一確定文件,-name等選項加在-o 之后
    • 使用user和nouser選項
      • 在$HOME目錄中查找文件屬主為peida的文件
      • 在/etc目錄下查找文件屬主為peida的文件
      • 為了查找屬主帳戶已經被刪除的文件,可以使用-nouser選項。在/home目錄下查找所有的這類文件
    • 使用group和nogroup選項
      • 按照更改時間或訪問時間等查找文件
        • 查找比某個文件新或舊的文件
          • 查找更改時間比文件log2012.log新但比文件log2017.log舊的文件
          • 查找更改時間在比log2012.log文件新的文件
        • 使用type選項
          • 在/etc目錄下查找所有的目錄
          • 在當前目錄下查找除目錄以外的所有類型的文件
          • 在/etc目錄下查找所有的符號鏈接文件
        • 使用size選項
          • 在當前目錄下查找文件長度大于1 M字節的文件
          • 在/home/apache目錄下查找文件長度恰好為100字節的文件
          • 在當前目錄下查找長度超過10塊的文件(一塊等于512字節)
        • 使用depth選項
          • find命令從文件系統的根目錄開始,查找一個名為CON.FILE的文件
        • 使用mount選項
          • 從當前目錄開始查找位于本文件系統中文件名以XC結尾的文件

      前言

      關于Linux文件查找命令總結我們分別介紹了which命令、whereis命令、locate命令、find命令這四個命令,本篇向大家介紹的是find命令。

      find 命令的參數詳解

      find一些常用參數的一些常用實例和一些具體用法和注意事項。

      使用name選項

      文件名選項是find命令最常用的選項,要么單獨使用該選項,要么和其他選項一起使用。

      可以使用某種文件名模式來匹配文件,記住要用引號將文件名模式引起來。

      不管當前路徑是什么,如果想要在自己的根目錄 H O M E 中 查 找 文 件 名 符 合 ∗ . l o g 的 文 件 , 使 用   作 為 ′ p a t h n a m e ′ 參 數 , 波 浪 號   代 表 了 你 的 HOME中查找文件名符合*.log的文件,使用~作為 'pathname'參數,波浪號~代表了你的 HOME中查找文件名符合∗.log的文件,使用 作為′pathname′參數,波浪號 代表了你的HOME目錄。

      find ~ -name "*.log" -print 

      想要在當前目錄及子目錄中查找所有的‘ *.log‘文件,可以用:

      find . -name "*.log" -print 

      想要的當前目錄及子目錄中查找文件名以一個大寫字母開頭的文件,可以用:

      find . -name "[A-Z]*" -print 

      想要在/etc目錄中查找文件名以host開頭的文件,可以用:

      find /etc -name "host*" -print 

      想要查找$HOME目錄中的文件,可以用:

      find ~ -name "*" -print 或find . -print 

      要想讓系統高負荷運行,就從根目錄開始查找所有的文件。

      find / -name "*" -print 

      如果想在當前目錄查找文件名以一個個小寫字母開頭,最后是4到9加上.log結束的文件:

      命令:

      find . -name "[a-z]*[4-9].log" -print

      輸出:

      [root@localhost test]# ll
      
      總計 316
      
      -rw-r--r-- 1 root root 302108 11-13 06:03 log2012.log
      
      -rw-r--r-- 1 root root   61 11-13 06:03 log2013.log
      
      -rw-r--r-- 1 root root   0 11-13 06:03 log2014.log
      
      -rw-r--r-- 1 root root   0 11-13 06:06 log2015.log
      
      drwxr-xr-x 6 root root  4096 10-27 01:58 scf
      
      drwxrwxr-x 2 root root  4096 11-13 06:08 test3
      
      drwxrwxr-x 2 root root  4096 11-13 05:50 test4
      
      [root@localhost test]# find . -name "[a-z]*[4-9].log" -print
      
      ./log2014.log
      
      ./log2015.log
      
      ./test4/log2014.log
      
      [root@localhost test]#

      用perm選項

      按照文件權限模式用-perm選項,按文件權限模式來查找文件的話。

      最好使用八進制的權限表示法。

      如在當前目錄下查找文件權限位為755的文件,即文件屬主可以讀、寫、執行,其他用戶可以讀、執行的文件,可以用:

      [root@localhost test]# find . -perm 755 -print
      
      .
      
      ./scf
      
      ./scf/lib
      
      ./scf/service
      
      ./scf/service/deploy
      
      ./scf/service/deploy/product
      
      ./scf/service/deploy/info
      
      ./scf/doc
      
      ./scf/bin
      
      [root@localhost test]#

      還有一種表達方法:在八進制數字前面要加一個橫杠-,表示都匹配,如-007就相當于777,-005相當于555,

      命令:

      find . -perm -005

      輸出:

      [root@localhost test]# ll
      
      總計 316
      
      -rw-r--r-- 1 root root 302108 11-13 06:03 log2012.log
      
      -rw-r--r-- 1 root root   61 11-13 06:03 log2013.log
      
      -rw-r--r-- 1 root root   0 11-13 06:03 log2014.log
      
      -rw-r--r-- 1 root root   0 11-13 06:06 log2015.log
      
      drwxr-xr-x 6 root root  4096 10-27 01:58 scf
      
      drwxrwxr-x 2 root root  4096 11-13 06:08 test3
      
      drwxrwxr-x 2 root root  4096 11-13 05:50 test4
      
      [root@localhost test]# find . -perm -005
      
      .
      
      ./test4
      
      ./scf
      
      ./scf/lib
      
      ./scf/service
      
      ./scf/service/deploy
      
      ./scf/service/deploy/product
      
      ./scf/service/deploy/info
      
      ./scf/doc
      
      ./scf/bin
      
      ./test3
      
      [root@localhost test]#

      忽略某個目錄

      如果在查找文件時希望忽略某個目錄,因為你知道那個目錄中沒有你所要查找的文件,那么可以使用-prune選項來指出需要忽略的目錄。

      在使用-prune選項時要當心,因為如果你同時使用了-depth選項,那么-prune選項就會被find命令忽略。

      如果希望在test目錄下查找文件,但不希望在test/test3目錄下查找,可以用:

      命令:

      find test -path "test/test3" -prune -o -print

      輸出:

      [root@localhost soft]# find test -path "test/test3" -prune -o -print
      
      test
      
      test/log2014.log
      
      test/log2015.log
      
      test/test4
      
      test/test4/log2014.log
      
      test/test4/log2013.log
      
      test/test4/log2012.log
      
      test/scf
      
      test/scf/lib
      
      test/scf/service
      
      test/scf/service/deploy
      
      test/scf/service/deploy/product
      
      test/scf/service/deploy/info
      
      test/scf/doc
      
      test/scf/bin
      
      test/log2013.log
      
      test/log2012.log
      
      [root@localhost soft]#

      使用find查找文件的時候怎么避開某個文件目錄

      在test 目錄下查找不在test4子目錄之內的所有文件

      命令:

      find test -path "test/test4" -prune -o -print

      輸出:

      [root@localhost soft]# find test
      
      test
      
      test/log2014.log
      
      test/log2015.log
      
      test/test4
      
      test/test4/log2014.log
      
      test/test4/log2013.log
      
      test/test4/log2012.log
      
      test/scf
      
      test/scf/lib
      
      test/scf/service
      
      test/scf/service/deploy
      
      test/scf/service/deploy/product
      
      test/scf/service/deploy/info
      
      test/scf/doc
      
      test/scf/bin
      
      test/log2013.log
      
      test/log2012.log
      
      test/test3
      
      [root@localhost soft]# find test -path "test/test4" -prune -o -print
      
      test
      
      test/log2014.log
      
      test/log2015.log
      
      test/scf
      
      test/scf/lib
      
      test/scf/service
      
      test/scf/service/deploy
      
      test/scf/service/deploy/product
      
      test/scf/service/deploy/info
      
      test/scf/doc
      
      test/scf/bin
      
      test/log2013.log
      
      test/log2012.log
      
      test/test3
      
      [root@localhost soft]#

      說明:

      find [-path …] [expression]

      在路徑列表的后面的是表達式

      -path “test” -prune -o -print 是 -path “test” -a -prune -o -print 的簡寫表達式按順序求值, -a 和 -o 都是短路求值,與 shell 的 && 和 || 類似如果

      -path “test” 為真,則求值 -prune , -prune 返回真,與邏輯表達式為真;

      否則不求值 -prune,與邏輯表達式為假。如果 -path “test” -a -prune 為假,則求值 -print ,-print返回真,或邏輯表達式為真;

      否則不求值 -print,或邏輯表達式為真。

      這個表達式組合特例可以用偽碼寫為:

      if -path “test” then

      -prune

      else

      -print

      避開多個文件夾:

      命令:

      find test \( -path test/test4 -o -path test/test3 \) -prune -o -print 

      輸出:

      [root@localhost soft]# find test \( -path test/test4 -o -path test/test3 \) -prune -o -print
      
      test
      
      test/log2014.log
      
      test/log2015.log
      
      test/scf
      
      test/scf/lib
      
      test/scf/service
      
      test/scf/service/deploy
      
      test/scf/service/deploy/product
      
      test/scf/service/deploy/info
      
      test/scf/doc
      
      test/scf/bin
      
      test/log2013.log
      
      test/log2012.log
      
      [root@localhost soft]#

      說明:

      圓括號表示表達式的結合。 \ 表示引用,即指示 shell 不對后面的字符作特殊解釋,而留給 find 命令去解釋其意義。

      查找某一確定文件,-name等選項加在-o 之后

      命令:

      find test \(-path test/test4 -o -path test/test3 \) -prune -o -name "*.log" -print

      輸出:

      [root@localhost soft]# find test \( -path test/test4 -o -path test/test3 \) -prune -o -name "*.log" -print
      
      test/log2014.log
      
      test/log2015.log
      
      test/log2013.log
      
      test/log2012.log
      
      [root@localhost soft]#

      使用user和nouser選項

      按文件屬主查找文件:

      在$HOME目錄中查找文件屬主為peida的文件

      命令:

      find ~ -user peida -print 

      在/etc目錄下查找文件屬主為peida的文件

      命令:

      find /etc -user peida -print 

      說明:

      為了查找屬主帳戶已經被刪除的文件,可以使用-nouser選項。在/home目錄下查找所有的這類文件

      命令:

      find /home -nouser -print

      說明:

      這樣就能夠找到那些屬主在/etc/passwd文件中沒有有效帳戶的文件。

      在使用-nouser選項時,不必給出用戶名; find命令能夠為你完成相應的工作。

      使用group和nogroup選項

      就像user和nouser選項一樣,針對文件所屬于的用戶組, find命令也具有同樣的選項,為了在/apps目錄下查找屬于gem用戶組的文件,可以用:

      find /apps -group gem -print 

      要查找沒有有效所屬用戶組的所有文件,可以使用nogroup選項。

      下面的find命令從文件系統的根目錄處查找這樣的文件:

      find / -nogroup-print

      按照更改時間或訪問時間等查找文件

      如果希望按照更改時間來查找文件,可以使用mtime,atime或ctime選項。

      如果系統突然沒有可用空間了,很有可能某一個文件的長度在此期間增長迅速,這時就可以用mtime選項來查找這樣的文件。

      用減號-來限定更改時間在距今n日以內的文件,而用加號+來限定更改時間在距今n日以前的文件。

      希望在系統根目錄下查找更改時間在5日以內的文件,可以用:

      find / -mtime -5 -print

      為了在/var/adm目錄下查找更改時間在3日以前的文件,可以用:

      find /var/adm -mtime +3 -print

      查找比某個文件新或舊的文件

      如果希望查找更改時間比某個文件新但比另一個文件舊的所有文件,可以使用-newer選項。

      它的一般形式為:

      newest_file_name ! oldest_file_name 

      其中,!是邏輯非符號。

      查找更改時間比文件log2012.log新但比文件log2017.log舊的文件

      命令:

      find -newer log2012.log ! -newer log2017.log

      輸出:

      [root@localhost test]# ll
      
      總計 316
      
      -rw-r--r-- 1 root root 302108 11-13 06:03 log2012.log
      
      -rw-r--r-- 1 root root   61 11-13 06:03 log2013.log
      
      -rw-r--r-- 1 root root   0 11-13 06:03 log2014.log
      
      -rw-r--r-- 1 root root   0 11-13 06:06 log2015.log
      
      -rw-r--r-- 1 root root   0 11-16 14:41 log2016.log
      
      -rw-r--r-- 1 root root   0 11-16 14:43 log2017.log
      
      drwxr-xr-x 6 root root  4096 10-27 01:58 scf
      
      drwxrwxr-x 2 root root  4096 11-13 06:08 test3
      
      drwxrwxr-x 2 root root  4096 11-13 05:50 test4
      
      [root@localhost test]# find -newer log2012.log ! -newer log2017.log
      
      .
      
      ./log2015.log
      
      ./log2017.log
      
      ./log2016.log
      
      ./test3
      
      [root@localhost test]#

      查找更改時間在比log2012.log文件新的文件

      命令:

      find . -newer log2012.log -print

      輸出:

      [root@localhost test]# find -newer log2012.log
      
      .
      
      ./log2015.log
      
      ./log2017.log
      
      ./log2016.log
      
      ./test3
      
      [root@localhost test]#

      使用type選項

      在/etc目錄下查找所有的目錄

      命令:

      find /etc -type d -print 

      在當前目錄下查找除目錄以外的所有類型的文件

      命令:

      find . ! -type d -print 

      在/etc目錄下查找所有的符號鏈接文件

      命令:

      find /etc -type l -print

      使用size選項

      可以按照文件長度來查找文件,這里所指的文件長度既可以用塊(block)來計量,也可以用字節來計量。

      以字節計量文件長度的表達形式為N c;以塊計量文件長度只用數字表示即可。

      在按照文件長度查找文件時,一般使用這種以字節表示的文件長度,在查看文件系統的大小,因為這時使用塊來計量更容易轉換。

      在當前目錄下查找文件長度大于1 M字節的文件

      命令:

      find . -size +1000000c -print

      在/home/apache目錄下查找文件長度恰好為100字節的文件

      命令:

      find /home/apache -size 100c -print 

      在當前目錄下查找長度超過10塊的文件(一塊等于512字節)

      命令:

      find . -size +10 -print

      使用depth選項

      在使用find命令時,可能希望先匹配所有的文件,再在子目錄中查找。

      使用depth選項就可以使find命令這樣做。這樣做的一個原因就是,當在使用find命令向磁帶上備份文件系統時,希望首先備份所有的文件,其次再備份子目錄中的文件。

      find命令從文件系統的根目錄開始,查找一個名為CON.FILE的文件

      命令:

      find / -name "CON.FILE" -depth -print

      說明:

      它將首先匹配所有的文件然后再進入子目錄中查找

      使用mount選項

      在當前的文件系統中查找文件(不進入其他文件系統),可以使用find命令的mount選項。

      從當前目錄開始查找位于本文件系統中文件名以XC結尾的文件

      命令:

      find . -name "*.XC" -mount -print 

      到此這篇關于Linux文件查找命令總結(下篇)的文章就介紹到這了,相關內容請搜索以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持!

      標簽: Linux Apache
      相關文章:
      日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
      香蕉久久99| 91精品二区| 欧美精品影院| 综合激情视频| 久久国产精品免费精品3p| 欧美在线看片| 丰满少妇一区| 久久精品国产www456c0m| 欧美日韩国产亚洲一区| 国产精品宾馆| 精品久久久中文字幕| 日韩在线综合| 99综合视频| 日本va欧美va瓶| 国产成人精品亚洲线观看| 四虎国产精品免费观看| 亚洲一级网站| 欧美偷窥清纯综合图区| 中文字幕人成乱码在线观看| 午夜日本精品| 久久精品99国产精品| 高清精品久久| 免费人成精品欧美精品| 久久中文精品| 亚洲精品1区2区| 亚洲午夜免费| a天堂资源在线| 六月丁香综合| 91日韩在线| 综合视频一区| 国产一区二区精品久| 香蕉久久夜色精品国产| 国产精品主播在线观看| 99久久视频| 国产亚洲精品美女久久 | 伊人国产精品| 奇米亚洲欧美| 亚洲午夜黄色| 麻豆国产91在线播放| 国产婷婷精品| 黄色在线网站噜噜噜| 亚洲精品系列| 国产99精品| 麻豆精品久久久| 日韩精品一级中文字幕精品视频免费观看 | 国产精品久久久久av蜜臀| 99久久夜色精品国产亚洲狼| 日韩av电影一区| 亚洲手机在线| 国产乱码精品一区二区三区四区 | 天堂av在线| 国产亚洲一区| 日韩午夜一区| 日本欧美不卡| 久久99高清| 日韩av一区二区三区四区| 蜜桃国内精品久久久久软件9| 久久久91麻豆精品国产一区| 91亚洲无吗| 免费观看在线综合| 亚洲一级黄色| 亚洲最新无码中文字幕久久| 国产精品日本一区二区三区在线 | 亚洲精品2区| 国产v日韩v欧美v| 国产精品一卡| 日韩福利视频一区| 欧美专区在线| 狠狠久久婷婷| 久久精品播放| 亚洲一区资源| 国产一区二区三区四区五区 | 午夜av一区| 免费在线亚洲| 综合一区二区三区| 久久国产成人午夜av影院宅| 精品视频在线观看网站| 91午夜精品| 99久久精品网| 香蕉成人av| 日韩免费小视频| 久久国产电影| 色综合www| 国产成人免费视频网站视频社区| 日韩欧美在线精品| 在线国产精品一区| 亚洲精品麻豆| 亚洲久久一区| 夜夜嗨一区二区三区| 欧美日韩一二| 欧美一区二区三区激情视频| 激情欧美亚洲| 欧美精品一二| 国产日韩专区| 视频一区二区三区在线| 视频一区二区三区入口| 鲁大师影院一区二区三区| 影音先锋国产精品| 五月天久久网站| 久久精品国产亚洲夜色av网站| 在线一区视频观看| 久久青草久久| 欧美 日韩 国产一区二区在线视频 | 水蜜桃精品av一区二区| 久久亚洲资源中文字| 久久精品二区亚洲w码| 精品一级视频| 9999国产精品| 日本精品不卡| 亚洲一区二区免费看| 亚洲视频国产精品| 午夜精品福利影院| 亚洲精一区二区三区| 欧美在线观看天堂一区二区三区| 亚洲精品少妇| 亚洲精品免费观看| 男女精品网站| 91大神在线观看线路一区| 亚洲97av| 国产极品模特精品一二| 欧美激情在线精品一区二区三区| av在线资源| 日韩在线视频精品| 蜜桃视频欧美| 色8久久久久| 国产999精品在线观看| 亚洲v在线看| 日韩精品免费视频人成 | 青草久久视频| 国产精品久久久久久久久久白浆| 日本午夜大片a在线观看| 日韩精品一卡二卡三卡四卡无卡| 国产精品传媒麻豆hd| 五月天激情综合网| 国产精品最新自拍| 欧美日韩黑人| 国产精品白浆| 午夜久久一区| 欧美黑人做爰爽爽爽| 99国产精品99久久久久久粉嫩| 国产精品三p一区二区| 久久精品高清| 国产剧情在线观看一区| 欧美高清一区| 91精品啪在线观看国产爱臀| 成人羞羞视频在线看网址| 欧美午夜网站| 欧美另类专区| 久久香蕉网站| 在线精品视频一区| 日韩欧美一区二区三区在线视频| 亚洲麻豆一区| 久久美女精品| 久久中文精品| 视频一区免费在线观看| 91视频久久| 欧美在线黄色| 国产农村妇女精品一二区| 久久91视频| 一本综合精品| 亚洲高清久久| 高清在线一区| 国产精品视频首页| 亚洲欧美日韩国产综合精品二区| 麻豆国产91在线播放| 亚洲欧美久久精品| 香蕉久久精品| 最近高清中文在线字幕在线观看1| 日韩av中文字幕一区| 欧美精品自拍| 色一区二区三区| 国产精品国码视频| 亚洲免费专区| 欧美综合国产| 99国产精品免费视频观看| 欧美交a欧美精品喷水| 婷婷久久免费视频| 热久久久久久久| 亚洲欧洲日本mm| 国产99亚洲| 都市激情国产精品| 美女av一区| 国产精品成人国产| 欧美亚洲一区二区三区| 日韩精品一区二区三区av| 快she精品国产999| 香蕉久久夜色精品国产| 亚州av乱码久久精品蜜桃| 久久国产欧美| 国产免费久久| 日本欧美韩国一区三区| 亚洲精品一区二区在线播放∴| 欧美网站在线| 婷婷综合激情| 五月天综合网站| 午夜精品影院| 夜夜嗨av一区二区三区网站四季av| 欧美日韩在线二区| 亚洲第一区色| 亚洲女同一区|