bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~$ find -help 用法: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression] 默认路径为当前目录;默认表达式为 -print 表达式可能由下列成份组成:操作符、选项、测试表达式以及动作: 操作符 (优先级递减;未做任何指定时默认使用 -and): ( EXPR ) ! EXPR -not EXPR EXPR1 -a EXPR2 EXPR1 -and EXPR2 EXPR1 -o EXPR2 EXPR1 -or EXPR2 EXPR1 , EXPR2 位置选项 (总是真): -daystart -follow -regextype 普通选项 (总是真,在其它表达式前指定): -depth --help -maxdepth LEVELS -mindepth LEVELS -mount -noleaf --version -xdev -ignore_readdir_race -noignore_readdir_race 测试(N可以是 +N 或-N 或 N):-amin N -anewer FILE -atime N -cmin -cnewer 文件 -ctime N -empty -false -fstype 类型 -gid N -group 名称 -ilname 匹配模式 -iname 匹配模式 -inum N -ipath 匹配模式 -iregex 匹配模式 -links N -lname 匹配模式 -mmin N -mtime N -name 匹配模式 -newer 文件 -nouser -nogroup -path 匹配模式 -perm [+-]访问模式 -regex 匹配模式 -readable -writable -executable -wholename PATTERN -size N[bcwkMG] -true -type [bcdpflsD] -uid N -used N -user NAME -xtype [bcdpfls] 动作: -delete -print0 -printf FORMAT -fprintf FILE FORMAT -print -fprint0 FILE -fprint FILE -ls -fls FILE -prune -quit -exec COMMAND ; -exec COMMAND {} + -ok COMMAND ; -execdir COMMAND ; -execdir COMMAND {} + -okdir COMMAND ;
bixiaopeng@bixiaopengtekiMacBook-Pro ~$ find . -name sed.txt ./sed.txt
bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ find . perm 755 -print . ./dir1 ./dir1/cpf1.txt ./dir1/cpf12.txt
bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ ls -al total 0 drwxr-xr-x 8 bixiaopeng staff 272 Sep 18 17:00 . drwxr-xr-x@ 7 bixiaopeng staff 238 Sep 18 15:43 .. drwxr-xr-x 7 bixiaopeng staff 238 Sep 18 17:27 dir1 drwxr-xr-x 5 bixiaopeng staff 170 Sep 18 16:50 dir11 drwxr-xr-x 7 bixiaopeng staff 238 Sep 18 17:31 dir2 drwxr-xr-x 5 bixiaopeng staff 170 Sep 18 16:53 dir3 -rw-r--r-- 1 bixiaopeng staff 0 Sep 18 16:15 f2.txt -rw-r--r-- 1 bixiaopeng staff 0 Sep 18 17:00 f3.txt bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ find . -path "./dir3" -prune -o -print . ./dir1 ./dir1/cpf1.txt ./dir1/cpf12.txt ./dir1/ddddir ./dir1/f1.txt ./dir1/f2.txt ./dir11 ./dir11/cpf1.txt ./dir11/cpf12.txt ./dir11/f1.txt ./dir2 ./dir2/cpf1.txt ./dir2/cpf12.txt ./dir2/ddddir ./dir2/f1.txt ./dir2/f2.txt ./f2.txt ./f3.txt
bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ find ~ -user bixiaopeng -print /Users/bixiaopeng/source-code/workshop/Wireless-Test-Workshop/wtc/web/report/src/main/webapp/WEB-INF/web.xml /Users/bixiaopeng/testfun1.sh /Users/bixiaopeng/testfun2.sh /Users/bixiaopeng/testfunc.sh /Users/bixiaopeng/testgetopts.sh …...
bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ find . -group staff -print . ./dir1 ./dir1/cpf1.txt ./dir1/cpf12.txt ./dir1/ddddir ./dir1/f1.txt ….
bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ find . -mtime -1 -print . ./dir1 ./dir1/cpf1.txt ./dir1/cpf12.txt ./dir1/ddddir ./dir1/f1.txt ./dir1/f2.txt ./dir11 ...
bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ find . -type d -print . ./dir1 ./dir1/ddddir ./dir11 ./dir2 ./dir2/ddddir ./dir3 ./dir3/dir1#例子:在当前目录下查找除目录以外的所有文件
bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ find . ! -type d -print ./dir1/cpf1.txt ./dir1/cpf12.txt ./dir1/f1.txt ./dir1/f2.txt ./dir11/cpf1.txt ./dir11/cpf12.txt ./dir11/f1.txt ./dir2/cpf1.txt ./dir2/cpf12.txt ./dir2/f1.txt ./dir2/f2.txt ./dir3/cpf1.txt ./dir3/cpf12.txt ./dir3/dir1/cpf1.txt ./dir3/dir1/cpf12.txt ./dir3/dir1/f1.txt ./f2.txt ./f3.txt#例子:在当前目录下查找其它文件类型
bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ find . -type l -print bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ find . -type c -print bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ find . -type p -print bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ find . -type f -print ./dir1/cpf1.txt ./dir1/cpf12.txt ./dir1/f1.txt ./dir1/f2.txt ./dir11/cpf1.txt ./dir11/cpf12.txt ./dir11/f1.txt ./dir2/cpf1.txt ./dir2/cpf12.txt ./dir2/f1.txt ./dir2/f2.txt ./dir3/cpf1.txt ./dir3/cpf12.txt ./dir3/dir1/cpf1.txt ./dir3/dir1/cpf12.txt ./dir3/dir1/f1.txt ./f2.txt ./f3.txt
bixiaopeng@bixiaopengtekiMacBook-Pro Projects$ find . size 300c -print ./workspaces/婵???????/.settings ./workspaces/婵???????/.settings/org.eclipse.wst.server.core.prefs ./workspaces/婵???????/Tomcat v7.0 Server @ localhost-config ./workspaces/婵???????/Tomcat v7.0 Server @ localhost-config/catalina.policy ./workspaces/婵???????/Tomcat v7.0 Server @ localhost-config/catalina.properties ./workspaces/婵???????/Tomcat v7.0 Server @ localhost-config/context.xml ./workspaces/婵???????/Tomcat v7.0 Server @ localhost-config/server.xml ….
bixiaopeng@bixiaopengtekiMacBook-Pro Projects$ find . -name "*.zip" -mount -print ./workspaces/.metadata/.mylyn/.tasks.xml.zip ./workspaces/.metadata/.mylyn/repositories.xml.zip ./workspaces/.metadata/.mylyn/tasks.xml.zip ./workspaces/Android Context璇﹁В蹇?????????????.zip ./workspaces/WirelessQa-EditText.zip ./workspaces/WirelessQA-Location.zip ./workspaces/WirelessQA-Provider.zip
bixiaopeng@bixiaopengtekiMacBook-Pro androidshell$ find . -type f -exec ls -l {} \; -rw-r--r-- 1 bixiaopeng staff 24576 Jul 3 10:03 ./.1.log.swp -rw-r--r--@ 1 bixiaopeng staff 6148 Sep 18 15:43 ./.DS_Store -rw-r--r-- 1 bixiaopeng staff 683295 Jun 5 10:39 ./1.log -rw-r--r-- 1 bixiaopeng staff 171 Jun 5 10:32 ./logcat.sh -rw-r--r-- 1 bixiaopeng staff 120 Jun 4 17:34 ./monkey.sh
bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ find dir1 -type f -mtime -1 -exec rm {} \; bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ ls dir1 -al ls: -al: No such file or directory dir1: ddddir bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ ls -al dir1 total 0 drwxr-xr-x 3 bixiaopeng staff 102 Sep 19 13:30 . drwxr-xr-x 8 bixiaopeng staff 272 Sep 18 17:00 .. drwxr-xr-x 2 bixiaopeng staff 68 Sep 18 17:27 ddddir#例子:查找并删除dir1目录下更改时间小于一天的文件,删除时提示是否删除 y 删除 n不删除
# 使用-ok bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ find dir2 -name "*.txt" -mtime -1 -ok rm {} \; "rm dir2/cpf1.txt"? y "rm dir2/cpf12.txt"? y "rm dir2/f1.txt"? y "rm dir2/f2.txt"? n #使用-exec bixiaopeng@bixiaopengtekiMacBook-Pro testshell$ find dir2 -name "*.txt" -mtime -1 -exec rm -i {} \; remove dir2/f2.txt? n
bixiaopeng@bixiaopengtekiMacBook-Pro androidshell$ find . -type f -print |xargs file ./.1.log.swp: Vim swap file, version 7.3 ./.DS_Store: data ./1.log: UTF-8 Unicode text, with very long lines, with CRLF, CR line terminators ./logcat.sh: Bourne-Again shell script text executable ./monkey.sh: Bourne-Again shell script text executable
find / -name "core" -print | xargs echo "" >/tmp/core.log
find . -type f -print | xargs grep "wirelessqa"#在/bixiaopeng/apps目录下查找所有用户具有读、写和执行权限的文件,并收回相应的写权限:
$ find /bixiaopeng/apps -perm -7 -print | xargs chmod o -w#在当前目录下的所有普通文件中搜索ILOVEU这个词
$ find . -name *\ -type f -print | xargs grep "ILOVEU"#删除3天以前的所有东西 (find . -ctime +3 -exec rm -rf {} \;)
find ./ -mtime +3 -print|xargs rm -f –r#删除文件大小为零的文件
find . -size 0 | xargs rm -f &
本文参考众多网上资料,感谢乐于分享的人们。