“kuon珤雅俗共赏”通过精心收集,向本站投稿了5篇Linux常用命令(二十一)find之参数详解,以下是小编收集整理后的Linux常用命令(二十一)find之参数详解,欢迎阅读与借鉴。

篇1:Linux命令详解之find
作用
搜索文件
格式
find pathoption [-print] [-exec -ok command] {} \
默认搜索路径为当前路径
默认为-print,输出至标准输出
对于查找到的文件执行command命令
option为搜索条件
主要参数
-name filename
限制文件名
-user username
按文件属主来搜索
-group groupname
按组来查找
-mtime -n +n
按文件更改时间来查找,-n指n天以内,+n指n天以前
-atime -n +n
按文件访问时间来查
-ctime -n +n
按文件创建时间来查找
-nogroup
-nouser
-type
按文件类型搜索
-size n
-depth
查找子目录前先搜索完本目录
-follow
如果遇到符号链接文件,就跟踪链接所指文件
-prune
忽略某个文件
-o
逻辑或
-a
逻辑与
!
逻辑否
\( \)
转义,可括住搜索条件
示例
查找当前目录下的所有普通文件
find .-type f -exec ls -l {} \;
在home目录下查找更改时间在5日以前的文件并删除它们
find /home-mtime +5 -exec -ok rm {} \;
查询今天修改过的文件
find /-mtime -1 -exec ls -l {} \;
查询今天修改过的文件并提示是否显示
find /-mtime -1 -ok ls -l {} \;
查找小于100k的文件并显示
find /home-size -100k -exec ls -l {} \;
查找后缀为.txt的所有文件
find ~-name “*.txt” -ok ls -l {} \;
篇2:linux基础命令 find 命令的参数详解
find一些常用参数的一些常用实例和一些具体用法和注意事项,
1.使用name选项:
文件名选项是find命令最常用 的选项,要么单独使用该选项,要么和其他选项一起使用。 可以使用某种文件名模式来匹配文件,记住要用引号将文件名模式 引起来。 不管当前路径是什么,如果想要在自己的根目录$HOME中查找文件名符合*.log的文件,使用~作为 'pathname'参数,波浪号~代表了你的$HOME目录。
find ~ -name “*.log” -print
想要在当 前目录及子目录中查找所有的‘ *.log‘文件,可以用:
find . -name “*.log” -print
想要的当前 目录及子目录中查找文件名以一个大写字母开头的文件,可以用:
find . -name “[A-Z]*” -print
想 要在/etc目录中查找文件名以host开头的文件,可以用:
find /etc -name “host*” -print
想要查找 $HOME目录中的文件,可以用:
find ~ -name “*” -print 或find . -print
要想让系统高负荷运行, 就从根目录开始查找所有的文件。
find / -name “*” -print
如果想在当前目录查找文件名以一个个 小写字母开头,最后是4到9加上.log结束的文件:
命令:
find . -name “[a-z]*[4-9].log” - print
输出:
[root@localhost test]# ll
总计 316
-rw-r--r-- 1 root root 302108 11-13 06:03 log.log
-rw-r--r-- 1 root root 61 11-13 06:03 log.log
-rw-r--r-- 1 root root 0 11-13 06:03 log.log
-rw-r--r-- 1 root root 0 11-13 06:06 log.log
drwxr-xr-x 6 root root 4096 10-27 01:58 scf
drwxrwxr-x 2 root root 4096 11-13 06:08 test3
drwxrwxr-x 2 root root 4096 11-13 05:50 test4
[root@localhost test]# find . -name “[a-z]*[4-9].log” - print
./log2014.log
./log2015.log
./test4/log2014.log
[root@localhost test]#
2.用 perm选项:
按照文件权限模式用-perm选项,按文件权限模式来查找文件的话。最好使用八进制的权限表示法。
如 在当前目录下查找文件权限位为755的文件,即文件属主可以读、写、执行,其他用户可以读、执行的文件,可以用:
[root@localhost test]# find . -perm 755 - print
.
./scf
./scf/lib
./scf/service
./scf/service/deploy
./scf/service/dep loy/product
./scf/service/deploy/info
./scf/doc
./scf/bin
[root@localhost test]#
还有一种表达方法:在八进制数字前面要加一个横杠-,表示都匹配,如-007就相当于777,-005相当于555,
命令:
find . -perm -005
输出:
[root@localhost test]# ll
总计 316
-rw-r--r-- 1 root root 302108 11-13 06:03 log2012.log
-rw-r--r-- 1 root root 61 11-13 06:03 log2013.log
-rw-r--r-- 1 root root 0 11-13 06:03 log2014.log
-rw-r--r-- 1 root root 0 11-13 06:06 log2015.log
drwxr-xr-x 6 root root 4096 10-27 01:58 scf
drwxrwxr-x 2 root root 4096 11-13 06:08 test3
drwxrwxr-x 2 root root 4096 11-13 05:50 test4
[root@localhost test]# find . -perm - 005
.
./test4
./scf
./scf/lib
./scf/service
./scf/service/deploy
./scf /service/deploy/product
./scf/service/deploy/info
./scf/doc
./scf/bin
./test3
[root@localhost test]#
3.忽略某个目录:
如果在查找文件时希望忽略某个目录,因为你知道那个目录中没有 你所要查找的文件,那么可以使用-prune选项来指出需要忽略的目录。在使用-prune选项时要当心,因为如果你同时使用了- depth选项,那么-prune选项就会被find命令忽略。如果希望在test目录下查找文件,但不希望在test/test3目录下查找,可以 用:
命令:
find test -path “test/test3” -prune -o -print
输出:
[root@localhost soft]# find test -path “test/test3” -prune -o - print
test
test/log2014.log
test/log2015.log
test/test4
test/test4/log2014.log
test/test4/log2013.log
test/test4/log2012.log
test/scf
test/scf/lib
test/scf/service< /p>
test/scf/service/deploy
test/scf/service/deploy/product
test/scf/service/deploy/info
tes t/scf/doc
test/scf/bin
test/log2013.log
test/log2012.log
[root@localhost soft]#
4 .使用find查找文件的时候怎么避开某个文件目录:
实例1:在test 目录下查找不在test4子目录之内的所有文件
命令:
find test -path “test/test4” -prune -o -print
输出:
[root@localhost soft]# find test
test
test/log2014.log
test/log2015.log
test/test4
test/test4/log2014.log
< p>test/test4/log2013.log
test/test4/log2012.log
test/scf
test/scf/lib
test/scf/service
test/scf/service/deploy
test/scf/service/deploy/product
test/scf/service/deploy/info
test /scf/doc
test/scf/bin
test/log2013.log
test/log2012.log
test/test3
[root@localhost soft]# find test -path “test/test4” -prune -o - print
test
test/log2014.log
test/log2015.log
test/scf
test/scf/lib
test/scf/ service
test/scf/service/deploy
test/scf/service/deploy/product
test/scf/service/deploy/info
test/scf/doc
test/scf/bin
test/log2013.log
test/log2012.log
test/test3
[root@localhost soft]#
说明:
find [-path ..] [expression]
在路径列表的后面的是表达式
- path “test” -prune -o -print 是 -path “test” -a -prune -o -print 的简写表达式按顺序求值, -a 和 -o 都是短路求值,与 shell 的 && 和 || 类似如果
-path “test” 为真,则求值 -prune , - prune 返回真,与逻辑表达式为真;否则不求值 -prune,与逻辑表达式为假,
如果 -path “test” -a -prune 为假 ,则求值 -print ,-print返回真,或逻辑表达式为真;否则不求值 -print,或逻辑表达式为真。
这个表达式组合特例 可以用伪码写为:
if -path “test” then
-prune
else
实例2:避开多个 文件夹:
命令:
find test \( -path test/test4 -o -path test/test3 \) -prune -o -print
输出:
[root@localhost soft]# find test \( -path test/test4 -o -path test/test3 \) -prune -o -print
test
test/log2014.log
test/log2015.log
test/scf
test/scf/lib
test/scf/service
test/scf/service/deploy
test/scf/service/deploy/product
test/scf/service/deploy/info
test /scf/doc
test/scf/bin
test/log2013.log
test/log2012.log
[root@localhost soft]#
说 明:
圆括号表示表达式的结合。 \表示引用,即指示 shell 不对后面的字符作特殊解释,而留给 find 命令去解释其意义。
实例3:查找某一确定文件,-name等选项加在-o 之后
命令:
find test \(-path test/test4 -o -path test/test3 \) -prune -o -name “*.log” -print
输出:
[root@localhost soft]# find test \( -path test/test4 -o -path test/test3 \) -prune -o -name “*.log” -print
test/log2014.log
test/log2015.log
test/log2013.log
test/log2012.log
[root@localhost soft]#
5.使用user和nouser选项:
按文件属主查找文件:
实例1:在$HOME目录中查找文件属主为peida 的文件
命令:
find ~ -user peida -print
实例2:在/etc目录下查找文件属主为peida的文件:
命 令:
find /etc -user peida -print
说明:
实例3:为了查找属主帐户已经被删除的文件,可以使用- nouser选项。在/home目录下查找所有的这类文件
命令:
find /home -nouser -print
说明:
这样 就能够找到那些属主在/etc/passwd文件中没有有效帐户的文件。在使用-nouser选项时,不必给出用户名; find命令能够为你 完成相应的工作。
6.使用group和nogroup选项:
就像user和nouser选项一样,针对文件所属于的用户组, find 命令也具有同样的选项,为了在/apps目录下查找属于gem用户组的文件,可以用:
find /apps -group gem - print
要查找没有有效所属用户组的所有文件,可以使用nogroup选项。下面的find命令从文件系统的根目录处查找这样 的文件:
find / -nogroup-print
7.按照更改时间或访问时间等查找文件:
如果希望按照更改时间来查找 文件,可以使用mtime,atime或ctime选项。如果系统突然没有可用空间了,很有可能某一个文件的长度在此期间增长迅速,这时 就可以用mtime选项来查找这样的文件。
用减号-来限定更改时间在距今n日以内的文件,而用加号+来限定更改时间在距 今n日以前的文件。
希望在系统根目录下查找更改时间在5日以内的文件,可以用:
find / -mtime -5 - print
为了在/var/adm目录下查找更改时间在3日以前的文件,可以用:
find /var/adm -mtime +3 - print
8.查找比某个文件新或旧的文件:
如果希望查找更改时间比某个文件新但比另一个文件旧的所有文件,可 以使用-newer选项。
它的一般形式为:
newest_file_name ! oldest_file_name
其中,!是逻辑非符号。
实例1:查找更改时间比文件log2012.log新但比文件log.log旧的文件
命令:
find -newer log2012.log ! -newer log2017.log
输出:
[root@localhost test]# ll
总计 316
-rw-r--r-- 1 root root 302108 11-13 06:03 log2012.log
-rw-r--r-- 1 root root 61 11-13 06:03 log2013.log
-rw-r--r-- 1 root root 0 11-13 06:03 log2014.log
-rw-r--r-- 1 root root 0 11-13 06:06 log2015.log
-rw-r--r-- 1 root root 0 11-16 14:41 log.log
-rw-r--r-- 1 root root 0 11-16 14:43 log2017.log
drwxr-xr-x 6 root root 4096 10-27 01:58 scf
drwxrwxr-x 2 root root 4096 11-13 06:08 test3
drwxrwxr -x 2 root root 4096 11-13 05:50 test4
[root@localhost test]# find -newer log2012.log ! -newer log2017.log
.
./log2015.log
./log2017.log
./log2016.log
./test3
[root@localhost test]#
实例2:查找更改时间在比log2012.log文件新的文件
命令:
find . -newer log2012.log -print
输出:
[root@localhost test]# find -newer log2012.log
.
./log2015.log
./log2017.log
./log2016.log
./test3
[root@localhost test]#
9.使用type选项:
实例1:在/etc目录下查找所有的目录
命令:
find /etc -type d -print
实例2:在当前目录下查找除目录以外的所有类型的文件
命令:
find . ! -type d -print
实例3:在/etc目录下查找所有的符号链接文件
命令:
find /etc -type l -print
10.使 用size选项:
可以按照文件长度来查找文件,这里所指的文件长度既可以用块(block)来计量,也可以用字节来计量。 以字节计量文件长度的表达形式为N c;以块计量文件长度只用数字表示即可。
在按照文件长度查找文件时,一般使用这 种以字节表示的文件长度,在查看文件系统的大小,因为这时使用块来计量更容易转换。
实例1:在当前目录下查找文件 长度大于1 M字节的文件
命令:
find . -size +1000000c -print
实例2:在/home/apache目录下查找文件 长度恰好为100字节的文件:
命令:
find /home/apache -size 100c -print
实例3:在当前目录下查找长 度超过10块的文件(一块等于512字节)
命令:
find . -size +10 -print
11.使用depth选项:
在使用find命令时,可能希望先匹配所有的文件,再在子目录中查找。使用depth选项就可以使find命令这样做。这样做的一个 原因就是,当在使用find命令向磁带上备份文件系统时,希望首先备份所有的文件,其次再备份子目录中的文件。
实例1 :find命令从文件系统的根目录开始,查找一个名为CON.FILE的文件。
命令:
find / -name “CON.FILE” -depth -print
说明:
它将首先匹配所有的文件然后再进入子目录中查找
12.使 用mount选项:
在当前的文件系统中查找文件(不进入其他文件系统),可以使用find命令的mount选项。
实例1 :从当前目录开始查找位于本文件系统中文件名以XC结尾的文件
命令:
find . -name “*.XC” -mount -print
查看全套教程:www.bianceng.cn/OS/Linux/201301/35075.htm
篇3:Linux常用命令(二十一)find之参数详解
一.使用name选项:
文件名选项是find命令最常用的选项,要么单独使用该选项,要么和其他选项一起使用, 可以使用某种文件名模式来匹配文件,记住要用引号将文件名模式引起来。 不管当前路径是什么,如果想要在自己的根目录$HOME中查找文件名符合*.log的文件,使用~作为 ‘pathname‘参数,波浪号~代表了你的$HOME目录。
find ~ -name “*.log” -print
想要在当前目录及子目录中查找所有的‘ *.log‘文件,可以用: find . -name “*.log” -print
想要的当前目录及子目录中查找文件名以一个大写字母开头的文件,可以用: find . -name “[A-Z]*” -print
想要在/etc目录中查找文件名以host开头的文件,可以用: find /etc -name “host*” -print
想要查找$HOME目录中的文件,可以用: find ~ -name “*” -print 或find . -print
要想让系统高负荷运行,就从根目录开始查找所有的文件。 find / -name “*” -print
如果想在当前目录查找文件名以一个个小写字母开头,最后是4到9加上.log结束的文件:find . -name “[a-z]*[4-9].log” -print
二.使用perm选项:
按照文件权限模式用-perm选项,按文件权限模式来查找文件的话。最好使用八进制的权限表示法。
如在当前目录下查找文件权限位为755的文件,即文件属主可以读、写、执行,其他用户可以读、执行的文件,可以用:
还有一种表达方法:在八进制数字前面要加一个横杠-,表示都匹配,如-007就相当于777,-005相当于555,
命令:find . -perm -005
三.忽略某个目录-prune:
如果在查找文件时希望忽略某个目录,因为你知道那个目录中没有你所要查找的文件,那么可以使用-prune选项来指出需要忽略的目录。在使用-prune选项时要当心,因为如果你同时使用了-depth选项,那么-prune选项就会被find命令忽略。
实例1:如果希望在test目录下查找文件,但不希望在test/test3目录下查找,可以用:
命令:find test -path “test/test3” -prune -o -print
说明:
find [-path ..] [expression]
在路径列表的后面的是表达式
-path “test” -prune -o -print 是 -path “test” -a -prune -o -print 的简写表达式按顺序求值,
-a 和 -o 都是短路求值,与 shell 的 && 和 || 类似如果 -path “test” 为真,则求值 -prune , -prune 返回真,与逻辑表达式为真;否则不求值 -prune,与逻辑表达式为假。
如果 -path “test” -a -prune 为假,则求值 -print ,-print返回真,或逻辑表达式为真;否则不求值 -print,或逻辑表达式为真。
这个表达式组合特例可以用伪码写为:
if -path “test” then
-prune
else
实例2:避开多个文件夹:
命令:find test \( -path test/test4 -o -path test/test3 \) -prune -o -print
说明:圆括号表示表达式的结合。 \ 表示引用,即指示 shell 不对后面的字符作特殊解释,而留给 find 命令去解释其意义。
实例3:查找某一确定文件,-name等选项加在-o 之后
命令:find test \(-path test/test4 -o -path test/test3 \) -prune -o -name “*.log” -print
五.使用user和nouser选项:
按文件属主查找文件:
实例1:在$HOME目录中查找文件属主为peida的文件
命令:find ~ -user peida -print
实例2:在/etc目录下查找文件属主为peida的文件:
命令:find /etc -user peida -print
说明:实例3:为了查找属主帐户已经被删除的文件,可以使用-nouser选项。在/home目录下查找所有的这类文件
命令:find /home -nouser -print
说明:这样就能够找到那些属主在/etc/passwd文件中没有有效帐户的文件,
在使用-nouser选项时,不必给出用户名; find命令能够为你完成相应的工作。
六.使用group和nogroup选项:
就像user和nouser选项一样,针对文件所属于的用户组, find命令也具有同样的选项,为了在/apps目录下查找属于gem用户组的文件,可以用: find /apps -group gem -print
要查找没有有效所属用户组的所有文件,可以使用nogroup选项。下面的find命令从文件系统的根目录处查找这样的文件:
find / -nogroup-print
七.按照更改时间或访问时间等查找文件:
如果希望按照更改时间来查找文件,可以使用mtime,atime或ctime选项。如果系统突然没有可用空间了,很有可能某一个文件的长度在此期间增长迅速,这时就可以用mtime选项来查找这样的文件。
用减号-来限定更改时间在距今n日以内的文件,而用加号+来限定更改时间在距今n日以前的文件。
希望在系统根目录下查找更改时间在5日以内的文件,可以用:
find / -mtime -5 -print
为了在/var/adm目录下查找更改时间在3日以前的文件,可以用:
find /var/adm -mtime +3 -print
八.查找比某个文件新或旧的文件:
如果希望查找更改时间比某个文件新但比另一个文件旧的所有文件,可以使用-newer选项。
它的一般形式为: newest_file_name ! oldest_file_name 其中,!是逻辑非符号。
实例1:查找更改时间比文件log2012.log新但比文件log2017.log旧的文件
命令:find -newer log2012.log ! -newer log2017.log
实例2:查找更改时间在比log2012.log文件新的文件
命令:find . -newer log2012.log -print
九.使用type选项:
实例1:在/etc目录下查找所有的目录
命令:find /etc -type d -print
实例2:在当前目录下查找除目录以外的所有类型的文件
命令:find . ! -type d -print
实例3:在/etc目录下查找所有的符号链接文件
命令:find /etc -type l -print
十.使用size选项:
可以按照文件长度来查找文件,这里所指的文件长度既可以用块(block)来计量,也可以用字节来计量。以字节计量文件长度的表达形式为N c;以块计量文件长度只用数字表示即可。
在按照文件长度查找文件时,一般使用这种以字节表示的文件长度,在查看文件系统的大小,因为这时使用块来计量更容易转换。
实例1:在当前目录下查找文件长度大于1 M字节的文件
命令:find . -size +1000000c -print
实例2:在/home/apache目录下查找文件长度恰好为100字节的文件:
命令:find /home/apache -size 100c -print
实例3:在当前目录下查找长度超过10块的文件(一块等于512字节)
命令:find . -size +10 -print
十一.使用depth选项:
在使用find命令时,可能希望先匹配所有的文件,再在子目录中查找。使用depth选项就可以使find命令这样做。这样做的一个原因就是,当在使用find命令向磁盘上备份文件系统时,希望首先备份所有的文件,其次再备份子目录中的文件。
实例1:find命令从文件系统的根目录开始,查找一个名为CON.FILE的文件。
命令:find / -name “CON.FILE” -depth -print
说明:它将首先匹配所有的文件然后再进入子目录中查找
十二.使用mount选项:
在当前的文件系统中查找文件(不进入其他文件系统),可以使用find命令的mount选项。
实例1:从当前目录开始查找位于本文件系统中文件名以XC结尾的文件
命令:find . -name “*.XC” -mount -print
篇4:Linux curl命令参数详解
linux curl是通过url语法在命令行下上传或下载文件的工具软件,它支持http,https,ftp,ftps,telnet等多种协议,常被用来抓取网页和监控Web服务器状态,
1. linux curl抓取网页:
抓取百度:
curl www.baidu.com
如发现乱码,可以使用iconv转码:
curl if rame.ip138.com/ic.asp|iconv -fgb2312
iconv的用法请参阅:在Linux/Unix系统下用iconv命令处理文本文件中文乱码问题
2. Linux curl使用代理:
linux curl使用http代理抓取页面:
curl -x 111.95.243.36:80 if rame.ip138.com/ic.asp|iconv -fgb2312
curl -x 111.95.243.36:80 -U aiezu:password www.baidu.com
使用socks代理抓取页面:
curl --socks4 202.113.65.229:443 if rame.ip138.com/ic.asp|iconv -fgb2312
curl --socks5 202.113.65.229:443 if rame.ip138.com/ic.asp|iconv -fgb2312
代理服务器地址可以从爬虫代理上获取。
3. linux curl处理cookies
接收cookies:
curl -c /tmp/cookies www.baidu.com #cookies保存到/tmp/cookies文件
发送cookies:
curl -b “key1=val1;key2=val2;” www.baidu.com #发送cookies文本
curl -b /tmp/cookies www.baidu.com #从文件中读取cookies
4. linux curl发送数据:
linux curl get方式提交数据:
curl -G -d “name=value&name2=value2” www.baidu.com
linux curl post方式提交数据:
curl -d “name=value&name2=value2” www.baidu.com #post数据
curl -d a=b&c=d&txt@/tmp/txt www.baidu.com #post文件
以表单的方式上传文件:
curl -F file=@/tmp/me.txt www.aiezu.com
相当于设置form表单的method=“POST”和enctype=‘multipart/form-data‘两个属性,
5. linux curl http header处理:
设置http请求头信息:
curl -A “Mozilla/5.0 Firefox/21.0” www.baidu.com #设置http请求头User-Agent
curl -e “pachong.org/” www.baidu.com #设置http请求头Referer
curl -H “Connection:keep-alive User-Agent: Mozilla/5.0” www.aiezu.com
设置http响应头处理:
curl -I www.aiezu.com #仅仅返回header
curl -D /tmp/header www.aiezu.com #将http header保存到/tmp/header文件
6. linux curl认证:
curl -u aiezu:password www.aiezu.com #用户名密码认证
curl -E mycert.pem www.baidu.com #采用证书认证
7. 其他:
curl -# www.baidu.com #以“#”号输出进度条
curl -o /tmp/aiezu www.baidu.com #保存http响应到/tmp/aiezu
linux 使用curl小经验教训:
http请求地址的url要使用“”括起来。当有存在多个参数使用&连接时可能会出错。
篇5:linux usermod命令参数及用法详解
命 令:usermod
功能说明:修改用户帐号,
语 法:usermod [-LU][-c <备注>][-d <登入目录>][-e <有效期限>][-f <缓冲天数>][-g <群组>][-G <群组>][-l <帐号名称>][-s
补充说明:usermod可用来修改用户帐号的各项设定。
参 数:
-c<备注> 修改用户帐号的备注文字。
-d登入目录> 修改用户登入时的目录。
-e<有效期限> 修改帐号的有效期限。
-f<缓冲天数> 修改在密码过期后多少天即关闭该帐号。
-g<群组> 修改用户所属的群组。
-G<群组> 修改用户所属的附加群组。
-l<帐号名称> 修改用户帐号名称。
-L 锁定用户密码,使密码无效。
-s
-u
-U 解除密码锁定。
usermod 不 允 许 你 改 变 正 在线 上 的 使 用 者 帐 号 名 称 。 当 usermod 用 来 改 变 user ID, 必 须 确 认 这 名 user 没 在 电 脑 上 执 行 任 何 程 序。 你 需 手 动 更 改 使 用 者 的 crontab 档 。 也 需 手 动 更 改 使 用 者 的 at 工 作 档 。 采 用 NIS server 须 在 server 上 更 动 相 关 的 NIS 设 定 。
应用举例:
1、将 newuser2 添加到组 staff 中
# usermod -G staff newuser2
2、修改 newuser 的用户名为 newuser1
# usermod -l newuser1 newuser
3、锁定账号 newuser1
# usermod -L newuser1
4、解除对 newuser1 的锁定
# usermod -U newuser1











