查找的基本命令:
1.which 只能查询命令
例如:
# which rpm
[root@localhost ~]# which rpm
/usr/bin/rpm
#whihc passwd
[root@localhost ~]# which passwd
/usr/bin/passwd
2.whereis 查询配置文件和命令
例如:
#whereis rpm
[root@localhost ~]# whereis rpm
rpm: /usr/bin/rpm /usr/lib/rpm /etc/rpm /usr/share/man/man8/rpm.8.gz
#whereis shadow
[root@localhost ~]# whereis shadow
shadow: /etc/shadow /usr/include/shadow.h /usr/share/man/man3/shadow.3.gz /usr/share/man/man5/shadow.5.gz
3.locate 维护着一个查询数据库
#vim /etc/updatedb.conf
1)文件系统类型
2)目录
如果被更改之后,需要更新数据库
#updatedb 手动更新数据库
#locate 被查找的关键字
#locate *.txt
*是通配符
4 find 命令
find命令用来在指定目录下查找文件。任何位于参数之前的字符串都将被视为欲查找的目录名。如果使用该命令时,不设置任何参数,则find命令将在当前目录下查找子目录与文件。并且将查找到的子目录和文件全部进行显示。
按文件名查找文件:
find 路径 -name 文件名称
# find / -name a.txt
按照文件属主来查找文件
find 路径 -user 用户名
按照文件所属的组来查找文件。
find 路径 -group 组名
查找大于10M小于20M的文件
#find / -size +10M -a -size -20M
-a可以换成-and
#find / -size -10M -o -size +20M
按文件类型查找-type
b - 块设备文件。
d - 目录。
c - 字符设备文件。
p - 管道文件。
l - 符号链接文件。
f - 普通文件。
# find / -type c -exec ls
按时间查询文件
-atime access时间
-mtime modify时间
-ctime change时间
查找两分钟内访问过的文件
# find /tmp -amin -2
/tmp/a.txt
查找两分钟前访问过的文件
# find /tmp -amin +2
查找一个文件的硬链接:
[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
./a.txt
./heihei
转载于:https://blog.51cto.com/13519464/2048489