国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Linux > 正文

Linux上的文件搜索命令實例詳解

2024-08-28 00:02:05
字體:
供稿:網(wǎng)友

locate

基礎(chǔ)了解

在centos7上默認(rèn)沒有l(wèi)ocate命令,需要先手動安裝。安裝步驟:http://www.cnblogs.com/feanmy/p/7676717.html

locate命令搜索的后臺數(shù)據(jù)庫路徑:/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

更新數(shù)據(jù)庫使用updatedb,配置文件為/etc/updatedb.conf

# 開啟搜索限制PRUNE_BIND_MOUNTS = "yes"# 不搜索的文件系統(tǒng)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相關(guān)的選項。這里只介紹幾個常用選項
-c, --count            只輸出找到的數(shù)量
-i, --ignore-case      忽略大小寫
-q, --quiet            安靜模式,不會顯示任何錯誤訊息
-r, --regexp REGEXP    使用基本正則表達(dá)式
    --regex            使用擴(kuò)展正則表達(dá)式
-n                     結(jié)果中顯示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 :顯示匹配到的文件數(shù)

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

基礎(chǔ)了解

使用find進(jìn)行文件查找的速度要慢于locate,但是功能及參數(shù)要強(qiáng)于locate。在使用find時,要避免大范圍的搜索

命令選項

這里介紹常用選項,其他選項可通過man find了解

-name  filename       #查找名為filename的文件-iname filename       #查找文件filename,不區(qū)分大小寫-gid  n           #查找屬組gid為n的文件-user  username       #按文件屬主來查找-group  groupname      #按組來查找-mtime  -n +n        #按文件更改時間來查找文件,-n指n天以內(nèi),+n指n天以前-atime  -n +n        #按文件訪問時間來查GIN: 0px">-ctime  -n +n        #按文件創(chuàng)建時間來查找文件,-n指n天以內(nèi),+n指n天以前-nogroup           #查無有效屬組的文件,即文件的屬組在/etc/groups中不存在-nouser            #查無有效屬主的文件,即文件的屬主在/etc/passwd中不存-newer  f1 !f2        #查更改時間比f1新但比f2舊的文件-type             #查是塊設(shè)備、目錄、字符設(shè)備、管道、符號鏈接、普通文件-size   n[c]        #查長度為n塊[或n字節(jié)]的文件
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 含山县| 城市| 永嘉县| 施甸县| 沾化县| 清远市| 芜湖县| 湟源县| 上高县| 曲沃县| 扶绥县| 江孜县| 松滋市| 宁安市| 咸阳市| 连山| 南康市| 辰溪县| 苍梧县| 比如县| 福贡县| 淄博市| 综艺| 蒙山县| 马公市| 浠水县| 玉田县| 佛山市| 中卫市| 宝山区| 仁怀市| 温泉县| 博野县| 同江市| 故城县| 印江| 石棉县| 阳新县| 平遥县| 安庆市| 石景山区|