使用linux系统难免会忘记文件所在的位置,可以使用以下命令对系统中的文件进行搜索。
搜索文件的命令为”find“;”locate“;”whereis“;”which“;”type“
1、find <指定目录> <指定条件> <指定动作>“
比如使用find命令搜索在根目录下的所有interfaces文件所在位置,
find / -name "oversea"
root@iZj6cjd6a760ev9yr3yiklZ:~# find / -name "oversea"
/opt/hpb/oversea
2、使用locate搜索linux系统中的文件,它比find命令快。因为它查询的是数据库(/var/lib/locatedb),数据库包含本地所有的文件信息。使用locate命令在根目录下搜索interfaces文件的
locate oversea
root@iZj6cjd6a760ev9yr3yiklZ:~# locate oversea
/opt/hpb/oversea
/opt/hpb/oversea/oversea-0.0.1-SNAPSHOT.jar
/opt/hpb/oversea/oversea.log
3、使用”whereis“命令可以搜索linux系统中的所有可执行文件即二进制文件。使用whereis命令搜索grep二进制文件的
whereis grep
root@iZj6cjd6a760ev9yr3yiklZ:~# whereis grep
grep: /bin/grep /usr/share/man/man1/grep.1.gz /usr/share/info/grep.info.gz
4、 使用type命令查看系统中的某个命令是否为系统自带的命令。
type cd
root@iZj6cjd6a760ev9yr3yiklZ:~# type cd
cd is a shell builtin
root@iZj6cjd6a760ev9yr3yiklZ:~# type grep
grep is aliased to `grep --color=auto'