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