Chinaunix首页 | 论坛 | 博客
  • 博客访问: 65060
  • 博文数量: 17
  • 博客积分: 673
  • 博客等级: 中士
  • 技术积分: 150
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-17 16:48
文章分类

全部博文(17)

文章存档

2012年(5)

2011年(12)

分类: LINUX

2012-08-18 22:34:52

<==============================================================================>
  #find的一些方法
  find  ${findPath}  -maxdepth 1 -regex ".*\.\(c\|h\)" -type f
  
  #避开 .开头的隐藏文件
  find  ! -name ".?*" -type f 
  
  #find 可以对regex做查询 指定目录下查找指定文件名
  find -name "Reporter_*" -type d| xargs -i find {} -regex ".*\.\(htm\|rtf\)" -type f | xargs -i cp {} DEST/
  
  #这不是个好方法: 
  # find . \( -path .*/Input -o -path .*/Output -o -path .*/Current    \) -prune -o -name "*.htm" -print
  #这个比较好 避开某些目录查找文件 提高效率
  find . \( -name Input -o -name Output -o -name Current \) -type d -prune -o -name "*.htm" -print
  
  #find 以后 先替换匹配的模式 再在文件末尾追加tag
  find + | xargs sed -i -e 's|\(.*\)\(\)|\1_DC\2|' -e '$ s|.*|& \n|'

  #Search  for  files in your home directory which have been modified in the last twenty-four hours.
  find $HOME -mtime 0

  #find empty dir and remove it
  find $findPath  -name "[A-Z]*" -type d -empty -exec rm -rf '{}' \;

  #find the dir in the current dir is modified 1 day ago, then remove them
  find  -maxdepth 1 -name "*DC" -type d -mtime +1| xargs rm -rf

  # Back up configuration files, adding a .orig extension
  find -name "*.conf" -exec cp {} {}.orig \;

  # Prompt to remove Joe's tmp files that are over 3 days old
  find /tmp -ctime +3 -user joe -ok rm {} \;

  # Fix other-writable files in your home directory
  find ~ -perm +o+w -exec chmod o-w {} \;
  
<==============================================================================>=============
 find / -type l -ls 查找softlink (07-13 15:09)   
 find /path -type l -exec ls -l {} \;|awk '$NF~/filename/' (07-13 15:10)    
 查找文件是否被软链接:find / -follow -xtype l -inum  

<================================================================>
  # delete empty dirs
  find  -type d -empty -exec rmdir {}\
  # delete empty dirs recursivly
  find  -depth -type d -empty -exec rmdir {}\

<================================================================>
  find 默认是每个分支深度优先。如果加上depth,那么先parse内容然后parse目录。

阅读(1275) | 评论(0) | 转发(0) |
0

上一篇:vi tips

下一篇:grep exp

给主人留下些什么吧!~~