歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> 學習Linux >> find命令基本使用一覽,find命令使用一覽

find命令基本使用一覽,find命令使用一覽

日期:2017/3/6 9:30:23   编辑:學習Linux

find命令基本使用一覽,find命令使用一覽


find命令基本使用一覽,find命令使用一覽


find命令相對於locate這種非實時查找的搜索命令,大大增加了我們搜索的便捷度以及准確性;並且能夠方便的幫助我們對大文件、特定類型的文件查找與刪除,特別是有超多小碎文件的時候,更是方便至極.... 根據屬主 屬組查找
   -user username:查找屬主是xx的文件
   -group group:查找屬組的xx文件
   -uid useruid:查找uid號的文件
   -gid groupid:查找gid號的文件
   -nouser:查找沒有屬主的文件,即文件存在但是 user已被刪除
   -nogroup:查找沒有屬組的文件
根據文件類型查找
    -type f:普通文件
   -type d:目錄文件
   -type l:符號鏈接文件
   -type s:套接字文件
   -type b:塊設備文件
   -type c:字符設備文件
   -type p:管道文件
根據大小查找
    -size +10M :大於10m的文件
    -size +10k:大於10k的文件
    -size +1G:大於1G的文件
    -size -1G:小於文件的文件
根據時間查找
    一天為單位
        -atime :訪問時間
        -mtime :修改時間
        -ctime :改變時間
   以分鐘為單位:
        -amin: 訪問時間
-mmin:修改時間
-cmin:改變時間
根據權限查找
    -perm +mode:
    -perm +600:屬主屬組其他權限 只要有一個匹配就當成功;600代表三個對象,6屬主 CentOS7上 使用 /600
    -perm -600:每個對象都必須同時擁有其指定的權限,三個對象同時成立 如:-003表示其他用戶必須有寫與執行權限
組合條件查找
   -a  :與
   -o  :或
   -not:非
   !  :非
處理動作
    -print:打印到屏幕
    -ls:查找到的文件 進行 ls
    -delete:刪除查找到的文件
    -ok command {}\; 對查找的文件執行由command指定的命令,交互式
    -exec command {}\;同上,非交互式
    {}:代表前面find找到的 文件名稱本身
    例如:
    find ./ -type f -exec cp {} {}.bak \; 將查找到的文件都復制出一個.bak文件
find查找後的動作傳遞模式 默認:查找到指定類型的文件時進行一次性傳遞 xargs:xargs命令即讓find查找的傳遞模式為 查找一個傳遞一個到動作上,刪除較多碎文件很好用,例如:find -type f | xargs command;相關示例介紹:
查找/home/test目錄下的符號*.txt的文件
find /home/test -name "*.txt" -print
查找權限是755的
find /home/test -perm 755 -print
查找屬主是test的
find /home/test -user test -print
查找數組是test的
find /home/test -group test -print
查找更改時間小於5天的
find /home/test -mtime -5 -print
查找更改時間大於3天的
find /home/test -mtime +3 -print
查找所有目錄
find /home/test -type d -print
查找除了目錄的所有文件
find /home/test ! -type d -print
查找文件
find /home/test -type f -print
查找符號鏈接文件
find /home/test -type l -pint
不包括/home/test/test/目錄下的test.sh
find /home/test -name "test.sh" -prune /home/test/test -print
刪除test.sh文件
find /home/test -name "test.sh" -type f -exec rm {} \;
顯示以test開頭的文件
find /home/test -name "*test*" -type f -exec more {} \;

http://xxxxxx/Linuxjc/1142207.html TechArticle

Copyright © Linux教程網 All Rights Reserved