Linux文件查找命令具体解释-which whereis find locate
生活随笔
收集整理的這篇文章主要介紹了
Linux文件查找命令具体解释-which whereis find locate
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
原創(chuàng)BLog。轉載請注明出處
http://blog.csdn.net/hello_hwc?
viewmode=contents
which命令
首先查看man which的說明which - shows the full path of (shell) commands.
在$PATH文件夾下查找命令的絕對路徑,PATH配置不同,查找的結果也不同
查看系統(tǒng)的PATH
[root@localhost testForCsdn]# echo $PATH /usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin使用舉例
[root@localhost testForCsdn]# which ls alias ls='ls --color=tty'/bin/ls過濾掉alias中的信息
[root@localhost testForCsdn]# which --skip-alias ls /bin/ls
whereis命令
man whereiswhereis - locate the binary, source, and manual page filesfor a command從db中查找系統(tǒng)特定二進制文件。源文件。和manual page文件
說明:db是系統(tǒng)文件信息的快照。保存在本地數(shù)據(jù)庫里,查找速度會非常快、db每隔一段時間更新。假設要手動更新,使用命令
updatedb選項
-b : 僅僅找二進制文件?
-m: 僅僅找在說明文件manual路徑下的文件?
-s : 僅僅找source源文件?
-u : 沒有說明文檔的文件
舉例
1、列出與init相關的文件
[root@localhost testForCsdn]# whereis init init: /sbin/init /etc/init.d /usr/share/man/man8/init.8.gz
2、僅僅查找二進制文件
[root@localhost testForCsdn]# whereis -b init init: /sbin/init /etc/init.d
locate
從db中,這里的db和whereis中的db一樣。找出系統(tǒng)中與指定名稱全部的相關文件
經(jīng)常使用選項
-b 只匹配base name
-c 統(tǒng)計數(shù)目
-r 正則匹配
-w 匹配完整的路徑名稱
-d 指定DBPATH,不用默認的/var/lib/mlocate/mlocate.db
舉例
[root@localhost ~]# locate -c init 601 [root@localhost ~]# locate -bc init 486<pre name="code" class="plain">[root@localhost ~]# locate init | mroe
find
從磁盤上查找文件,查找時能夠指定路
1、-name通過名稱查找
[root@localhost ~]# find /etc -name init /etc/sysconfig/init
2、-size通過大小查找
[root@localhost ~]# find testForCsdn/ -size -2048 testForCsdn/ testForCsdn/file.txt testForCsdn/file.softlink testForCsdn/file.hardlink
3、 -user通過全部者查找
[root@localhost ~]# find testForCsdn/ -user root testForCsdn/ testForCsdn/file.txt testForCsdn/file.softlink testForCsdn/file.hardlink
4、-ctime/mtime/atime -cmin/mmin/amin
c change 如權限改變
a access 訪問
m modify 改動
time依照天為單位
min依照分鐘為單位
查找一小時內訪問過的文件
[root@localhost ~]# find testForCsdn/ -amin -60 testForCsdn/ testForCsdn/file.txt testForCsdn/file.softlink testForCsdn/file.hardlink5、-type 依照類型來查找
經(jīng)常使用類型
f 二進制
l 軟連接
d 文件夾
[root@localhost ~]# find testForCsdn/ -type l testForCsdn/file.softlink
6、-inum
查找指定inode的文件
查找指定inode然后產(chǎn)出
查找指定inode然后刪除該文件
find / -inum 15 –exec rm –rf {} \;7、-a -r
a andr or
多個條件同一時候查找
查找大小小于2M而且類型是軟連接的文件
[root@localhost ~]# find testForCsdn/ -size -2048 -a -type l testForCsdn/file.softlink
8、exec對查找的結果進行處理
查找大小小于2M而且類型是軟連接的文件,然后顯示具體信息
[root@localhost ~]# find testForCsdn/ -size -2048 -a -type l -exec ls -l {} \; lrwxrwxrwx 1 root root 8 Oct 24 20:32 testForCsdn/file.softlink -> file.txt解釋下:這里的{}是查找的結果,分號。代表結果。用\進行轉義
Grep
附上之前寫的一篇鏈接
Grep的9個經(jīng)典使用場景
http://blog.csdn.net/hello_hwc/article/details/40017833
轉載于:https://www.cnblogs.com/yfceshi/p/7063367.html
總結
以上是生活随笔為你收集整理的Linux文件查找命令具体解释-which whereis find locate的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vuejs 过渡效果
- 下一篇: MongoDB--架构搭建(主从、副本集