Saturday, 25 February 2017

find 文件查找 (advanced)



  • 查找txt和pdf文件
  find . \( -name "*.txt" -o -name "*.pdf" \) -print

  • 否定参数
       查找所有非txt文本 (!)

   find . ! -name "*.txt" -print

  • 指定搜索深度
       打印出当前目录的文件(深度为1)

  find . -maxdepth 1 -type f 


定制搜索

  • 按类型搜索:
  find . -type d -print  //只列出所有目录, 这里的d是directory的意思
-type f 文件 / l 符号链接


  • 按时间搜索: (Does not work for me, need to figure out why)

-atime 访问时间 (单位是天,分钟单位则是-amin,以下类似)
-mtime 修改时间 (内容被修改)
-ctime 变化时间 (元数据或权限变化)


  • 最近7天被访问过的所有文件:

 find . -atime 7 -type f -print

  • 按大小搜索:
       w字 k M G
       寻找大于2k的文件


找到后的后续动作

  • 删除:
删除当前目录下所有的swp文件: (这个对常用vim的同学非常有用)

  find . -type f -name "*.swp" -delete



forwarded from:

http://mp.weixin.qq.com/s?__biz=MzAxODI5ODMwOA==&mid=2666540479&idx=2&sn=3d31b275c840f07aacbe27c8c0f80145&chksm=80dce914b7ab6002d72ba8cdd724e7d5dcb967313301846dff5f1554d20c382794fe62fd0659&mpshare=1&scene=5&srcid=0225JX3GZ2o4co9AOHf5rJyG#rd

No comments:

Post a Comment