• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 298  文章 - 377  trackbacks - 0
            <2016年6月>
            2930311234
            567891011
            12131415161718
            19202122232425
            262728293012
            3456789

            常用鏈接

            留言簿(34)

            隨筆分類(lèi)

            隨筆檔案

            文章檔案

            相冊(cè)

            收藏夾

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            ·find   path   -option   [   -print ]   [ -exec   -ok   command ]   {} \;

            find命令的參數(shù);

            pathname: find命令所查找的目錄路徑。例如用.來(lái)表示當(dāng)前目錄,用/來(lái)表示系統(tǒng)根目錄。
            -print: find命令將匹配的文件輸出到標(biāo)準(zhǔn)輸出。
            -exec: find命令對(duì)匹配的文件執(zhí)行該參數(shù)所給出的shell命令。相應(yīng)命令的形式為'command' { } \;,注意{ }和\;之間的空格。
            -ok: 和-exec的作用相同,只不過(guò)以一種更為安全的模式來(lái)執(zhí)行該參數(shù)所給出的shell命令,在執(zhí)行每一個(gè)命令之前,都會(huì)給出提示,讓用戶(hù)來(lái)確定是否執(zhí)行。

            #-print 將查找到的文件輸出到標(biāo)準(zhǔn)輸出
            #-exec   command   {} \;      —–將查到的文件執(zhí)行command操作,{} 和 \;之間有空格
            #-ok 和-exec相同,只不過(guò)在操作前要詢(xún)用戶(hù)
            例:find . -name .svn | xargs rm -rf

            ====================================================

            -name   filename             #查找名為filename的文件
            -perm                        #按執(zhí)行權(quán)限來(lái)查找
            -user    username             #按文件屬主來(lái)查找
            -group groupname            #按組來(lái)查找
            -mtime   -n +n                #按文件更改時(shí)間來(lái)查找文件,-n指n天以?xún)?nèi),+n指n天以前
            -atime    -n +n               #按文件訪(fǎng)問(wèn)時(shí)間來(lái)查GIN: 0px">

            -ctime    -n +n              #按文件創(chuàng)建時(shí)間來(lái)查找文件,-n指n天以?xún)?nèi),+n指n天以前

            -nogroup                     #查無(wú)有效屬組的文件,即文件的屬組在/etc/groups中不存在
            -nouser                     #查無(wú)有效屬主的文件,即文件的屬主在/etc/passwd中不存
            -newer   f1 !f2              找文件,-n指n天以?xún)?nèi),+n指n天以前 
            -ctime    -n +n               #按文件創(chuàng)建時(shí)間來(lái)查找文件,-n指n天以?xún)?nèi),+n指n天以前 
            -nogroup                     #查無(wú)有效屬組的文件,即文件的屬組在/etc/groups中不存在
            -nouser                      #查無(wú)有效屬主的文件,即文件的屬主在/etc/passwd中不存
            -newer   f1 !f2               #查更改時(shí)間比f(wàn)1新但比f(wàn)2舊的文件
            -type    b/d/c/p/l/f         #查是塊設(shè)備、目錄、字符設(shè)備、管道、符號(hào)鏈接、普通文件
            -size      n[c]               #查長(zhǎng)度為n塊[或n字節(jié)]的文件
            -depth                       #使查找在進(jìn)入子目錄前先行查找完本目錄
            -fstype                     #查更改時(shí)間比f(wàn)1新但比f(wàn)2舊的文件
            -type    b/d/c/p/l/f         #查是塊設(shè)備、目錄、字符設(shè)備、管道、符號(hào)鏈接、普通文件
            -size      n[c]               #查長(zhǎng)度為n塊[或n字節(jié)]的文件
            -depth                       #使查找在進(jìn)入子目錄前先行查找完本目錄
            -fstype                      #查位于某一類(lèi)型文件系統(tǒng)中的文件,這些文件系統(tǒng)類(lèi)型通常可 在/etc/fstab中找到
            -mount                       #查文件時(shí)不跨越文件系統(tǒng)mount點(diǎn)
            -follow                      #如果遇到符號(hào)鏈接文件,就跟蹤鏈接所指的文件
            -cpio                %;      #查位于某一類(lèi)型文件系統(tǒng)中的文件,這些文件系統(tǒng)類(lèi)型通常可 在/etc/fstab中找到
            -mount                       #查文件時(shí)不跨越文件系統(tǒng)mount點(diǎn)
            -follow                      #如果遇到符號(hào)鏈接文件,就跟蹤鏈接所指的文件
            -cpio                        #對(duì)匹配的文件使用cpio命令,將他們備份到磁帶設(shè)備中
            -prune                       #忽略某個(gè)目錄

            =====================================================
            $find   ~   -name   "*.txt"   -print    #在$HOME中查.txt文件并顯示
            $find   .    -name   "*.txt"   -print
            $find   .    -name   "[A-Z]*"   -print   #查以大寫(xiě)字母開(kāi)頭的文件
            $find   /etc   -name   "host*"   -print #查以host開(kāi)頭的文件
            $find   .   -name   "[a-z][a-z][0–9][0–9].txt"    -print   #查以?xún)蓚€(gè)小寫(xiě)字母和兩個(gè)數(shù)字開(kāi)頭的txt文件
            $find .   -perm   755   -print
            $find   .   -perm -007   -exec ls -l {} \;   #查所有用戶(hù)都可讀寫(xiě)執(zhí)行的文件同-perm 777
            $find   . -type d   -print
            $find   .   !   -type   d   -print 
            $find   .   -type l   -print

            $find   .   -size   +1000000c   -print        #查長(zhǎng)度大于1Mb的文件
            $find   .   -size   100c         -print       # 查長(zhǎng)度為100c的文件
            $find   .   -size   +10   -print              #查長(zhǎng)度超過(guò)期作廢10塊的文件(1塊=512字節(jié))

            $cd /
            $find   etc   home   apps    -depth   -print   | cpio   -ivcdC65536   -o   /dev/rmt0
            $find   /etc -name "passwd*"   -exec grep   "cnscn"   {}   \;   #看是否存在cnscn用戶(hù)
            $find . -name "yao*"   | xargs file
            $find   . -name "yao*"   |   xargs   echo    "" > /tmp/core.log
            $find   . -name "yao*"   | xargs   chmod   o-w

            ======================================================

            find   -name april*                     在當(dāng)前目錄下查找以april開(kāi)始的文件
            find   -name   april*   fprint file        在當(dāng)前目錄下查找以april開(kāi)始的文件,并把結(jié)果輸出到file中
            find   -name ap* -o -name may*   查找以ap或may開(kāi)頭的文件
            find   /mnt   -name tom.txt   -ftype vfat   在/mnt下查找名稱(chēng)為tom.txt且文件系統(tǒng)類(lèi)型vfat的文件
            find   /mnt   -name t.txt ! -ftype vfat   在/mnt下查找名稱(chēng)為tom.txt且文件系統(tǒng)類(lèi)型不為vfat的文件
            find   /tmp   -name wa* -type l            在/tmp下查找名為wa開(kāi)頭且類(lèi)型為符號(hào)鏈接的文件
            find   /home   -mtime   -2                 在/home下查最近兩天內(nèi)改動(dòng)過(guò)的文件
            find /home    -atime -1                  查1天之內(nèi)被存取過(guò)的文件
            find /home -mmin    +60                  在/home下查60分鐘前改動(dòng)過(guò)的文件
            find /home   -amin   +30                  查最近30分鐘前被存取過(guò)的文件
            find /home   -newer   tmp.txt             在/home下查更新時(shí)間比tmp.txt近的文件或目錄
            find /home   -anewer   tmp.txt            在/home下查存取時(shí)間比tmp.txt近的文件或目錄
            find   /home   -used   -2                  列出文件或目錄被改動(dòng)過(guò)之后,在2日內(nèi)被存取過(guò)的文件或目錄
            find   /home   -user cnscn                列出/home目錄內(nèi)屬于用戶(hù)cnscn的文件或目錄
            find   /home   -uid   +501                  列出/home目錄內(nèi)用戶(hù)的識(shí)別碼大于501的文件或目錄
            find   /home   -group   cnscn              列出/home內(nèi)組為cnscn的文件或目錄
            find   /home   -gid 501                   列出/home內(nèi)組id為501的文件或目錄
            find   /home   -nouser                    列出/home內(nèi)不屬于本地用戶(hù)的文件或目錄
            find   /home   -nogroup                   列出/home內(nèi)不屬于本地組的文件或目錄
            find   /home    -name tmp.txt    -maxdepth   4   列出/home內(nèi)的tmp.txt 查時(shí)深度最多為3層
            find   /home   -name tmp.txt   -mindepth   3   從第2層開(kāi)始查
            find   /home   -empty                     查找大小為0的文件或空目錄
            find   /home   -size   +512k                查大于512k的文件
            find   /home   -size   -512k               查小于512k的文件
            find   /home   -links   +2                查硬連接數(shù)大于2的文件或目錄
            find   /home   -perm   0700                查權(quán)限為700的文件或目錄
            find   /tmp   -name tmp.txt   -exec cat {} \;
            find   /tmp   -name   tmp.txt   -ok   rm {} \;

            find    /   -amin    -10     # 查找在系統(tǒng)中最后10分鐘訪(fǎng)問(wèn)的文件
            find    /   -atime   -2        # 查找在系統(tǒng)中最后48小時(shí)訪(fǎng)問(wèn)的文件
            find    /   -empty             # 查找在系統(tǒng)中為空的文件或者文件夾
            find    /   -group   cat        # 查找在系統(tǒng)中屬于 groupcat的文件
            find    /   -mmin   -5         # 查找在系統(tǒng)中最后5分鐘里修改過(guò)的文件
            find    /   -mtime   -1       #查找在系統(tǒng)中最后24小時(shí)里修改過(guò)的文件
            find    /   -nouser           #查找在系統(tǒng)中屬于作廢用戶(hù)的文件
            find    /   -user    fred     #查找在系統(tǒng)中屬于FRED這個(gè)用戶(hù)的文件

            查當(dāng)前目錄下的所有普通文件
            # find . -type f -exec ls -l {} \; 
            -rw-r–r–    1 root      root         34928 2003-02-25   ./conf/httpd.conf 
            -rw-r–r–    1 root      root         12959 2003-02-25   ./conf/magic 
            -rw-r–r–    1 root      root          180 2003-02-25   ./conf.d/README 
            查當(dāng)前目錄下的所有普通文件,并在- e x e c選項(xiàng)中使用ls -l命令將它們列出

            =================================================
            在/ l o g s目錄中查找更改時(shí)間在5日以前的文件并刪除它們:
            $ find logs -type f -mtime +5 -exec   -ok   rm {} \;

            =================================================
            查詢(xún)當(dāng)天修改過(guò)的文件
            [root@book class]# find   ./   -mtime   -1   -type f   -exec   ls -l   {} \;

            =================================================
            查詢(xún)文件并詢(xún)問(wèn)是否要顯示
            [root@book class]# find   ./   -mtime   -1   -type f   -ok   ls -l   {} \;  
            < ls … ./classDB.inc.php > ? y
            -rw-r–r–    1 cnscn    cnscn       13709   1月 12 12:22 ./classDB.inc.php
            [root@book class]# find   ./   -mtime   -1   -type f   -ok   ls -l   {} \;  
            < ls … ./classDB.inc.php > ? n
            [root@book class]#

            =================================================
            查詢(xún)并交給awk去處理
            [root@book class]# who   |   awk   ’{print $1"\t"$2}’
            cnscn    pts/0

            =================================================
            awk—grep—sed

            [root@book class]# df   -k |   awk ‘{print $1}’ |   grep   -v   ’none’ |   sed   s"/\/dev\///g"
            文件系統(tǒng)
            sda2
            sda1
            [root@book class]# df   -k |   awk ‘{print $1}’ |   grep   -v   ’none’
            文件系統(tǒng)
            /dev/sda2
            /dev/sda1

            1)在/tmp中查找所有的*.h,并在這些文件中查找“SYSCALL_VECTOR",最后打印出所有包含"SYSCALL_VECTOR"的文件名

            A) find   /tmp   -name   "*.h"   | xargs   -n50   grep SYSCALL_VECTOR
            B) grep   SYSCALL_VECTOR   /tmp/*.h | cut    -d’:'   -f1| uniq > filename
            C) find   /tmp   -name "*.h"   -exec grep "SYSCALL_VECTOR"   {}   \; -print

            2)find / -name filename -exec rm -rf {} \;
                find / -name filename -ok rm -rf {} \;

            3)比如要查找磁盤(pán)中大于3M的文件:
            find . -size +3000k -exec ls -ld {} ;

            4)將find出來(lái)的東西拷到另一個(gè)地方
            find *.c -exec cp ‘{}’ /tmp ‘;’

            如果有特殊文件,可以用cpio,也可以用這樣的語(yǔ)法:
            find dir -name filename -print | cpio -pdv newdir

            6)查找2004-11-30 16:36:37時(shí)更改過(guò)的文件
            # A=`find ./ -name "*php"` |   ls -l –full-time $A 2>/dev/null | grep "2004-11-30 16:36:37"

            Linux-allLinux | No Comments »

            find 實(shí)例

            四月 18th, 2006

              要在/usr/linux中查找所有的*.h,并在這些文件中查找“SYSCALL_VECTOR",最后打印出所有包含"SYSCALL_VECTOR"的文件名,有以下幾種方法實(shí)現(xiàn)
            find /usr/linux -name "*.h" | xargs -n50 grep SYSCALL_VECTOR
            grep SYSCALL_VECTOR /usr/linux/*.h | cut -d’:’ -f1 | uniq > filename
            find /usr/linux -name "*.h" -exec grep "SYSCALL_VECTOR" {} \; -print

              我用find / -name filename| rm -rf,不成功,請(qǐng)問(wèn)為什么不成功?
            find / -name filename -exec rm -rf {} \;
            find . -name filename |rm -rf試一下{} 表示你找出來(lái)的結(jié)果。
            \; 則相當(dāng)于“憲法”,沒(méi)什么說(shuō)頭,就是這么規(guī)定的,在 -exec 后面需要一個(gè)表示該命令終結(jié)的的符號(hào)。可以在 man find 中找到答案。
            要讓rm識(shí)別find的結(jié)果,如下:
            find / -name filename |xargs rm -rf
            之所以find . -name filename |rm -rf不通過(guò),是因?yàn)閞m命令不接受從標(biāo)準(zhǔn)輸入傳過(guò)來(lái)的指令
            查找含特定字符串的文件
            例如查找當(dāng)前目錄下含有"the string you want find…"字符串的文件:
            $find . -type f -exec grep “the string you want find…” {} ; -print

              從根目錄開(kāi)始查tmpfile,一旦查到馬上刪除
            find / -name "tmpfile" -exec rm {} \;

              find 的perm問(wèn)題
            請(qǐng)問(wèn)一下以下命令什么意思?關(guān)鍵是那個(gè)數(shù)字前的-,其他都還知道
            find -name ".*" -perm -007
            我知道
            find -name ".*" -perm 755
            這個(gè)是用來(lái)查找權(quán)限位為755的隱藏文件
            噢,對(duì)了還有,我上邊的命令都省略了find的pathname參數(shù) find默認(rèn)是查找當(dāng)前工作目錄的嗎?
            如果我用 -ok 替代 -exec, 那么還需要加上 {} \; 嗎?
            這個(gè)已經(jīng)清楚,仍然需要,因?yàn)?-ok 只是 -exec 的提示模式,它只是多了一個(gè)確認(rèn)操作的步驟,剛才沒(méi)有讀懂那幾句E文的意思 呵呵 不好意思
            -007是指查找所有用戶(hù)都可讀、寫(xiě)、執(zhí)行的文件,要小心呀~~~
            解釋解釋?zhuān)?br style="margin: 0px; padding: 0px;" /> find -name ".*" -perm -007 和 find -name ".*" -perm 777 有區(qū)別嗎?
            -007是怎么來(lái)得呢?
            不過(guò)有一個(gè)問(wèn)題
            我用 find . -perm -100 會(huì)列出當(dāng)前目錄 . , 這是為什么呢?

            下面引用由explover在 2002/10/01 06:15am 發(fā)表的內(nèi)容:
            -007是指查找所有用戶(hù)都可讀、寫(xiě)、執(zhí)行的文件,要小心呀~~~
            -007是查找含其它用戶(hù)(不同組,非屬主)可讀,寫(xiě),執(zhí)行的文件.并不一定要同組可讀寫(xiě),-是指最少權(quán)限為007.
            下面引用由一顆小白菜在 2002/10/01 10:16am 發(fā)表的內(nèi)容:
            OK了, 呵呵
            不過(guò)有一個(gè)問(wèn)題
            我用 find . -perm -100 會(huì)列出當(dāng)前目錄 . , 這是為什么呢?
            這種方法不會(huì)準(zhǔn)確的找出目錄的. -100是指權(quán)限至少是屬主可運(yùn)行.
            在unix系統(tǒng)下,你可以擁有對(duì)目錄文件的執(zhí)行權(quán)你才可以進(jìn)入一個(gè)目錄.這便是目錄文件被列出的原因.
            find . -perm -001 -print找到往往是目錄文件.
            我的意思當(dāng)然不是使用這種方法來(lái)找目錄,只不過(guò)不明白其中的 -100 意義了
            那以此類(lèi)推,是不是 -010是指權(quán)限至少是owner同組可執(zhí)行的嗎?也就是說(shuō)其實(shí)這里的010和-是分開(kāi)的,-表示一個(gè)至少的意思,而且010才是真正用來(lái)描述權(quán)限位的?
            這樣子就明白了 謝謝你噢

              將find出來(lái)的東西拷到另一個(gè)地方?
            find *.c -exec cp ‘{}’ /tmp ‘;’
            如果有特殊文件,可以用cpio,也可以用這樣的語(yǔ)法:
            find dir -name filename -print | cpio -pdv newdir

              找出磁盤(pán)中某個(gè)大小范圍內(nèi)的文件
            比如要查找磁盤(pán)中大于3M的文件:
            find . -size +3000k -exec ls -ld {} ;

              如何用find查找某一天更改的文件?
            可以使用這一行命令來(lái)實(shí)現(xiàn):
            A=`find ~ -print` | ls -l –full-time $A 2>/dev/null | grep "Jun 27" | grep 1998

              使用find 命令查找某個(gè)時(shí)間段的shell怎么寫(xiě)。比如11點(diǎn)到12點(diǎn)的。thanks
            創(chuàng)建一個(gè)腳本judgetime,內(nèi)容如下:
            ls -l $*|awk ‘{split($8,hour,":");if((hour[1]>23 || hour[1] < 1)&&hour[1]<24)print}’
            到要查找的目錄下,運(yùn)行
            find ./ -name "*" -exec judgetime {} \;
            注意時(shí)間格式為24小時(shí)制。
            thank you ,如果我要精確到分鐘呢
            touch -t 04241112 starttemp #精確到12分鐘
            touch -t 04241220 endtemp #截止到12點(diǎn)20
            find [dir] -newer starttemp -a ! -newer endtemp -exec ls -l {} \;
            newer?
            那昨天12:10文件如何呢?
            每天執(zhí)行的時(shí)候,用當(dāng)天的日期和時(shí)間戳替換一下不就行了嗎?
            我不知道他是不是把所有的11:00~12:00的都找出來(lái),是不是只執(zhí)行一次還是每天都執(zhí)行?
            這種情況俺猜想是自己的東西放在哪忘了,只記得當(dāng)時(shí)是深夜了。
            有道理!
            不愧是斑竹!
            不光知道怎么解決問(wèn)題,還知道在什么情況下出現(xiàn)這類(lèi)問(wèn)題,佩服佩服!
            問(wèn)題又出現(xiàn)了。創(chuàng)建這個(gè)文件的時(shí)候。本來(lái)應(yīng)該是時(shí)間的一欄現(xiàn)在寫(xiě)上了2002,而不是12:00.
            等到12:00過(guò)了吧!

              刪除指定日期的文件
            find ./ -name 文件名 -exec rm -f {} \;
            例:刪除當(dāng)前30天內(nèi)沒(méi)用過(guò)的文件,用如下命令:
            find / -atime +30 -exec rm -f {} \;
            我自己試著寫(xiě)了一小段SHELL,也用ll ,grep, rm 幾個(gè)命令,用起來(lái)還差強(qiáng)人意。
            對(duì)過(guò)濾出來(lái)的文件名列表中用了一個(gè)FOR語(yǔ)句,再執(zhí)行rm 。現(xiàn)在我想把這段SHELL 擴(kuò)展一下讓它每天定時(shí)運(yùn)行將 n 天前的文件刪掉,有沒(méi)有人能給我一些提示,謝謝!
            還有個(gè)問(wèn)題,對(duì)于前面那位朋友提到的"find / -atime +30 -exec rm -f {} \;
            "方法,我很早就試過(guò)幾次,不過(guò)好像都不太對(duì),參數(shù) -atime n 是查找n天前被訪(fǎng)問(wèn)過(guò)的文件,我不明白的是這里的時(shí)間參照點(diǎn)是什么,以及這個(gè)n天是怎么計(jì)算的。
            問(wèn) 題二、對(duì)于"ll |cut -f 1" 這個(gè)命令我是不是用錯(cuò)了,我只想取出 ll 中列出的文件名,但用cut -f 命令做不到 ,我只好換用 ll |cut -c 59- 這種方式得到我要的文件名,but it’s a pool idear !我也試過(guò)用awk ,好像也不對(duì),看看大家可不可以給我一些小小的提醒,TKS SO MUCH
            問(wèn)題三、如何改變 I結(jié)點(diǎn) 的日期格式 我現(xiàn)在的系統(tǒng)顯示的格式是:
            -rw-r—– 1 msahz01 users 2253 2002年2月 2日 poheader.i
            我想把這換成
            -rw-rw-rw- 1 house users 2193 Apr 19 2001 hkdisp.p
            如何才能做到這點(diǎn)?
            awk 應(yīng)該可以
            ll | awk ‘{print $9}’
            刪除多少天之前的文件
            find /yourpath -mtime +31 -exec rm {} \;
            find /yourpath -mtime +366 -exec rm {} \;

            find中, -ctime, -mtime及其-atime有何區(qū)別

            請(qǐng)問(wèn) -ctime 和 -mtime 有什么關(guān)系 ?
            如果父目錄的 ctime 改變, 那它下面的文件的 ctime 就會(huì)自動(dòng)都改了嗎 ?
            -ctime 和 -mtime ,-atime 這些信息是存在哪兒呢 ?

            我用 -mtime -1 找到了新建或改的文件.
            但怎樣才能找到一天內(nèi) mv 來(lái)的文件呢( 它們的時(shí)間是原有的時(shí)間,早于一天 ) ?

            用-newer選項(xiàng)啊。
            你可以先touch一個(gè)你想要的時(shí)間的文件如下:
            $ touch -t 08190800 test
            $ ls -l test
            -rw-r–r– 1 dba other 0 Aug 19 08:00 test
            然后
            $ find . -newer test -print
            .
            ./.sh_history
            $ ls -l .sh_history
            -rw——- 1 dba other 154 Aug 20 17:39 .sh_history

            用touch可以寫(xiě)出你想要的任何時(shí)間的文件,然后用-newer ,! -newer選項(xiàng)即可成功。

            1.ctime含inode信息修改的時(shí)間.mtime只指文件內(nèi)容建立或修改的時(shí)間.
            2 不會(huì).
            3.這些信息應(yīng)該是存在文件系統(tǒng)的超級(jí)塊里.

            我查了書(shū) -ctime 是指 inode 的改變(或稱(chēng)文件的狀態(tài)改變).
            請(qǐng)問(wèn) inode 存了哪些信息 ?
            做了些小測(cè)試,-mtime 改, -ctime 一定也改.
            改文件名, -ctime 也會(huì)改.
            誰(shuí)能回答 i-node 存了哪些東西 ?

            vi /usr/include/sys/inode.h

            班主,我不能 access /usr/include/sys/inode.h .
            摘書(shū)如下:
            Directories contain directory entries. Each entry contains a file or subdirectory name and an index node reference number (i-node number). To increase speed and enhance use of disk space, the data in a file is stored at various locations in the computer’s memory. The i-node contains the addresses used to locate all the scattered blocks of data associated with a file. The i-node also records other information about the file including time of modification and access, access modes, number of links, file owner, and file type.
            可我發(fā)現(xiàn) -atime 改了, -ctime 還沒(méi)改. why ?
            ( 我先 cat 一個(gè) ASCII 文件,再用 -atime -1 有它用 -ctime -1 居然沒(méi)有它.)
            著豈不跟 inode 信息改變, ctime 就改矛盾嗎?

            我不同意你貼出來(lái)的那段文章,正如我提到的那樣,atime,ctime,mtime是放到超級(jí)塊里,在sco unix下是一種叫stat的結(jié)構(gòu).(stat_32),不同的系統(tǒng)文件系統(tǒng)可能不同.
            sco 下inode的結(jié)構(gòu)如下:

            typedef struct inode
            {
            struct inode *i_forw; /* inode hash chain */
            struct inode *i_back; /* ‘’ */
            struct inode *av_forw; /* freelist chain */
            struct inode *av_back; /* ‘’ */
            int *i_fsptr; /* "typeless" pointer to fs dependent */
            ino32_t i_number; /* i number, 1-to-1 with dev address */
            ushort i_ftype; /* file type = IFDIR, IFREG, etc. */
            short i_fstyp; /* File system type */
            off_t i_size; /* size of file */
            ushort i_uid; /* owner */
            ushort i_gid; /* group of owner */
            ushort i_flag;
            ushort i_want; /* i_flag extension to avoid MP races */
            ushort i_count; /* reference count */
            short i_nlink; /* directory entries */
            dev_t i_rdev; /* Raw device number */
            #define i_namtype i_rdev /* i_ftype==IFNAM subtype */
            dev_t i_dev; /* device where inode resides */
            struct mount *i_mton;/* ptr to mount table entry that */
            /* this directory is mounted on */
            struct region *i_rp; /* ptr to shared region if any */
            struct stdata *i_sp; /* ptr to associated stream */
            struct iisem *isem; /* ptr to XENIX semaphores */
            struct iisd *isd; /* ptr to XENIX shared data */
            } i_un;
            #define i_mnton i_un.i_mton /* i_ftype==IFDIR IMOUNT */
            #define i_rptr i_un.i_rp /* i_ftype==IFREG || i_ftype==IFBLK */
            #define i_sptr i_un.i_sp /* i_ftype==IFCHR || i_ftype==IFIFO */
            #define i_sem i_un.isem /* i_ftype==IFNAM && i_namtype==IFSEM */
            #define i_sd i_un.isd /* i_ftype==IFNAM && i_namtype==IFSHD */

            struct fstypsw *i_fstypp; /* ptr to file system switch FSPTR */
            long *i_filocks; /* pointer to filock (structure) list */
            unsigned long i_mappages; /* number of pages currently cached */
            unsigned long i_vcode; /* read-ahead block save (NFS) */
            short i_wcnt; /* write open count or ITEXT count */
            struct lockb i_cilock; /* tas to synchronize i_flag changes */
            ushort i_rdlocks; /* count of non-exclusive lockers */
            } inode_t;

            所以,訪(fǎng)問(wèn)一個(gè)文件不能改變inode信息.
            使用chown, chgrp, chmod命令可以很好的比較mtime和ctime
            chown改變一個(gè)文件的屬主,用ctime可以找到,用mtime便找不到.
            試試看.

            多謝斑竹! 我是在 Solaris 上面試的.我是對(duì) -ctime 不明白.
            試的結(jié)果如下:
            修改文件,-mtime 改了, -ctime 也會(huì)改.
            訪(fǎng)問(wèn)文件,-atime 改了, -ctime 沒(méi)變.
            chown, chgrp, chmod,mv, 都會(huì)使 -ctime 改變,但不影響 -atime 和 -mtime.
            touch 可以改 -mtime and/or -atime,但 touch -a 只改訪(fǎng)問(wèn)時(shí)間時(shí),-ctime也改了.
            touch -m 改修改時(shí)間時(shí),-ctime當(dāng)然也改了.
            好象還有別的很多東西可以令 -ctime 改變, 搞不清楚.
            有什么方法可以顯示 -mtime,atime,ctime 嗎?
            可以用 -ctime 來(lái)實(shí)現(xiàn)對(duì)目錄的增量文件進(jìn)行備份或 transfer 嗎 ?
            多謝!

            沒(méi)有什么工具顯示,(可能是俺不知道)
            把下面程序里的st_mtime換成st_ctime,或st_atime便可以得到你要的了.
            #include
            int
            main (int argc, char **argv)
            {
            struct stat buf;
            char date[80];
            char fname[80];
            printf("Enter filename (with full path) to check mtime : ");
            scanf("%s",fname);
            stat(fname, &buf);
            printf ("mtime (in sec) of %s = %ld\n", fname, buf.st_mtime);
            strcpy(date, ctime((time_t *)&(buf.st_mtime)));
            printf ("mtime (in date) of %s = %s\n", fname, date);
            }

            至于文件備份,有什么不可以的么?

            mtime ls -l 最近修改文件內(nèi)容的時(shí)間
            atime ls -lu 最近訪(fǎng)問(wèn)文件的時(shí)間
            ctime ls -li 最近文件有所改變的狀態(tài) ,如文件修改,屬性\屬主 改變 ,節(jié)點(diǎn) ,鏈接變化等 ,應(yīng)該是不拘泥只是時(shí)間前后的改變

            俺看了ls的幫助,以為只是按ctime或atime排序,顯示的時(shí)間還是mtime.

            仔細(xì)比較了一下,ayhan說(shuō)的是對(duì)的.謝謝ayhan.

            多謝 ahyan 提示 ! 我在 Solaris 上試過(guò)如下:
            mtime 用 ls -l 看到
            atime 用 ls -lu 看到
            ctime 用 ls -lc 看到. (ls -li 只有 inode number)
            摘書(shū)如下:
            -c Uses time of last modification of the i-node (file
            created, mode changed, and so forth) for sorting (-t)
            or printing (-l or -n).
            -u Uses time of last access instead of last modification
            for sorting (with the -t option) or printing (with the
            -l option).
            -i For each file, prints the i-node number in the first
            column of the report.








            =======================================================================================

            1. set命令可以顯示出當(dāng)前shell下所有全局參量定義及其值;
             
            2. 查找并刪除當(dāng)前目錄下小文件:
            find . -type f -size -10k -exec rm {} \;
            說(shuō)明: www.2cto.com  
            -type f 查找文件
            -size -10k,
            小于10k的。"+"是表示要求系統(tǒng)只列出大于指定大小的文件,而使用"-"則表示要求系統(tǒng)列出小于指定大小的文件。
             
            3. 遍歷文件夾grep一個(gè)字符串
            find . -name "*c" | xargs grep "strings"
            在當(dāng)前文件夾下所有c文件中查找字符串“string”
             
            4. 在某目錄下文件中查找某字符串
            grep -r youcode dir
            例如:查找home下文件中查找hello
            grep -r hello /home
            例如:在當(dāng)前所有目錄下文件中查找hello,不區(qū)分大小寫(xiě)
            grep -ir hello .  www.2cto.com  
            從文件內(nèi)容查尋匹配指定字符串的行:
             
              $ grep "被查尋的字符串" 文件名
             
            從文件內(nèi)容查尋與正則表達(dá)式匹配的行:
             
              $ grep –e “正則表達(dá)式” 文件名
             
            查尋時(shí)不區(qū)分大小寫(xiě):
             
              $ grep –i "被查尋的字符串" 文件名
             
            查尋匹配的行數(shù):
             
                  www.2cto.com  
              $ grep -c "被查尋的字符串" 文件名
             
            從文件內(nèi)容查尋不匹配指定字符串的行:
             
              $ grep –v "被查尋的字符串" 文件名
             

            從根目錄開(kāi)始查尋所有擴(kuò)展名為.log的文本文件,并找出包羅”ERROR”的行
            @import url(http://www.shnenglu.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
            posted on 2016-06-26 18:17 聶文龍 閱讀(347) 評(píng)論(3)  編輯 收藏 引用

            FeedBack:
            # re: Linux中find常見(jiàn)用法示例 2016-06-26 18:21 聶文龍
            Linux下find命令在目錄結(jié)構(gòu)中搜索文件,并執(zhí)行指定的操作。Linux下find命令提供了相當(dāng)多的查找條件,功能很強(qiáng)大。由于find具有強(qiáng)大的功能,所以它的選項(xiàng)也很多,其中大部分選項(xiàng)都值得我們花時(shí)間來(lái)了解一下。即使系統(tǒng)中含有網(wǎng)絡(luò)文件系統(tǒng)( NFS),find命令在該文件系統(tǒng)中同樣有效,只你具有相應(yīng)的權(quán)限。 在運(yùn)行一個(gè)非常消耗資源的find命令時(shí),很多人都傾向于把它放在后臺(tái)執(zhí)行,因?yàn)楸闅v一個(gè)大的文件系統(tǒng)可能會(huì)花費(fèi)很長(zhǎng)的時(shí)間(這里是指30G字節(jié)以上的文件系統(tǒng))。
            1.命令格式:
            find pathname -options [-print -exec -ok ...]
            2.命令功能:
            用于在文件樹(shù)種查找文件,并作出相應(yīng)的處理
            3.命令參數(shù):
            pathname: find命令所查找的目錄路徑。例如用.來(lái)表示當(dāng)前目錄,用/來(lái)表示系統(tǒng)根目錄。
            -print: find命令將匹配的文件輸出到標(biāo)準(zhǔn)輸出。
            -exec: find命令對(duì)匹配的文件執(zhí)行該參數(shù)所給出的shell命令。相應(yīng)命令的形式為'command' { } \;,注意{ }和\;之間的空格。
            -ok: 和-exec的作用相同,只不過(guò)以一種更為安全的模式來(lái)執(zhí)行該參數(shù)所給出的shell命令,在執(zhí)行每一個(gè)命令之前,都會(huì)給出提示,讓用戶(hù)來(lái)確定是否執(zhí)行。
            4.命令選項(xiàng):
            -name 按照文件名查找文件。
            -perm 按照文件權(quán)限來(lái)查找文件。
            -prune 使用這一選項(xiàng)可以使find命令不在當(dāng)前指定的目錄中查找,如果同時(shí)使用-depth選項(xiàng),那么-prune將被find命令忽略。
            -user 按照文件屬主來(lái)查找文件。
            -group 按照文件所屬的組來(lái)查找文件。
            -mtime -n +n 按照文件的更改時(shí)間來(lái)查找文件, - n表示文件更改時(shí)間距現(xiàn)在n天以?xún)?nèi),+ n表示文件更改時(shí)間距現(xiàn)在n天以前。find命令還有-atime和-ctime 選項(xiàng),但它們都和-m time選項(xiàng)。
            -nogroup 查找無(wú)有效所屬組的文件,即該文件所屬的組在/etc/groups中不存在。
            -nouser 查找無(wú)有效屬主的文件,即該文件的屬主在/etc/passwd中不存在。
            -newer file1 ! file2 查找更改時(shí)間比文件file1新但比文件file2舊的文件。
            -type 查找某一類(lèi)型的文件,諸如:
            b - 塊設(shè)備文件。
            d - 目錄。
            c - 字符設(shè)備文件。
            p - 管道文件。
            l - 符號(hào)鏈接文件。
            f - 普通文件。
            -size n:[c] 查找文件長(zhǎng)度為n塊的文件,帶有c時(shí)表示文件長(zhǎng)度以字節(jié)計(jì)。-depth:在查找文件時(shí),首先查找當(dāng)前目錄中的文件,然后再在其子目錄中查找。
            -fstype:查找位于某一類(lèi)型文件系統(tǒng)中的文件,這些文件系統(tǒng)類(lèi)型通常可以在配置文件/etc/fstab中找到,該配置文件中包含了本系統(tǒng)中有關(guān)文件系統(tǒng)的信息。
            -mount:在查找文件時(shí)不跨越文件系統(tǒng)mount點(diǎn)。
            -follow:如果find命令遇到符號(hào)鏈接文件,就跟蹤至鏈接所指向的文件。
            -cpio:對(duì)匹配的文件使用cpio命令,將這些文件備份到磁帶設(shè)備中。
            另外,下面三個(gè)的區(qū)別:
            -amin n 查找系統(tǒng)中最后N分鐘訪(fǎng)問(wèn)的文件
            -atime n 查找系統(tǒng)中最后n*24小時(shí)訪(fǎng)問(wèn)的文件
            -cmin n 查找系統(tǒng)中最后N分鐘被改變文件狀態(tài)的文件
            -ctime n 查找系統(tǒng)中最后n*24小時(shí)被改變文件狀態(tài)的文件
            -mmin n 查找系統(tǒng)中最后N分鐘被改變文件數(shù)據(jù)的文件
            -mtime n 查找系統(tǒng)中最后n*24小時(shí)被改變文件數(shù)據(jù)的文件
            5.使用實(shí)例:
            實(shí)例1:查找指定時(shí)間內(nèi)修改過(guò)的文件
            命令:
            find -atime -2
            輸出:

            復(fù)制代碼代碼如下:

            [root@peidachang ~]# find -atime -2
            .
            ./logs/monitor
            ./.bashrc
            ./.bash_profile
            ./.bash_history
            說(shuō)明:
            超找48小時(shí)內(nèi)修改過(guò)的文件
            實(shí)例2:根據(jù)關(guān)鍵字查找
            命令:
            find . -name "*.log"
            輸出:

            復(fù)制代碼代碼如下:

            [root@localhost test]# find . -name "*.log"
            ./log_link.log
            ./log2014.log
            ./test4/log3-2.log
            ./test4/log3-3.log
            ./test4/log3-1.log
            ./log2013.log
            ./log2012.log
            ./log.log
            ./test5/log5-2.log
            ./test5/log5-3.log
            ./test5/log.log
            ./test5/log5-1.log
            ./test5/test3/log3-2.log
            ./test5/test3/log3-3.log
            ./test5/test3/log3-1.log
            ./test3/log3-2.log
            ./test3/log3-3.log
            ./test3/log3-1.log
            說(shuō)明:
            在當(dāng)前目錄查找 以.log結(jié)尾的文件。 ". "代表當(dāng)前目錄
            實(shí)例3:按照目錄或文件的權(quán)限來(lái)查找文件
            命令:
            find /opt/soft/test/ -perm 777
            輸出:

            復(fù)制代碼代碼如下:

            [root@localhost test]# find /opt/soft/test/ -perm 777
            /opt/soft/test/log_link.log
            /opt/soft/test/test4
            /opt/soft/test/test5/test3
            /opt/soft/test/test3
            說(shuō)明:
            查找/opt/soft/test/目錄下 權(quán)限為 777的文件
            實(shí)例4:按類(lèi)型查找
            命令:
            find . -type f -name "*.log"
            輸出:

            復(fù)制代碼代碼如下:

            [root@localhost test]# find . -type f -name "*.log"
            ./log2014.log
            ./test4/log3-2.log
            ./test4/log3-3.log
            ./test4/log3-1.log
            ./log2013.log
            ./log2012.log
            ./log.log
            ./test5/log5-2.log
            ./test5/log5-3.log
            ./test5/log.log
            ./test5/log5-1.log
            ./test5/test3/log3-2.log
            ./test5/test3/log3-3.log
            ./test5/test3/log3-1.log
            ./test3/log3-2.log
            ./test3/log3-3.log
            ./test3/log3-1.log
            [root@localhost test]#
            說(shuō)明:
            查找當(dāng)目錄,以.log結(jié)尾的普通文件
            實(shí)例5:查找當(dāng)前所有目錄并排序
            命令:
            find . -type d | sort
            輸出:

            復(fù)制代碼代碼如下:

            [root@localhost test]# find . -type d | sort
            .
            ./scf
            ./scf/bin
            ./scf/doc
            ./scf/lib
            ./scf/service
            ./scf/service/deploy
            ./scf/service/deploy/info
            ./scf/service/deploy/product
            ./test3
            ./test4
            ./test5
            ./test5/test3
            [root@localhost test]#
            實(shí)例6:按大小查找文件
            命令:
            find . -size +1000c -print
            輸出:

            復(fù)制代碼代碼如下:

            [root@localhost test]# find . -size +1000c -print
            .
            ./test4
            ./scf
            ./scf/lib
            ./scf/service
            ./scf/service/deploy
            ./scf/service/deploy/product
            ./scf/service/deploy/info
            ./scf/doc
            ./scf/bin
            ./log2012.log
            ./test5
            ./test5/test3
            ./test3
            [root@localhost test]#
            說(shuō)明:
            查找當(dāng)前目錄大于1K的文件
            一、Linux中find常見(jiàn)用法示例
            ·find path -option [ -print ] [ -exec -ok command ] {} \;
            #-print 將查找到的文件輸出到標(biāo)準(zhǔn)輸出
            #-exec command {} \; -----將查到的文件執(zhí)行command操作,{} 和 \;之間有空格
            #-ok 和-exec相同,只不過(guò)在操作前要詢(xún)用戶(hù) ==================================================== -name filename #查找名為filename的文件
            -perm #按執(zhí)行權(quán)限來(lái)查找
            -user username #按文件屬主來(lái)查找
            -group groupname #按組來(lái)查找
            -mtime -n +n #按文件更改時(shí)間來(lái)查找文件,-n指n天以?xún)?nèi),+n指n天以前
            -atime -n +n #按文件訪(fǎng)問(wèn)時(shí)間來(lái)查GIN: 0px">-perm #按執(zhí)行權(quán)限來(lái)查找
            -user username #按文件屬主來(lái)查找
            -group groupname #按組來(lái)查找
            -mtime -n +n #按文件更改時(shí)間來(lái)查找文件,-n指n天以?xún)?nèi),+n指n天以前
            -atime -n +n #按文件訪(fǎng)問(wèn)時(shí)間來(lái)查找文件,-n指n天以?xún)?nèi),+n指n天以前
            -ctime -n +n #按文件創(chuàng)建時(shí)間來(lái)查找文件,-n指n天以?xún)?nèi),+n指n天以前
            -nogroup #查無(wú)有效屬組的文件,即文件的屬組在/etc/groups中不存在
            -nouser #查無(wú)有效屬主的文件,即文件的屬主在/etc/passwd中不存
            -newer f1 !f2 找文件,-n指n天以?xún)?nèi),+n指n天以前
            -ctime -n +n #按文件創(chuàng)建時(shí)間來(lái)查找文件,-n指n天以?xún)?nèi),+n指n天以前
            -nogroup #查無(wú)有效屬組的文件,即文件的屬組在/etc/groups中不存在
            -nouser #查無(wú)有效屬主的文件,即文件的屬主在/etc/passwd中不存
            -newer f1 !f2 #查更改時(shí)間比f(wàn)1新但比f(wàn)2舊的文件
            -type b/d/c/p/l/f #查是塊設(shè)備、目錄、字符設(shè)備、管道、符號(hào)鏈接、普通文件
            -size n[c] #查長(zhǎng)度為n塊[或n字節(jié)]的文件
            -depth #使查找在進(jìn)入子目錄前先行查找完本目錄
            -fstype #查更改時(shí)間比f(wàn)1新但比f(wàn)2舊的文件
            -mount #查文件時(shí)不跨越文件系統(tǒng)mount點(diǎn)
            -follow #如果遇到符號(hào)鏈接文件,就跟蹤鏈接所指的文件
            -cpio #對(duì)匹配的文件使用cpio命令,將他們備份到磁帶設(shè)備中
            -prune #忽略某個(gè)目錄 ====================================================
            $find ~ -name "*.txt" -print #在$HOME中查.txt文件并顯示
            $find . -name "*.txt" -print
            $find . -name "[A-Z]*" -pri26nbsp; #對(duì)匹配的文件使用cpio命令,將他們備份到磁帶設(shè)備中
            -prune #忽略某個(gè)目錄 $find . -name "[A-Z]*" -print #查以大寫(xiě)字母開(kāi)頭的文件
            $find /etc -name "host*" -print #查以host開(kāi)頭的文件
            $find . -name "[a-z][a-z][0--9][0--9].txt" -print #查以?xún)蓚€(gè)小寫(xiě)字母和兩個(gè)數(shù)字開(kāi)頭的txt文件
            $find . -perm 755 -print
            $find . -perm -007 -exec ls -l {} \; #查所有用戶(hù)都可讀寫(xiě)執(zhí)行的文件同-perm 777
            $find . -type d -print 打印目錄結(jié)構(gòu)
            $find . ! -type d -print 打印非目錄文件 find /usr/include -name '*.h' -exec grep AF_INEF6 {} \; 因grep無(wú)法遞歸搜索子目錄,故可以和find相結(jié)合使用。 在/usr/include 所有子目錄中的.h文件中找字串AF_INEF6
            $find . -type l -print $find . -size +1000000c -print #查長(zhǎng)度大于1Mb的文件
            $find . -size 100c -print # 查長(zhǎng)度為100c的文件
            $find . -size +10 -print #查長(zhǎng)度超過(guò)期作廢10塊的文件(1塊=512字節(jié)) $cd /
            $find etc home apps -depth -print | cpio -ivcdC65536 -o /dev/rmt0
            $find /etc -name "passwd*" -exec grep "cnscn" {} \; #看是否存在cnscn用戶(hù)
            $find . -name "yao*" | xargs file
            $find . -name "yao*" | xargs echo "" > /tmp/core.log
            $find . -name "yao*" | xargs chmod o-w ====================================================== find -name april* 在當(dāng)前目錄下查找以april開(kāi)始的文件
            find -name april* fprint file 在當(dāng)前目錄下查找以april開(kāi)始的文件,并把結(jié)果輸出到file中
            find -name ap* -o -name may* 查找以ap或may開(kāi)頭的文件
            find /mnt -name tom.txt -ftype vfat 在/mnt下查找名稱(chēng)為tom.txt且文件系統(tǒng)類(lèi)型為vfat的文件
            find /mnt -name t.txt ! -ftype vfat 在/mnt下查找名稱(chēng)為tom.txt且文件系統(tǒng)類(lèi)型不為vfat的文件
            find /tmp -name wa* -type l 在/tmp下查找名為wa開(kāi)頭且類(lèi)型為符號(hào)鏈接的文件
            find /home -mtime -2 在/home下查最近兩天內(nèi)改動(dòng)過(guò)的文件
            find /home -atime -1 查1天之內(nèi)被存取過(guò)的文件
            find /home -mmin +60 在/home下查60分鐘前改動(dòng)過(guò)的文件
            find /home -amin +30 查最近30分鐘前被存取過(guò)的文件
            find /home -newer tmp.txt 在/home下查更新時(shí)間比tmp.txt近的文件或目錄
            find /home -anewer tmp.txt 在/home下查存取時(shí)間比tmp.txt近的文件或目錄
            find /home -used -2 列出文件或目錄被改動(dòng)過(guò)之后,在2日內(nèi)被存取過(guò)的文件或目錄
            find /home -user cnscn 列出/home目錄內(nèi)屬于用戶(hù)cnscn的文件或目錄
            find /home -uid +501 列出/home目錄內(nèi)用戶(hù)的識(shí)別碼大于501的文件或目錄
            find /home -group cnscn 列出/home內(nèi)組為cnscn的文件或目錄
            find /home -gid 501 列出/home內(nèi)組id為501的文件或目錄
            find /home -nouser 列出/home內(nèi)不屬于本地用戶(hù)的文件或目錄
            find /home -nogroup 列出/home內(nèi)不屬于本地組的文件或目錄
            find /home -name tmp.txt -maxdepth 4 列出/home內(nèi)的tmp.txt 查時(shí)深度最多為3層
            find /home -name tmp.txt -mindepth 3 從第2層開(kāi)始查
            find /home -empty 查找大小為0的文件或空目錄
            find /home -size +512k 查大于512k的文件
            find /home -size -512k 查小于512k的文件
            find /home -links +2 查硬連接數(shù)大于2的文件或目錄
            find /home -perm 0700 查權(quán)限為700的文件或目錄
            find /tmp -name tmp.txt -exec cat {} \;
            find /tmp -name tmp.txt -ok rm {} \; find / -amin -10 # 查找在系統(tǒng)中最后10分鐘訪(fǎng)問(wèn)的文件
            find / -atime -2 # 查找在系統(tǒng)中最后48小時(shí)訪(fǎng)問(wèn)的文件
            find / -empty # 查找在系統(tǒng)中為空的文件或者文件夾
            find / -group cat # 查找在系統(tǒng)中屬于 groupcat的文件
            find / -mmin -5 # 查找在系統(tǒng)中最后5分鐘里修改過(guò)的文件
            find / -mtime -1 #查找在系統(tǒng)中最后24小時(shí)里修改過(guò)的文件
            find / -nouser #查找在系統(tǒng)中屬于作廢用戶(hù)的文件
            find / -user fred #查找在系統(tǒng)中屬于FRED這個(gè)用戶(hù)的文件

            查當(dāng)前目錄下的所有普通文件
            -------------------------------------------------------------------------------- # find . -type f -exec ls -l {} \;
            -rw-r--r-- 1 root root 34928 2003-02-25 ./conf/httpd.conf
            -rw-r--r-- 1 root root 12959 2003-02-25 ./conf/magic
            -rw-r--r-- 1 root root 180 2003-02-25 ./conf.d/README
            查當(dāng)前目錄下的所有普通文件,并在- e x e c選項(xiàng)中使用ls -l命令將它們列出
            =================================================
            在/ l o g s目錄中查找更改時(shí)間在5日以前的文件并刪除它們:
            $ find logs -type f -mtime +5 -exec -ok rm {} \;
            =================================================
            查詢(xún)當(dāng)天修改過(guò)的文件
            [root@book class]# find ./ -mtime -1 -type f -exec ls -l {} \;
            =================================================
            查詢(xún)文件并詢(xún)問(wèn)是否要顯示
            [root@book class]# find ./ -mtime -1 -type f -ok ls -l {} \;
            < ls ... ./classDB.inc.php > ? y
            -rw-r--r-- 1 cnscn cnscn 13709 1月 12 12:22 ./classDB.inc.php
            [root@book class]# find ./ -mtime -1 -type f -ok ls -l {} \;
            < ls ... ./classDB.inc.php > ? n
            [root@book class]# =================================================
            查詢(xún)并交給awk去處理
            [root@book class]# who | awk '{print $1"\t"$2}'
            cnscn pts/0 =================================================
            awk---grep---sed [root@book class]# df -k | awk '{print $1}' | grep -v 'none' | sed s"/\/dev\///g"
            文件系統(tǒng)
            sda2
            sda1
            [root@book class]# df -k | awk '{print $1}' | grep -v 'none'
            文件系統(tǒng)
            /dev/sda2
            /dev/sda1


            1)在/tmp中查找所有的*.h,并在這些文件中查找“SYSCALL_VECTOR",最后打印出所有包含"SYSCALL_VECTOR"的文件名 A) find /tmp -name "*.h" | xargs -n50 grep SYSCALL_VECTOR
            B) grep SYSCALL_VECTOR /tmp/*.h | cut -d':' -f1| uniq > filename
            C) find /tmp -name "*.h" -exec grep "SYSCALL_VECTOR" {} \; -print
            2)find / -name filename -exec rm -rf {} \;
            find / -name filename -ok rm -rf {} \;
            3)比如要查找磁盤(pán)中大于3M的文件:
            find . -size +3000k -exec ls -ld {} ;
            4)將find出來(lái)的東西拷到另一個(gè)地方
            find *.c -exec cp '{}' /tmp ';' 如果有特殊文件,可以用cpio,也可以用這樣的語(yǔ)法:
            find dir -name filename -print | cpio -pdv newdir
            6)查找2004-11-30 16:36:37時(shí)更改過(guò)的文件
            # A=`find ./ -name "*php"` | ls -l --full-time $A 2>/dev/null | grep "2004-11-30 16:36:37
            二、linux下find命令的用法
            1. 基本用法:
            find / -name 文件名 find ver1.d ver2.d -name '*.c' -print 查找ver1.d,ver2.d *.c文件并打印 find . -type d -print 從當(dāng)前目錄查找,僅查找目錄,找到后,打印路徑名。可用于打印目錄結(jié)構(gòu)。
            2. 無(wú)錯(cuò)誤查找:
            find / -name access_log 2 >/dev/null
            3. 按尺寸查找:
            find / -size 1500c (查找1,500字節(jié)大小的文件,c表示字節(jié))
            find / -size +1500c (查找大于1,500字節(jié)大小的文件,+表示大于)
            find / -size +1500c (查找小于1,500字節(jié)大小的文件,-表示小于)
            4. 按時(shí)間:
            find / -amin n 最后n分鐘
            find / -atime n 最后n天
            find / -cmin n 最后n分鐘改變狀態(tài)
            find / -ctime n 最后n天改變狀態(tài)
            5. 其它:
            find / -empty 空白文件、空白文件夾、沒(méi)有子目錄的文件夾
            find / -false 查找系統(tǒng)中總是錯(cuò)誤的文件
            find / -fstype type 找存在于指定文件系統(tǒng)的文件,如type為ext2
            find / -gid n 組id為n的文件
            find / -group gname 組名為gname的文件
            find / -depth n 在某層指定目錄中優(yōu)先查找文件內(nèi)容
            find / -maxdepth levels 在某個(gè)層次目錄中按遞減方式查找
            6. 邏輯
            -and 條件與 -or 條件或
            7. 查找字符串
            find . -name '*.html' -exec grep 'mailto:'{}  回復(fù)  更多評(píng)論
              
            # re: Linux中find常見(jiàn)用法示例 2016-06-26 18:38 聶文龍
            find . -name "*.*" -type f ! -name "*.jpg"| xargs grep "function xxxxxx"  回復(fù)  更多評(píng)論
              
            # re: Linux中find常見(jiàn)用法示例 2016-07-02 11:01 聶文龍
            find . -regex '.*\.php\|.*\.html' | xargs grep 折扣價(jià)

            find . -name "*.*" -type f ! -name "*.htm" -type f ! -name "*.jpg" | xargs grep 折扣價(jià)  回復(fù)  更多評(píng)論
              

            只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            久久精品一区二区三区AV| 亚洲人成网站999久久久综合| 嫩草影院久久99| 久久精品国产日本波多野结衣| 777久久精品一区二区三区无码| 久久精品国产亚洲av麻豆色欲| 久久婷婷五月综合成人D啪| 看全色黄大色大片免费久久久| 久久精品一区二区国产| 996久久国产精品线观看| 亚洲va久久久噜噜噜久久| 久久丫忘忧草产品| 午夜视频久久久久一区| 日日狠狠久久偷偷色综合96蜜桃| 久久久久国产视频电影| 久久久精品人妻无码专区不卡| 国产精品成人无码久久久久久 | 中文字幕一区二区三区久久网站| 久久青青草原亚洲av无码app| 久久久久久亚洲Av无码精品专口| 久久精品国产99久久无毒不卡| 久久婷婷五月综合色奶水99啪| 九九精品99久久久香蕉| 99久久无码一区人妻a黑| 久久久久久久尹人综合网亚洲| 国产AV影片久久久久久| 久久久久一本毛久久久| 麻豆久久久9性大片| 无遮挡粉嫩小泬久久久久久久| www久久久天天com| 久久国产亚洲精品麻豆| 久久se精品一区精品二区国产| 尹人香蕉久久99天天拍| 日产精品久久久久久久| 久久免费国产精品一区二区| 久久丝袜精品中文字幕| 婷婷五月深深久久精品| 亚洲一本综合久久| 日韩一区二区三区视频久久| 一本色道久久HEZYO无码| 久久成人精品视频|