21.linux文件的查找

    locate 非實時查找全系統的文件,依靠一個數據庫,非精確的查找

<span style="font-family:Courier New;font-size:14px;">[root@localhost bin]# locate passwd
/etc/passwd
/etc/passwd-
/etc/passwd.OLD
/etc/pam.d/passwd
/etc/security/opasswd
/lib/security/pam_passwdqc.so
/lib/security/pam_unix_passwd.so
/usr/bin/RSA_SecurID_getpasswd</span>
    有時候剛剛創建過文件,由於數據庫還沒有更新,需要我們手動更新
<span style="font-family:Courier New;font-size:14px;">[root@localhost bin]# updatedb</span>
    find實時查找,精確速度慢,遍歷指定的目錄

        格式:find 查找的路徑 查找的標準 查找後的處理

        查找的路徑 默認爲當前的目錄

        查找的標準 默認爲當前路徑下的所有文件

        查找後的處理 默認爲打印

       

        -name FILENAME 對文件名做精確的匹配

<span style="font-family:Courier New;font-size:14px;">[root@localhost bin]# find /etc/ -name "passwd"
/etc/pam.d/passwd
/etc/passwd</span>
         文件通配符

             * 任意字符任意長度

             ? 單個任意字符

             [] 集合中的一個

         -iname 不區分大小寫匹配

         -regex pattern 基於正則表達式進行文件名匹配

         -user USERNAME 基於用戶名進行查找

<span style="font-family:Courier New;font-size:14px;">[root@localhost xin]# find ./ -user "xin"
./
./.bashrc
./.bash_profile
./.bash_logout
./.mozilla
./.mozilla/extensions
./.mozilla/plugins</span></span><pre name="code" class="plain">


         -group GROUP 基於用戶組進行查找

         -uid

         -gid

         -nouser 沒有用戶的文件

         -nogroup 沒有用戶組的文件


         -type 格局文件類型查找


         -size 根據文件的大小

              nk

              nM

              nG

         組合條件

             -o 或

             -a 與

             -not 非

[root@localhost ~]# find /tmp -nouser -a -type d
[root@localhost ~]# find /tmp -not -type d
/tmp/.font-unix/fs7100
/tmp/orbit-root/linc-24d7-0-12486249b9468
/tmp/orbit-root/linc-24d7-0-1950f57c22c71
        

         -mtime 天

         -ctime

         -atime

             [+-]n

[root@localhost ~]# find /tmp -atime +7
/tmp/vmware-config0/99-vmware-scsi-udev.rules
/tmp/mapping-root
/tmp/keyring-xD2dOV/socket
/tmp/ks-script-JxlfUE.log
         -perm MODE 根據權限來查找

               -MODE 每一位權限都被包含

               /MODE 有任何一位符合即可 

[root@localhost tmp]# find -perm 644
[root@localhost tmp]# find -perm -644
[root@localhost tmp]# find -perm /644
         處理動作

              -print 默認顯示

              -ls 類似 ls -l

[root@localhost tmp]# find -perm /644 -ls
5832705    8 drwxrwxrwt  13 root     root         4096 Jan 17 04:27 .

            
發佈了75 篇原創文章 · 獲贊 3 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章