linux 查找文件的命令

1、which

[root@lb01 ~]# which passwd
/usr/bin/passwd
# which - shows the full path of (shell) commands. 
# 顯示命令的全路徑


2、whereis

[root@lb01 ~]# whereis passwd
passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man5/passwd.5.gz /usr/share/man/man1/passwd.1.gz
# whereis - locate the binary, source, and manual page files for a command
# 爲命令:定位二進制文件、源文件、man page文件

3、locate

[root@lb01 ~]# locate passwd
/etc/passwd
/usr/bin/passwd
# locate - find files by name
# 根據名字找出文件名,只要含有關鍵字的,全部找出來

updatedb# 使用這條命令更新緩存的數據庫
/var/lib/mlocate/mlocate.db# 默認緩存的數據庫文件
The database searched by default.


例子:

[root@lb01 ~]# touch /etc/chen.txt# 創建新文件
[root@lb01 ~]# locate chen.txt# 找不到,因爲還沒緩存到/var/lib/mlocate/mlocate.db
[root@lb01 ~]# updatedb # 強制刷新緩存的數據庫
[root@lb01 ~]# locate chen.txt# 可以找到了,而且很快,因爲讀取的是緩存數據庫,並沒有去讀取磁盤
/etc/chen.txt


4、find

[root@lb01 ~]# find / -name chen.txt# find搜索文件系統,實時查找,效率低,因爲搜索的是磁盤,但功能最強大
/etc/chen.txt
[root@lb01 ~]# find / -name passwd
/tmp/oldboy/passwd
/etc/passwd
/etc/pam.d/passwd
/usr/bin/passwd
















發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章