locate
基礎了解
在centos7上默認沒有locate命令,需要先手動安裝。安裝步驟:http://www.cnblogs.com/feanmy/p/7676717.html
locate命令搜索的后臺數據庫路徑:/var/lib/mlocate/mlocate.db
ls -hl /var/lib/mlocatetotal 1.2M-rw-r----- 1 root slocate 1.2M Oct 16 14:36 mlocate.db
更新數據庫使用updatedb,配置文件為/etc/updatedb.conf
# 開啟搜索限制PRUNE_BIND_MOUNTS = "yes"# 不搜索的文件系統PRUNEFS = "9p afs anon_inodefs auto autofs bdev binfmt_misc cgroup cifs coda configfs cpuset debugfs devpts ecryptfs exofs fuse fuse.sshfs fusectl gfs gfs2 gpfs hugetlbfs inotifyfs iso9660 jffs2 lustre mqueue ncpfs nfs nfs4 nfsd pipefs proc ramfs rootfs rpc_pipefs securityfs selinuxfs sfs sockfs sysfs tmpfs ubifs udf usbfs"# 不搜索的文件類型PRUNENAMES = ".git .hg .svn"# 不搜索的文件路徑PRUNEPATHS = "/afs /media /mnt /net /sfs /tmp /udev /var/cache/ccache /var/lib/yum/yumdb /var/spool/cups /var/spool/squid /var/tmp"
命令選項
了解一個命令可以使用man,如 man locate,可以顯示locate相關的選項。這里只介紹幾個常用選項
-c, --count 只輸出找到的數量
-i, --ignore-case 忽略大小寫
-q, --quiet 安靜模式,不會顯示任何錯誤訊息
-r, --regexp REGEXP 使用基本正則表達式
--regex 使用擴展正則表達式
-n 結果中顯示n個文件
使用示例
1、locate /etc/pro :查詢出/etc目錄下所有以pro開頭的文件
locate /etc/pro/etc/profile/etc/profile.d/etc/protocols/etc/profile.d/256term.csh/etc/profile.d/256term.sh/etc/profile.d/colorgrep.csh/etc/profile.d/colorgrep.sh/etc/profile.d/colorls.csh/etc/profile.d/colorls.sh/etc/profile.d/lang.csh/etc/profile.d/lang.sh/etc/profile.d/less.csh/etc/profile.d/less.sh/etc/profile.d/vim.csh/etc/profile.d/vim.sh/etc/profile.d/which2.csh/etc/profile.d/which2.sh
2、locate -c /etc/pro :顯示匹配到的文件數
locate -c /etc/pro17
3、locate -i topoftencent.class.php :忽略文件名大小寫
locate -i topoftencent.class.php/var/www/html/fxyxManage/Spider/TopOfTencent.class.php
雖然文件名大小寫不一致,但使用-i選項依然能匹配出
find
基礎了解
使用find進行文件查找的速度要慢于locate,但是功能及參數要強于locate。在使用find時,要避免大范圍的搜索
命令選項
這里介紹常用選項,其他選項可通過man find了解
新聞熱點
疑難解答