Linux文件搜索工具find
一般格式:find [options] [查找路径] [查找条件] [处理动作]
例如:
# find /etc/ -name passwd |ls -l
这个命令只表示去找/etc/下名为passwd的文件;然后
在当前目录执行一次ls -l命令
因此如果想要用ls -l去查看find找到的文件可以这样写
# find /etc/ -name passwd |xargs ls -l
当然用上面的-exec \;也可以实现这样的功能,但是
xargs有它的优点,就是会把上面传递下来的参数一点
一点的传递给后面的命令。因此当你找到很多的小文件
并试图删除的时候rm命令一次接收不了那么多的文件
就可以用xargs命令了。关于xargs的更多用法可以看man
和google
一般用法:
1,查找查找/etc/下文件名为passwd的文件
# find /etc/ -name passwd
# find /etc/ -name *passwd*
# find /tmp/ -user root -exec ls -l \;
# find / -nouser -exec ls -l {} \;
# find /boot/ -size +5M |xargs ls -hl
这里的+5M表示大于5M,5M表示4M到5M之间
-5M就表示小于4M
# find ./ -size 5M -exec ls -lh {} \;
# find /bin/ -perm +7000 |xargs ls -l
这里的+表示任何一类用户的任何一位权限匹配都行
-表示每类用户的指定要检查的权限位都匹配不写+或—
表示精确匹配。
# find /boot/ -type l |xargs ls -l
f: 普通文件
d: 目录
b: 块设备
c: 字符设备
l: 符号链接文件
p: 命名管道
s: 套接字
# find /etc/ -mtime -4 |xargs stat
文件很多我就不完全截图了
-4表示4天以内,+4表示五天以前
4表示4天到5天之间
还可以使用amin,mmin,cmin来表示分钟
# find /sbin/ -perm +7000 -mtime -5|xargs stat
可能有的地方写的不对,希望大家多多指点。。。
转载于:https://blog.51cto.com/evildexy/1363740