Linux下提供了2个强大的文件/文本查找工具 find,grep,以下作简要介绍;
find 工具是一种强大的文件查找工具,可以使用正则表达式进行文件的查找,一般的指令格式如下:
find <role> <dir> <pattern>
dir参数:查找的目录
role参数:功能参数
pattern参数:查找的正则表达式
使用示例:
#根据文件名查找文件
find ./ -name "php" #查找当前目录下名称为"php"的文件
find ./ -name "*php*" #查找名称中含有"php"的文件
find ./ -name "*.php" #查找以".php"结尾的文件
find ./ -iname "php" #忽略大小写查找
find ./ ! -name "*php*" #否定查找,查找名称中不含有"php"的文件
find ./ -type 类型参数
类型参数列表:
f:普通文件
d:目录
l:link文件
find ./ -maxdepth 2 -type f #查找深度最大为2的文件
find ./ -mindepth 2 -type f ##查找深度最小为2的文件
#限制查找范围在当下目录的这一层
find ./ -maxdepth 1 -name "php"
#根据时间戳查找
find ./ -type f -atime -7 #查找 7天内 被访问的文件
find ./ -type f -atime 7 #查找 7天前那一天 被访问的文件
find ./ -type f -atime +7 #查找 超过7天之内 被访问的文件
find ./ -type f -amin -30 #30分钟之内被访问的文件
#根据大小查找
find ./ -type f -size -100k #查找 <100k 的文件
find ./ -type f -size 10M #查找 =10M 的文件
find ./ -type f -size +1G #查找 >1G 的文件