国产宅男网站在线|亚洲A级性爱免费视频|亚洲中精品级在线|午夜福利AA毛

  • <dd id="gf5jf"><th id="gf5jf"></th></dd>

    <cite id="gf5jf"><label id="gf5jf"></label></cite>
  • <div id="gf5jf"><listing id="gf5jf"></listing></div>
    學(xué)習(xí)啦 > 學(xué)習(xí)電腦 > 操作系統(tǒng) > Linux教程 >

    linux中的find命令有哪些用法參數(shù)設(shè)置是什么

    時(shí)間: 加城1195 分享

      Linux中的find命令主要用于各種查找,很常用,其中包括了很多的參數(shù)選項(xiàng),那么具體參數(shù)有什么呢?怎么用?下面由學(xué)習(xí)啦小編為大家整理了linux中的find命令參數(shù)的相關(guān)知識,希望對大家有幫助!

      linux中的find命令詳解

      一.find命令

      基本格式:find path expression

      1.按照文件名查找

      (1)find / -name httpd.conf  #在根目錄下查找文件httpd.conf,表示在整個(gè)硬盤查找

      (2)find /etc -name httpd.conf  #在/etc目錄下文件httpd.conf

      (3)find /etc -name '*srm*'  #使用通配符*(0或者任意多個(gè))。表示在/etc目錄下查找文件名中含有字符串‘srm’的文件

      (4)find . -name 'srm*'   #表示當(dāng)前目錄下查找文件名開頭是字符串‘srm’的文件

      2.按照文件特征查找

      (1)find / -amin -10   # 查找在系統(tǒng)中最后10分鐘訪問的文件(access time)

      (2)find / -atime -2   # 查找在系統(tǒng)中最后48小時(shí)訪問的文件

      (3)find / -empty   # 查找在系統(tǒng)中為空的文件或者文件夾

      (4)find / -group cat   # 查找在系統(tǒng)中屬于 group為cat的文件

      (5)find / -mmin -5   # 查找在系統(tǒng)中最后5分鐘里修改過的文件(modify time)

      (6)find / -mtime -1   #查找在系統(tǒng)中最后24小時(shí)里修改過的文件

      (7)find / -user fred   #查找在系統(tǒng)中屬于fred這個(gè)用戶的文件

      (8)find / -size +10000c  #查找出大于10000000字節(jié)的文件(c:字節(jié),w:雙字,k:KB,M:MB,G:GB)

      (9)find / -size -1000k   #查找出小于1000KB的文件

      3.使用混合查找方式查找文件

      參數(shù)有: !,-and(-a),-or(-o)。

      (1)find /tmp -size +10000c -and -mtime +2   #在/tmp目錄下查找大于10000字節(jié)并在最后2分鐘內(nèi)修改的文件

      (2)find / -user fred -or -user george   #在/目錄下查找用戶是fred或者george的文件文件

      (3)find /tmp ! -user panda  #在/tmp目錄中查找所有不屬于panda用戶的文件

      find命令參數(shù)1.使用name選項(xiàng)

      文件名選項(xiàng)是find命令最常用的選項(xiàng),要么單獨(dú)使用該選項(xiàng),要么和其他選項(xiàng)一起使用。 可以使用某種文件名模式來匹配文件,記住要用引號將文件名模式引起來。 不管當(dāng)前路徑是什么,如果想要在自己的根目錄$HOME中查找文件名符合*.log的文件,使用~作為 'pathname'參數(shù),波浪號~代表了你的$HOME目錄。

      find ~ -name "*.log" -print

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

      find . -name "*.log" -print

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

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

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

      find /etc -name "host*" -print

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

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

      要想讓系統(tǒng)高負(fù)荷運(yùn)行,就從根目錄開始查找所有的文件。

      find / -name "*" -print

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

      命令:

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

      輸出:

      [root@localhost test]# ll

      總計(jì) 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]#

      find命令參數(shù)2.用perm選項(xiàng)

      按照文件權(quán)限模式用-perm選項(xiàng),按文件權(quán)限模式來查找文件的話。最好使用八進(jìn)制的權(quán)限表示法。

      如在當(dāng)前目錄下查找文件權(quán)限位為755的文件,即文件屬主可以讀、寫、執(zhí)行,其他用戶可以讀、執(zhí)行的文件,可以用:

      [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]#

      還有一種表達(dá)方法:在八進(jìn)制數(shù)字前面要加一個(gè)橫杠-,表示都匹配,如-007就相當(dāng)于777,-005相當(dāng)于555,

      命令:

      find . -perm -005

      輸出:

      [root@localhost test]# ll

      總計(jì) 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]#

      find命令參數(shù)3.忽略某個(gè)目錄

      如果在查找文件時(shí)希望忽略某個(gè)目錄,因?yàn)槟阒滥莻€(gè)目錄中沒有你所要查找的文件,那么可以使用-prune選項(xiàng)來指出需要忽略的目錄。在使用-prune選項(xiàng)時(shí)要當(dāng)心,因?yàn)槿绻阃瑫r(shí)使用了-depth選項(xiàng),那么-prune選項(xiàng)就會(huì)被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命令參數(shù)4.使用find查找文件的時(shí)候怎么避開某個(gè)文件目錄

      實(shí)例1:在test 目錄下查找不在test4子目錄之內(nèi)的所有文件

      命令:

      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]#

    3996221