find命令用于查找文件 find [起始目录] [搜索条件] [操作]
find ~ -name:在自己当前HOME根目录的查找以.ssh结尾的文件名 (~表示HOME根目录)
wxc@wxc-Lenovo-G40-30:/$ sudo find ~ -name "*.ssh" -print
/home/wxc/.ssh
find . -name "[a-f]*" -print:查找当前目录及其子目录下以小写a-f开头的文件
wxc@wxc-Lenovo-G40-30:~/learngit/cwsroot/cws-02$ find . -name "[a-f]*" -print
./cws02.iml
./src/main/java/com
./src/main/webapp/WEB-INF/applicationContext.xml
wxc@wxc-Lenovo-G40-30:~/learngit/cwsroot/cws-02$ find . -name "[a-k]*" -print
./cws02.iml
./src/main/java
./src/main/java/com
./src/main/webapp/WEB-INF/applicationContext.xml
./src/main/webapp/index.jsp
find . - name "[a-z]*[a-m].xml" -print:表示在当前目录下查找以小写a-z开头 以a-m结尾的 后缀名为xml的文件
wxc@wxc-Lenovo-G40-30:~/learngit/cwsroot/cws-02$ find . -name "[a-z]*[a-m].xml" -print
./src/main/webapp/WEB-INF/log4j.xml
./src/main/webapp/WEB-INF/web.xml
./pom.xml
find / - name "*" -print:表示在根目录下查找所有文件 由于考虑到负荷问题,就不执行了
按照文件权限模式 -perm查找文件目录
find . -perm 权限号
wxc@wxc-Lenovo-G40-30:~$ find . -perm 755
.
./音乐
./文档
./模板
./视频
./.vim
./桌面
find: `./.cache/dconf': 权限不够
./.cache/fontconfig
./.cache/uksc/xapiandb
./.cache/mozilla/firefox/ojey6it2.default/safebrowsing
./.cache/mozilla/firefox/ojey6it2.default/safebrowsing/google4
./.cache/mozilla/firefox/ojey6it2.default/cache2/doomed
./.cache/thunderbird/4n8m0je4.default/safebrowsing
./.cache/thunderbird/4n8m0je4.default/safebrowsing/google
find . -size +100k -print :在当前目录下大于100k的文件
wxc@wxc-Lenovo-G40-30:~/learngit/cwsroot$ find . -size +100k -print
./cwx-01/target/cwx-01-1.0-SNAPSHOT.war
./cwx-01/target/tomcat/conf/web.xml
./cwx-01/target/cwx-01-1.0-SNAPSHOT/WEB-INF/lib/spring-beans-5.0.5.RELEASE.jar
./cwx-01/target/cwx-01-1.0-SNAPSHOT/WEB-INF/lib/spring-expression-5.0.5.RELEASE.jar
./cwx-01/target/cwx-01-1.0-SNAPSHOT/WEB-INF/lib/spring-context-5.0.5.RELEASE.jar
./cwx-01/target/cwx-01-1.0-SNAPSHOT/WEB-INF/lib/servlet-api-2.5.jar
./cwx-01/target/cwx-01-1.0-SNAPSHOT/WEB-INF/lib/mail-1.4.3.jar
./cwx-01/target/cwx-01-1.0-SNAPSHOT/WEB-INF/lib/spring-aop-5.0.5.RELEASE.jar
./cwx-01/target/cwx-01-1.0-SNAPSHOT/WEB-INF/lib/spring-core-5.0.5.RELEASE.jar
./cwx-01/target/cwx-01-1.0-SNAPSHOT/WEB-INF/lib/mysql-connector-java-6.0.6.jar
./cwx-01/target/cwx-01-1.0-SNAPSHOT/WEB-INF/lib/spring-context-support-4.0.2.RELEASE.jar
使用find目录查找时,避开某一个目录 -prume :忽略某一个目录
find cwsroot -path "cwsroot/cwx-01" -prune -o -print
wxc@wxc-Lenovo-G40-30:~/learngit$ find cwsroot -path "cws/cwx-01" -prune -o -print
cwsroot
cwsroot/cws-02
cwsroot/cws-02/cws02.iml
cwsroot/cws-02/src
cwsroot/cws-02/src/test
cwsroot/cws-02/src/test/resources
cwsroot/cws-02/src/main
cwsroot/cws-02/src/main/java
cwsroot/cws-02/src/main/java/com
cwsroot/cws-02/src/main/java/com/maven
cwsroot/cws-02/src/main/java/com/maven/Servlet
cwsroot/cws-02/src/main/java/com/maven/Servlet/UserServlet.java
cwsroot/cws-02/src/main/resources
cwsroot/cws-02/src/main/webapp
cwsroot/cws-02/src/main/webapp/WEB-INF
cwsroot/cws-02/src/main/webapp/WEB-INF/log4j.xml
避开多个文件夹 \表示引用 ()表示表达式结合
find cwsroot \( -path cwsroot/cwx-01 -o -path cwsroot/cws-02 \) -prune -o -print
wxc@wxc-Lenovo-G40-30:~/learngit$ find cwsroot \( -path cwsroot/cwx-01 -o -path cwsroot/cws-02 \) -prune -o -print
cwsroot
cwsroot/.idea
cwsroot/.idea/workspace.xml
cwsroot/.idea/compiler.xml
cwsroot/.idea/encodings.xml
cwsroot/.idea/misc.xml
cwsroot/.attach_pid18810
cwsroot/cwsroot.iml
cwsroot/pom.xml
-atime显示当前目录不到5天前访问的文件名
find . -atime -5 -print
wxc@wxc-Lenovo-G40-30:~/learngit/cwsroot$ find . -atime -5 -print
.
./cws-02
./cws-02/cws02.iml
./cws-02/src
./cws-02/src/test
./cws-02/src/test/resources
./cws-02/src/main
./cws-02/src/main/java
./cws-02/src/main/java/com
./cws-02/src/main/java/com/maven
./cws-02/src/main/java/com/maven/Servlet
./cws-02/src/main/java/com/maven/Servlet/UserServlet.java
./cws-02/src/main/resources
./cws-02/src/main/webapp
./cws-02/src/main/webapp/WEB-INF
./cws-02/src/main/webapp/WEB-INF/log4j.xml
./cws-02/src/main/webapp/WEB-INF/applicationContext.xml
./cws-02/src/main/webapp/WEB-INF/web.xml
./cws-02/src/main/webapp/index.jsp
更精确的查找某一文件,在 -o后加上 -name “×××”
wxc@wxc-Lenovo-G40-30:~/learngit$ find cwsroot \( -path cwsroot/cwx-01 -o -path cwsroot/cws-02 \) -prune -o -name "*.xml" -print
cwsroot/.idea/workspace.xml
cwsroot/.idea/compiler.xml
cwsroot/.idea/encodings.xml
cwsroot/.idea/misc.xml
cwsroot/pom.xml
查找更改时间比pom.xml新,比cwws-02/pom.xml旧的文件
find -newer pom.xml ! -newer cws-02/pom.xml
wxc@wxc-Lenovo-G40-30:~/learngit/cwsroot$ find -newer pom.xml ! -newer cws-02/pom.xml
./cws-02/pom.xml
./cwx-01/src/main/java
./cwx-01/src/main/java/UserServlet.java
查找更改时间比 XXX新的文件
find -newer xxx -print
wxc@wxc-Lenovo-G40-30:~/下载$ find -newer BaiduExporter-master.pem -print
.
./jar包
./jar包/tomcat-servlet-api-7.0.30.jar.zip
./jar包/tomcat-servlet-api-7.0.30-sources.jar.zip
查找指定文件夹下所有的目录
find xxx -type d -print
wxc@wxc-Lenovo-G40-30:/$ find /home/wxc/learngit/cwsroot/cwx-01 -type d -print
/home/wxc/learngit/cwsroot/cwx-01
/home/wxc/learngit/cwsroot/cwx-01/target
/home/wxc/learngit/cwsroot/cwx-01/target/tomcat
/home/wxc/learngit/cwsroot/cwx-01/target/tomcat/conf
/home/wxc/learngit/cwsroot/cwx-01/target/tomcat/webapps
/home/wxc/learngit/cwsroot/cwx-01/target/tomcat/work
/home/wxc/learngit/cwsroot/cwx-01/target/tomcat/work/Tomcat
/home/wxc/learngit/cwsroot/cwx-01/target/tomcat/work/Tomcat/localhost
/home/wxc/learngit/cwsroot/cwx-01/target/tomcat/work/Tomcat/localhost/cwx01_war_
/home/wxc/learngit/cwsroot/cwx-01/target/tomcat/logs
/home/wxc/learngit/cwsroot/cwx-01/target/apache-tomcat-maven-plugin
/home/wxc/learngit/cwsroot/cwx-01/target/classes
/home/wxc/learngit/cwsroot/cwx-01/target/generated-sources
/home/wxc/learngit/cwsroot/cwx-01/target/generated-sources/annotations
/home/wxc/learngit/cwsroot/cwx-01/target/maven-status