linux檔案尋找(find,locate)

來源:互聯網
上載者:User

標籤:資料   檔案尋找   linux   blocks   att   此刻   []   chmod   atime   

檔案尋找:locate:      非即時,模糊比對,尋找是根據全系統檔案資料庫進行的;# updatedb, 手動組建檔案資料庫速度快 find:      即時      精確      支援眾多尋找標準      遍曆指定目錄中的所有檔案完成尋找,速度慢;      find 尋找路徑 尋找標準 尋找到以後的處理運作尋找路徑:預設為目前的目錄尋找標準:預設為指定路徑下的所有檔案處理運作:預設為顯示 匹配標準:      -name ‘FILENAME‘:對檔案名稱作精確匹配            檔案名稱通配:                  *:任意長度的任一字元                  ?                  []      -iname ‘FILENAME‘: 檔案名稱匹配時不區分大小寫      -regex PATTERN:基於Regex進行檔案名稱匹配            -user USERNAME: 根據屬主尋找      -group GROUPNAME: 根據屬組尋找            -uid UID: 根據UID尋找      -gid GID: 根據GID尋找            -nouser:尋找沒有屬主的檔案      -nogroup: 尋找沒有屬組的檔案            -type            f: 普通檔案            d            c            b            l            p            s            -size [+|-]            #k            #M            #G/tmp目錄,不是目錄,並且還不能通訊端類型的檔案/tmp/test目錄下,屬主不是user1,也不是user2的檔案;       -mtime  修改時間      -ctime        -atime  訪問時間            [+|-]#      -mmin      -cmin      -amin            [+|-]#解釋-atime 5 表示距離此刻剛好五天的    -atime +5  表示距離此刻大於五天都沒訪問過的    -atime -5  表示距離此刻五天之內有訪問過的                  -perm MODE:精確匹配            /MODE: 任意一位匹配即滿足條件            -MODE: 檔案許可權能完全包含此MODE時才符合條件                        -644            644: rw-r--r--            755: rwxr-xr-x            750: rwxr-x---      find ./ -perl -001運作:      -print: 顯示      -ls:類似ls -l的形式顯示每一個檔案的詳細      -ok COMMAND {} \; 每一次操作都需要使用者確認      -exec COMMAND {} \;運作例子:{}表示匹配到的內容[[email protected] scripts]# find . -amin -30 -exec chmod u-w {} \;[[email protected] scripts]# lltotal 20-rwxr-xr-x 1 root root 280 Jan  7 11:55 1.sh-r--r--r-- 1 root root   0 Jan  8 08:03 a-rwxr-xr-x 1 root root 168 Jan  7 11:13 jiou_sum.sh-rwxr-xr-x 1 root root 261 Jan  8 03:30 sum.sh-rwxr-xr-x 1 root root 222 Jan  7 17:42 user01.sh-rwxr-xr-x 1 root root 489 Jan  7 18:24 user.sh[[email protected] scripts]# find . -amin -30 -ok chmod u+w {} \;< chmod ... . > ? y< chmod ... ./a > ? y[[email protected] scripts]# lltotal 20-rwxr-xr-x 1 root root 280 Jan  7 11:55 1.sh-rw-r--r-- 1 root root   0 Jan  8 08:03 a-rwxr-xr-x 1 root root 168 Jan  7 11:13 jiou_sum.sh-rwxr-xr-x 1 root root 261 Jan  8 03:30 sum.sh-rwxr-xr-x 1 root root 222 Jan  7 17:42 user01.sh-rwxr-xr-x 1 root root 489 Jan  7 18:24 user.sh改檔案名稱:[[email protected] scripts]# find  -perm 644./a[[email protected] scripts]# find  -perm 644 -exec mv {} {}.new \;[[email protected] scripts]# lltotal 20-rwxr-xr-x 1 root root 280 Jan  7 11:55 1.sh-rw-r--r-- 1 root root   0 Jan  8 08:03 a.new-rwxr-xr-x 1 root root 168 Jan  7 11:13 jiou_sum.sh-rwxr-xr-x 1 root root 261 Jan  8 03:30 sum.sh-rwxr-xr-x 1 root root 222 Jan  7 17:42 user01.sh-rwxr-xr-x 1 root root 489 Jan  7 18:24 user.sh 再一個例子:將大於1M的檔案找出並追加到/tmp/etc.largesfile [[email protected] scripts]# find /etc/ -size +1M/etc/pki/tls/certs/ca-bundle.trust.crt/etc/selinux/targeted/policy/policy.24/etc/selinux/targeted/modules/active/policy.kern[[email protected] scripts]# find /etc/ -size +1M |xargs >> /tmp/etc.largesfile[[email protected] scripts]# cat /tmp/etc.largesfile/etc/pki/tls/certs/ca-bundle.trust.crt /etc/selinux/targeted/policy/policy.24 /etc/selinux/targeted/modules/active/policy.kern[[email protected] scripts]# find /etc/ -size +1M -exec echo {} >> /tmp/etc.largesfile \;                    [[email protected] scripts]# cat /tmp/etc.largesfile/etc/pki/tls/certs/ca-bundle.trust.crt /etc/selinux/targeted/policy/policy.24 /etc/selinux/targeted/modules/active/policy.kern/etc/pki/tls/certs/ca-bundle.trust.crt/etc/selinux/targeted/policy/policy.24/etc/selinux/targeted/modules/active/policy.kern##############################################################[[email protected] scripts]# stat a  File: `a‘  Size: 0               Blocks: 0          IO Block: 4096   regular empty fileDevice: fd00h/64768d    Inode: 131939      Links: 1Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)Access: 2017-01-08 08:03:12.990058301 +0800Modify: 2017-01-08 08:03:07.122074618 +0800Change: 2017-01-08 08:03:12.990058301 +0800 [[email protected] scripts]# find -amin -5 -ls143757    4 drwxr-xr-x   2 root     root         4096 Jan  8 08:03 .131939    0 -rw-r--r--   1 root     root            0 Jan  8 08:03 ./a[[email protected] scripts]# find -atime -5 -ls143757    4 drwxr-xr-x   2 root     root         4096 Jan  8 08:03 .131939    0 -rw-r--r--   1 root     root            0 Jan  8 08:03 ./a140442    4 -rwxr-xr-x   1 root     root          168 Jan  7 11:13 ./jiou_sum.sh140514    4 -rwxr-xr-x   1 root     root          222 Jan  7 17:42 ./user01.sh140515    4 -rwxr-xr-x   1 root     root          261 Jan  8 03:30 ./sum.sh140448    4 -rwxr-xr-x   1 root     root          280 Jan  7 11:55 ./1.sh140513    4 -rwxr-xr-x   1 root     root          489 Jan  7 18:24 ./user.sh

linux檔案尋找(find,locate)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.