8、文件搜索 find
2015-09-25 12:13
211 查看
操作实例代码
[root@localhost tmp]# [root@localhost tmp]# pwd /tmp [root@localhost tmp]# ls yum.log [root@localhost tmp]# mkdir findtest [root@localhost tmp]# cd findtest/ [root@localhost findtest]# touch duanbang.file qinxianyou.file [root@localhost findtest]# ls duanbang.file qinxianyou.file [root@localhost findtest]# touch duanba.file qin.file du.file q.file qinxianyo.file [root@localhost findtest]# ls -li 总用量 0 271342 -rw-r--r--. 1 root root 0 9月 25 19:35 duanba.file 271340 -rw-r--r--. 1 root root 0 9月 25 19:34 duanbang.file 271344 -rw-r--r--. 1 root root 0 9月 25 19:35 du.file 271345 -rw-r--r--. 1 root root 0 9月 25 19:35 q.file 271343 -rw-r--r--. 1 root root 0 9月 25 19:35 qin.file 271346 -rw-r--r--. 1 root root 0 9月 25 19:35 qinxianyo.file 271341 -rw-r--r--. 1 root root 0 9月 25 19:34 qinxianyou.file [root@localhost findtest]# find -name duanbang [root@localhost findtest]# find -name duanb* find: 路径必须在表达式之前: duanbang.file 用法: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression] [root@localhost findtest]# find . -name duanbang* ./duanbang.file [root@localhost findtest]# find . -iname DU* ./du.file ./duanba.file ./duanbang.file [root@localhost findtest]# find . -name duanba???? [root@localhost findtest]# find . -name duanba????? ./duanba.file [root@localhost findtest]# find . -size +2048 [root@localhost findtest]# find . -size -2048 . ./du.file ./qinxianyo.file ./duanba.file ./qin.file ./duanbang.file ./q.file ./qinxianyou.file [root@localhost findtest]# find . -size -2048 -exec ls -il {} \; 总用量 0 271342 -rw-r--r--. 1 root root 0 9月 25 19:35 duanba.file 271340 -rw-r--r--. 1 root root 0 9月 25 19:34 duanbang.file 271344 -rw-r--r--. 1 root root 0 9月 25 19:35 du.file 271345 -rw-r--r--. 1 root root 0 9月 25 19:35 q.file 271343 -rw-r--r--. 1 root root 0 9月 25 19:35 qin.file 271346 -rw-r--r--. 1 root root 0 9月 25 19:35 qinxianyo.file 271341 -rw-r--r--. 1 root root 0 9月 25 19:34 qinxianyou.file 271344 -rw-r--r--. 1 root root 0 9月 25 19:35 ./du.file 271346 -rw-r--r--. 1 root root 0 9月 25 19:35 ./qinxianyo.file 271342 -rw-r--r--. 1 root root 0 9月 25 19:35 ./duanba.file 271343 -rw-r--r--. 1 root root 0 9月 25 19:35 ./qin.file 271340 -rw-r--r--. 1 root root 0 9月 25 19:34 ./duanbang.file 271345 -rw-r--r--. 1 root root 0 9月 25 19:35 ./q.file 271341 -rw-r--r--. 1 root root 0 9月 25 19:34 ./qinxianyou.file [root@localhost findtest]# find . -user root -exec -ls -li {} \; find: “-ls”: 没有那个文件或目录 find: “-ls”: 没有那个文件或目录 find: “-ls”: 没有那个文件或目录 find: “-ls”: 没有那个文件或目录 find: “-ls”: 没有那个文件或目录 find: “-ls”: 没有那个文件或目录 find: “-ls”: 没有那个文件或目录 find: “-ls”: 没有那个文件或目录 [root@localhost findtest]# whoami root [root@localhost findtest]# find . -user root -exec ls -li {} \; 总用量 0 271342 -rw-r--r--. 1 root root 0 9月 25 19:35 duanba.file 271340 -rw-r--r--. 1 root root 0 9月 25 19:34 duanbang.file 271344 -rw-r--r--. 1 root root 0 9月 25 19:35 du.file 271345 -rw-r--r--. 1 root root 0 9月 25 19:35 q.file 271343 -rw-r--r--. 1 root root 0 9月 25 19:35 qin.file 271346 -rw-r--r--. 1 root root 0 9月 25 19:35 qinxianyo.file 271341 -rw-r--r--. 1 root root 0 9月 25 19:34 qinxianyou.file 271344 -rw-r--r--. 1 root root 0 9月 25 19:35 ./du.file 271346 -rw-r--r--. 1 root root 0 9月 25 19:35 ./qinxianyo.file 271342 -rw-r--r--. 1 root root 0 9月 25 19:35 ./duanba.file 271343 -rw-r--r--. 1 root root 0 9月 25 19:35 ./qin.file 271340 -rw-r--r--. 1 root root 0 9月 25 19:34 ./duanbang.file 271345 -rw-r--r--. 1 root root 0 9月 25 19:35 ./q.file 271341 -rw-r--r--. 1 root root 0 9月 25 19:34 ./qinxianyou.file [root@localhost findtest]# find .group root -exec ls -li {} \; find: “.group”: 没有那个文件或目录 find: “root”: 没有那个文件或目录 [root@localhost findtest]# find . -group root -exec ls -li {} \; 总用量 0 271342 -rw-r--r--. 1 root root 0 9月 25 19:35 duanba.file 271340 -rw-r--r--. 1 root root 0 9月 25 19:34 duanbang.file 271344 -rw-r--r--. 1 root root 0 9月 25 19:35 du.file 271345 -rw-r--r--. 1 root root 0 9月 25 19:35 q.file 271343 -rw-r--r--. 1 root root 0 9月 25 19:35 qin.file 271346 -rw-r--r--. 1 root root 0 9月 25 19:35 qinxianyo.file 271341 -rw-r--r--. 1 root root 0 9月 25 19:34 qinxianyou.file 271344 -rw-r--r--. 1 root root 0 9月 25 19:35 ./du.file 271346 -rw-r--r--. 1 root root 0 9月 25 19:35 ./qinxianyo.file 271342 -rw-r--r--. 1 root root 0 9月 25 19:35 ./duanba.file 271343 -rw-r--r--. 1 root root 0 9月 25 19:35 ./qin.file 271340 -rw-r--r--. 1 root root 0 9月 25 19:34 ./duanbang.file 271345 -rw-r--r--. 1 root root 0 9月 25 19:35 ./q.file 271341 -rw-r--r--. 1 root root 0 9月 25 19:34 ./qinxianyou.file [root@localhost findtest]# find . -cname -5 find: 未知的断言“-cname” [root@localhost findtest]# find . -cmin -5 [root@localhost findtest]# find . -cmin +5 . ./du.file ./qinxianyo.file ./duanba.file ./qin.file ./duanbang.file ./q.file ./qinxianyou.file [root@localhost findtest]# find . -amin -5 [root@localhost findtest]# find . -amin +5 . ./du.file ./qinxianyo.file ./duanba.file ./qin.file ./duanbang.file ./q.file ./qinxianyou.file [root@localhost findtest]# find . -mmin +5 . ./du.file ./qinxianyo.file ./duanba.file ./qin.file ./duanbang.file ./q.file ./qinxianyou.file [root@localhost findtest]# find . -mmin -5 [root@localhost findtest]# find . -mmin -5 -a -size -2048 -a -name duanbang* -exec ls -li {} \; [root@localhost findtest]# find . -mmin +5 -a -size -2048 -a -name duanbang* -exec ls -li {} \; 271340 -rw-r--r--. 1 root root 0 9月 25 19:34 ./duanbang.file [root@localhost findtest]# find . -mmin +5 -a -size -2048 -a -name duanbang* -o -type f -exec ls -li {} \; 271344 -rw-r--r--. 1 root root 0 9月 25 19:35 ./du.file 271346 -rw-r--r--. 1 root root 0 9月 25 19:35 ./qinxianyo.file 271342 -rw-r--r--. 1 root root 0 9月 25 19:35 ./duanba.file 271343 -rw-r--r--. 1 root root 0 9月 25 19:35 ./qin.file 271345 -rw-r--r--. 1 root root 0 9月 25 19:35 ./q.file 271341 -rw-r--r--. 1 root root 0 9月 25 19:34 ./qinxianyou.file [root@localhost findtest]# find . -inum 271344 -exec ls -li {} \; 271344 -rw-r--r--. 1 root root 0 9月 25 19:35 ./du.file [root@localhost findtest]# find . -inum 271344 -ok rm {} \; < rm ... ./du.file > ? y [root@localhost findtest]# ls -li 总用量 0 271342 -rw-r--r--. 1 root root 0 9月 25 19:35 duanba.file 271340 -rw-r--r--. 1 root root 0 9月 25 19:34 duanbang.file 271345 -rw-r--r--. 1 root root 0 9月 25 19:35 q.file 271343 -rw-r--r--. 1 root root 0 9月 25 19:35 qin.file 271346 -rw-r--r--. 1 root root 0 9月 25 19:35 qinxianyo.file 271341 -rw-r--r--. 1 root root 0 9月 25 19:34 qinxianyou.file [root@localhost findtest]#
操作代码解释
命令 | 作用 | 解释 |
---|---|---|
find . -name duanbang | 在当前目录下搜索名字为”duanbang”的文件和目录 | .表示范围参数 -name表示按名字搜索 |
find . -name duanb* | 在当前目录下模糊搜索名字是duanb开头的文件和目录 | *表示所有字符数目的未知字符 包括0 |
find . -iname DU* | 在当前目录下搜索DU开头的文件和目录 | -iname表示忽略大小写 |
find . -name duanba????? | 在当前目录下搜索duanba开头后面还有5个未知字符的文件和目录 | 一个问号表示一个通配符 |
find . -size +2048, find / -size -2048 | 在当前目录下查找文件大于1MB/小于1MB 的文件和目录 | 在linux中按大小查找文件的时候,数字代表的是数据块的数量,一个数据库大小是0.5KB,所以2048=1MB |
find . -size -2048 -exec ls -il {} \; | 查找当前目录小于1M的文件并ls 加上-li参数 | i参数代表ls的时候,显示文件的i节点编号,-exec [commond] {} \;是固定格式,表示对查找结果执行commond。exec可以换成ok,ok的作用是执行命令操作的时候还会询问是否确定! |
find . -user root -exec ls -li {} \; | 查找当前目录所有者为root的所有文件并展示详情和i节点 | |
find . -group root -exec ls -li {} \; | 查找当前目录所属组为root的文件并展示详情和i节点 | |
find . -cmin -5 | 查找属性修改时间在五分钟内的文件 | +5代表五分钟外,5可修改 |
find . -amin -5 | 查找访问时间在五分钟内的文件 | +5代表五分钟外,5可修改 |
find . -mmin -5 | 查找内容修改时间在五分钟内的文件 | +5代表五分钟外,5可修改 |
find . -mmin -5 -a -size -2048 -a -name duanbang* -exec ls -li {} \; | 查找当前目录下内容修改时间在五分钟内并且名字是duanbang开头的所有文件并且展示出详情和i节点 | -a 连接多个查找条件 -o 等于与 -o 也可以连接多个查找调节 等于或 |
find . -inum 271344 -ok rm {} \; | 查找出当前目录下节点为2731344的文件,并执行删除,但是删除前会询问用户是否确认删除 |
相关文章推荐
- redis教程(一):redis的安装
- Saiku汉化工作记录
- Android中RemoteViews的实现
- 【转】浮点数与十六进制如何转换?
- 机械革命X5(MECHREVO MR-X5)开包检验
- HTML文件模板替换到转换PDF文件并下载PDF文件
- ASP.NET MVC Application_Error 无效不执行
- uvalive 3490 解法二 AC自动机 + 高斯消元
- Linux系统管理-(20)-awk
- 相似图片搜索的原理
- hihocoder #1039 : 字符消除
- Android中AppWidget的分析与应用:AppWidgetProvider
- SDUT oj 3005 打怪升级(内存搜索)
- CentOS7安装Hadoop2.7完整流程
- C++派生类构造函数调用顺序
- 最大熵模型与最大似然概率
- Unity3D Member Data和Inspector, Serialize的关系
- 深入Java底层:内存屏障与JVM并发详解
- vs的 Avalon 自动补全
- 线段树(区间合并) HDOJ 3308 LCIS