Linux · 2009-04-13

shell基础十二篇_学习笔记_3_find_exec_mtime_type

man一下find,头大,这能写一本书了呵呵.
find默认在当前路径查找,例如查找 .sh 的文件:

-name 名字选项
find -name \*.sh

-mtime +x -x
-mtime +3 表示3天前修改过的文件
-mtime -3 表示3天内修改过的文件
来自 LinuxSir 论坛
-amin n
  查找系统中最后N分钟访问的文件

  -atime n
  查找系统中最后n*24小时访问的文件

  -cmin n
  查找系统中最后N分钟被改变文件状态的文件

  -ctime n
  查找系统中最后n*24小时被改变文件状态的文件

 -mmin n
  查找系统中最后N分钟被改变文件数据的文件

  -mtime n
  查找系统中最后n*24小时被改变文件数据的文件

-user 与 -group 分别是已用户或组为条件的查找
find -user abc 查找abc用户的文件
find -group abc 查找abc组的成员的文件

-perm 用权限来查找
find -perm 777 查找当前目录下权限为777的文件

-type 指定文件类型
常用的有:
-d 目录
-f 普通文件

-exec 或 -ok 使用-exec 来增加find的功能,例如删除或其他等等..
find -type f -exec ls -ahl {} \; 查找当前文件夹,类型为文件的 执行 ls -ahl

指定路径 , 例如/etc
find /etc -type f -exec ls -ahl {} \;

find -type f -exec ls -ahl {} \;
-rw-r–r– 1 root root 0 2009-04-11 10:41 ./bbb
-rw-r–r– 1 root root 0 2009-04-11 10:41 ./aaa
-rwxrwxrwx 1 root root 0 2009-04-11 16:56 ./temp

-exec 加入 rm 使得可以删除已经找到的文件
列出文件并删除:
find -type f -exec ls -ahl {} \; -exec rm {} \;
-rw-r–r– 1 root root 0 2009-04-11 10:41 ./bbb
-rw-r–r– 1 root root 0 2009-04-11 10:41 ./aaa
-rwxrwxrwx 1 root root 0 2009-04-11 16:56 ./temp

-prune 排除目录,但不能与 -depth 选项一起使用,否则 -prune 会被忽略.
find很多东西,具体看这里