find命令用于查找目录下的文件,同时也可以调用其他命令执行相应的操作。
[root@7bfe451a2fe1 /]# find --help
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
说明:
find查找条件
find /home -type f -name "*.py"# -name参数只支持* ? []这三个通配符
find . -name 1.pcap
find /usr -name which
find . -atime -2# -atime 按照文件的访问时间来查找文件,单位为天
# -2 表示时间距现在2天内
# +2 表示时间距现在2天前
# 2 表示距现在第2天
find / -mmin -5# -mmin 按照文件的修改时间来查找文件,单位为分钟
find . -newer file1.txt
find . -newer file1.txt ! -newer file2.txt
find . -type f -mtime +3 -exec rm {} \;
find . -type d -iname douyin# d表示目录
# f表示文件
find /etc/ -type f -perm 0644 -print
find / -size +20M -size -30M
find / -user nobody
find . -nouser
find paathname -regextype "type" -regex "pattern"# 正则表达式的类型默认为emacs
find . -type f -name "*.exe" -exec rm -f {} \;
find ~ -iname "wordpress*"
find /var/www/html ! -name "*.html"# ! 表示反向查找,注意其位置
find /data \(-path /data/logs -o -path /data/data\) -prune -o -print# -a 和 -o 类似于 and 和 or
# -path "/data/dir1" -prune -o -print
# 相当于 -path "/data/dir1" -a -prune -o -print
find /home -maxdepth 1 -type d ! -name '.'
将找到的文件移到指定位置的几种方法
find命令结合exec和xargs使用的区别
好记性不如烂笔头,用来备查