linux find 命令


Usage

find <path> <conditions> <actions>

Conditions

-name "*.c"
-type f            # File
-type d            # Directory
-type l            # Symlink
-depth 2           # At least 3 levels deep
-regex PATTERN
-newer   file.txt
-newerm  file.txt        # modified newer than file.txt
-newerX  file.txt        # [c]hange, [m]odified, [B]create
-newerXt "1 hour ago"    # [t]imestamp
-path  "*/node_modules" -prune  # 忽略任意node_modules文件夾

Condition flow

查找當前文件夾且忽略node_modules文件夾下的,所有后綴為js的文件,-o是短路語句

find . -path  "*/node_modules" -prune -o -type f -name "*.js" -print

Actions

-exec rm {} \; # 花括號代表前面find查找出來的文件名,反斜杠分號代表語句結束
-print # 打印
-delete

Examples

find . -name '*.jpg'
find . -name '*.jpg' -exec rm {} \;
find . -newerBt "24 hours ago"


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM