查找:
which
whereis
locate
find
which +命令 只能查询命令
whereis 能查询命令 能查询系统里配置文件的位置
whatis 相当于man -f rpm 查看在man的那一章那一节
locate 查询速度快
维护着一个查询数据库
#vim /etc/updatedb.conf
1)文件系统类型
2)目录
如果被更改之后,需要更新数据库
#updatedb 手动更新数据库
find#find 路径 条件(-name wing - type f) 默认打印
跟条件相关的操作符 [-exec|-ok 动作]
路径:默认不写路径就是当前路径
条件:
- 名称 -name
- -iname 不区分大小写
- 大小 -size
- 时间 -time
- 类型 -type
- 用户
- 组
- 权限
-name 文件名称 按名称查找
#find / -name a.txt
#find / -name a.t??
#find / -name a.tx?
#find / -name '*a.txt'- 表示所有的字符
不区分大小写 -iname 不区分大小写
2)目录
如果被更改之后,需要更新数据库
#updatedb 手动更新数据库
#locate 被查找的关键字
#locate .txt
是通配符
{} ?--> 表示单个字符,任意的单个字符 []--> 表示其中任意一个
?表示单个字符
表示所有字符
[abc]
[a-z]
[a-Z]
[a-zA-Z]
[!a-z]--------> ! 取反 (也就是除了a-z的以外的) 不包括隐藏文件
a-Z的匹配顺序为:aAbB……
一般情况下{}不能用
{1..100}
{abc,abd,efg}
查找大于10M小于20M
#find / -size +10M -a -size -20M
-o可以换成-or
#find ./ ! -size -10Mfind /! \(-size -10M -a -name "wing*" \)
echo -e "hello \tworld hello\ tworal" -e 让特殊符号 生效\是转译字符 : 把有意义 变得没意义,把没意义的变得有意义
附加:用dd命令做测试数据
#dd if=/dev/zero of=/tmp/aa.txt bs=5M count=2
#dd </dev/zero >/tmp/aa.txt bs=5M count=2
按type查找
f:普通文件
find / -type s
-exec 对之前查找出来的文件做进一步操作
-ok 和-exec一样,只不过多了提示
- 表示所有的字符
按权限查找:
-perm
#find ./ -perm 644
./dd.txt
按用户和组查找
-user
-group
#find ./ -user wing
./bb.txt
#find ./ -group user3
./cc.txt
按时间
-atime access时间
-mtime modify时间
-ctime change时间
time表示时间是天
-amin
-mmin
-cmin
min表示时间是分钟查找两分钟内访问过的文件
#find /tmp -amin -2
/tmp/a.txt
查找两分钟前访问过的文件
#find /tmp -amin +2
find . atime +2 -a atime -3 +2 两天以前 -3 三天以内
查找一个文件的硬链接:
[root@wing test]# ln a.txt heihei
[root@wing test]# ll -i
439360 -rw-r--r-- 2 root root 12 Nov 29 22:22 a.txt
439360 -rw-r--r-- 2 root root 12 Nov 29 22:22 heihei
通过正则表达式
[root@wing test]# find . -samefile a.txt -exec --->后面可跟任何命令 {} \; 找到a.txt的硬连接 前面的找出来的东西 交给后面来执行
-ok 有提示 -exec 没有提示
./a.txt
./heihei
防止被查到的文件过多,导致内存溢出错误
find -name wing.txt | xargs -i cp {} /root/Desktop