Linux 搜索查找文件

2019-01-11  本文已影响0人  Kokoronashi

Linux 搜索查找文件

locate 命令

Search for entries in a mlocate database.

usage:

locate [OPTION]... [PATTERN]...

安装locate命令

yum install -y mlocate

通过 /var/lib/mlocate/mlocate.db 数据库查找,这个数据库通过/etc/cron.daily/mlocate每天执行一次updatedb更新,如果刚添加的文件,需要手动执行updatedb才能找到.

常用参数:

OPTIONS explanation
-c, --count 统计数字
-i, --ignore-case 忽略大小写
-l, --limit, -n LIMIT 限制 打印出多少行

eg

#查找/etc下所有sh开头的文件
locate /etc/sh
#查找/usr/share下所有jpg文件
locate /usr/share/*.jpg

which 命令

Write the full path of COMMAND(s) to standard output.

usage:

/usr/bin/which [options] [--] COMMAND [...]

which是shell内建命令,通常使用which来确定是否安装了某个指定的软件,因为它只从PATH环境变量指定的路径中去搜索命令

find 命令

Usage:

find [path...] [expression]

find 不但可以通过文件类型、文件名进行查找而且可以根据文件的属性(如文件的时间戳,文件的权限等)进行搜索。

eg

find /opt -type f #找出/opt下所有普通类型文件
find /opt -name *.txt -exec ls {} \;    #找出/opt下的所有.txt结尾文件ls
find /opt -name *.txt |xargs ls #找出/opt下的所有.txt结尾文件ls
上一篇 下一篇

猜你喜欢

热点阅读