shitou's blog 

  • Home
  • About
  • Feed
  • 十人族
  • MIX BOY
  • 塌客

Category "system manage"

21
May

find使用非业余研究

find平时用于查找文件是不可缺少的,find的用法也比较复杂,平时我们用的最多的就是:

find ./ -name "*filename*"

了, 其他一些复杂的用法平时都不怎么用到,这里列下shitou经常用的参数吧:


#找出当前目录下所有以production开头.log结尾的文件

find ./ -name "production*.log" 

#如果当前目录下还有其他子文件夹,但你不想递归查找子文件夹下的目录时使用

find ./ -maxdepth 1 -name "production*.log" 

#如果碰巧当前目录下有个匹配到"production*.log"的文件夹,而你只想要regular(一般)文件时

find ./ -maxdepth 1 -name "production*.log" -type f

#找出当前目录下包含有shitou字符的文件

find ./ -maxdepth 1 -type f | xargs fgrep 'shitou'



#好的,我们继续

#如果你想找最近7天创建的文件时

find ./ -maxdepth 1 -name "production*.log" -type -ctime -7

#如果你想找7天前创建的文件时

find ./ -maxdepth 1 -name "production*.log" -type -ctime +7



#下面来个正真非业余研究的

#如果你想找一个时间段内创建的文件时怎么办呢,find只支持-cnewer参数,即找到比某个文件创建时间更新的文件,

#不过利用这个就够了

#首先我们创建两个文件,并且指定创建时间就为我们要寻找时间段的起至, 用于我们作为基准比较使用

touch tmp -t 201005130000

touch tmp1 -t 201005200000

#上面给定时间戳时要按照“年年年年月月日日时时分分”方式指定,好了现在就可以了

find ./ -maxdepth 1 -name "production-*log" -type f -cnewer tmp -and ! -cnewer tmp1

上面的-ctime为create time的意思,还有-atime(access time),-mtime(modify time)

-type参数还可以有d(目录),f(一版文件),等等

另外还有-group查找指定用户组的,-perm查找指定权限的(0644这样的),-size指定大小,-regex使用正则表达式


find后还可以跟管道(|),用xargs命令把查找到的文件用作后续命令的参数传递进来,看上面的例子



如来神掌打完收工


参考资料

Finding Files


Tags: command

2010-05-21 11:36:29, 947 reviews, comment

send to mailbox

Your email:

Related Posts

strace使用

TOP

Tags

json Impactjs Canvas fun gen_server superfly PS3 Webgame HTML5 jquery SSH tenerer MooseFS gearman-ruby Gearman MongoDB MochiChat TCP U-ka saegusa IN db command Mai Kuraki Norah Jones log iPhoneException ACG Mac Safari objective-c CouchDB LVS AJAX debian 推荐 AMQP google mail bug gettext Erlang 北京 iptables 架构 tips mysql backup function 我看 postfix 监控 SEO cache Etag memcache thread 进程 线程 无锡 yield file column mixboy xml rss gems ruby shitou shell lighttpd 安全 csrf 公司 nginx linux 模块 apache webserver 朋友 大学 生活 尼古拉斯凯奇 movie 文件同步 笑笑 歌词 auto complete plugin rails music ubuntu blog

Category

  • HTML5[3]
  • iPhone[17]
  • Erlang[11]
  • google[13]
  • 生活[45]
  • 音乐[13]
  • 电影[11]
  • linux[29]
  • web server[6]
  • mail server[3]
  • cluster[1]
  • system manage[9]
  • ruby[20]
  • ruby on rails[28]
  • 开源[4]

Episode

  • MongoDB
  • MochiChat
  • iPhoneException
  • shell
  • thread
  • memcache


Popular Posts

  • 准备开始学习Erlang了(恶狼, 二郎..)
  • Ruby遍历MemCached的key
  • 服务器监控小脚本
  • MySQL Innodb备份
  • [转载]5个有用的ruby gems

Recommended Posts

  • Tri-survive - HTML5 Game
  • Cut the rope - HTML5版
  • json_formatter
  • 在gen_server中spawn新的进程
  • Superfly - Wildflowers
  • 继续凸墙 for Mac OS
  • MongoDB Beijing 2011
  • MongoDB删除map_reduce生成的tmp collection
  • Mai Kuraki - Future Kiss
  • Erlang OOP
  • 用SSH tunnel凸墙
  • Google的语法高亮工具包
  • 大量数据的批量操作
  • 再次被和谐-_-
  • 十人族: 上线了

Friends' blogs

  • levy
  • sphance
  • andreas
  • yangkunlun
  • {:dev=>:wxianfeng}
  • bheye
  • joeydarko

Login

   注册

留言 查看留言

留言

   取消

留言 查看留言


Statistics

  • 访问次数: 316267
  • 今天访问: 62
  • 日志: 213
  • 评论: 4967
  • 音乐: 9
  • 用户: 1759


少年,不点下广告吗!

 

all by shitou

blog comments powered by Disqus

close