find . ( -name "*.txt"-o -name "*.pdf") -print
find . -regex ".*(.txt|.pdf)$"
查找所有非txt文本
find . ! -name "*.txt" -print
打印出当前目录的文件(深度为1)
find . -maxdepth 1 -type f
find . -type d -print # 只列出所有目录-type f 文件 / l 符号链接
-atime 访问时间 (单位是天,分钟单位则是-amin,以下类似)
-mtime 修改时间 (内容被修改)
-ctime 变化时间 (元数据或权限变化)
find . -atime 7 -type f -print
w字 k M G
find . -type f -size +2k
find . -type f -perm 644-print # 找具有可执行权限的所有文件
find . -type f -user weber -print # 找用户weber所拥有的文件
删除:
find . -type f -name "*.swp"-delete
find . -type f -user root -exec chown weber {} ; //将当前目录下的所有权变更为weber
注:{}是一个特殊的字符串,对于每一个匹配的文件,{}会被替换成相应的文件名;
find . -type f -mtime +10-name "*.txt"-exec cp {} OLD ;
tips: 如果需要后续执行多个命令,可以将多个命令写成一个脚本。然后 -exec 调用时执行脚本即可;
-exec ./commands.sh {} ;
默认使用' ‘作为文件的定界符;
-print0 使用'‘作为文件的定界符,这样就可以搜索包含空格的文件;