shell基础--find查找文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 # 第一个参数交待查找路径,默认为当前路径 # -name 参数指定需要查找的文件名,支持正则表达式 find -name '*.txt' find ./dir1/ -name '*.txt' # -maxdepth 指定查找的最大目录层级深度 find -maxdepth 2 -name '*.txt' # -type d 表示查找目录类型 # -type f 表示查找文件类型 find -type f -name '*.txt' # 查找指定大小范围的文件;如下表示查找大小范围在50M~100M范围之间的文件 find -size +50M -size -100M # 找到文件后,执行一些命令操作 ## 查看找到文件的详细信息 find -name '*.txt' -exec ls -l {} \; ## 返回找到文件的文件名(去除路径) find -name '*.txt' -exec basename {} \;