龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 操作系统 > LINUX系统 >

Linux中find常见用法示例(7)

时间:2014-05-25 02:22来源:网络整理 作者:网络 点击:
分享到:
A) find /tmp -name *.h | xargs -n50 grep SYSCALL_VECTOR B) grep SYSCALL_VECTOR /tmp/*.h | cut -d:' -f1| uniq filename C) find /tmp -name *.h -exec grep SYSCALL_VECTOR {} \; -print 2)find / -name filen

A) find   /tmp   -name   "*.h"   | xargs   -n50   grep SYSCALL_VECTOR
B) grep   SYSCALL_VECTOR   /tmp/*.h | cut    -d’:'   -f1| uniq > filename
C) find   /tmp   -name "*.h"   -exec grep "SYSCALL_VECTOR"   {}   \; -print

2)find / -name filename -exec rm -rf {} \;
    find / -name filename -ok rm -rf {} \;

3)比如要查找磁盘中大于3M的文件:
find . -size +3000k -exec ls -ld {} ;

4)将find出来的东西拷到另一个地方
find *.c -exec cp ‘{}’ /tmp ‘;’

如果有特殊文件,可以用cpio,也可以用这样的语法:
find dir -name filename -print | cpio -pdv newdir

6)查找2004-11-30 16:36:37时更改过的文件
# A=`find ./ -name "*php"` |   ls -l –full-time $A 2>/dev/null | grep "2004-11-30 16:36:37"

=================================================
在/ l o g s目录中查找更改时间在5日以前的文件并删除它们:
$ find logs -type f -mtime +5 -exec   -ok   rm {} \;

=================================================
查询当天修改过的文件
[root@book class]# find   ./   -mtime   -1   -type f   -exec   ls -l   {} \;

=================================================
查询文件并询问是否要显示
[root@book class]# find   ./   -mtime   -1   -type f   -ok   ls -l   {} \;  
< ls … ./classDB.inc.php > ? y
-rw-r–r–    1 cnscn    cnscn       13709   1月 12 12:22 ./classDB.inc.php
[root@book class]# find   ./   -mtime   -1   -type f   -ok   ls -l   {} \;  
< ls … ./classDB.inc.php > ? n
[root@book class]#

=================================================
查询并交给awk去处理
[root@book class]# who   |   awk   ’{print $1"\t"$2}’
cnscn    pts/0

=================================================
awk—grep—sed

[root@book class]# df   -k |   awk ‘{print $1}’ |   grep   -v   ’none’ |   sed   s"/\/dev\///g"
文件系统
sda2
sda1
[root@book class]# df   -k |   awk ‘{print $1}’ |   grep   -v   ’none’
文件系统
/dev/sda2
/dev/sda1

精彩图集

赞助商链接