find pathname -options [-print -exec -ok ....]
-exec表示find命令对匹配的文件执行该参数给出的shell命令。命令的形式为 'command' {} \;
注意{}和\;之间的空格和反斜杠后面的分号。
-ok和-exec作用相同,但是以一种更为安全的模式执行参数所给出的shell命令,在执行每个命令前,将会给出提示,让用户确定是否执行


[root@centos1 c]# find . -name "*.c" ./arr/ar.c ./arr/mp.c ./auto.c ./book/getchar.c ./book/grep.c ./doc.c ./fun/f.c ./fun/f1.c ./io/printf.c ./makefile/main.c ./makefile/t1.c ./makefile/t2.c ./point.c ./point1.c ./pointv.c ./proj/main.c ./proj/proj.c ./struct/s1.c ./struct/st.c [root@centos1 c]# find . -name "*.c" -exec ls -l {} \; -rwxrwxrwx 1 root root 323 1月 2 21:03 ./arr/ar.c -rwxrwxrwx 1 root root 156 1月 15 02:05 ./arr/mp.c -rwxrwxrwx 1 root root 140 4月 22 17:33 ./auto.c -rwxrwxrwx 1 root root 89 4月 13 23:09 ./book/getchar.c -rwxrwxrwx 1 root root 717 4月 13 22:43 ./book/grep.c -rwxrwxrwx 1 root root 1104 1月 29 22:38 ./doc.c -rwxrwxrwx 1 root root 93 1月 28 12:56 ./fun/f.c -rwxrwxrwx 1 root root 798 1月 15 23:27 ./fun/f1.c -rwxrwxrwx 1 root root 702 12月 20 22:20 ./io/printf.c -rwxrwxrwx 1 root root 93 1月 28 17:24 ./makefile/main.c -rwxrwxrwx 1 root root 82 1月 28 20:57 ./makefile/t1.c -rwxrwxrwx 1 root root 79 1月 28 18:44 ./makefile/t2.c -rwxrwxrwx 1 root root 192 8月 2 2017 ./point.c -rwxrwxrwx 1 root root 200 8月 2 2017 ./point1.c -rwxrwxrwx 1 root root 406 9月 12 2017 ./pointv.c -rwxrwxrwx 1 root root 147 12月 20 21:20 ./proj/main.c -rwxrwxrwx 1 root root 144 12月 19 21:59 ./proj/proj.c -rwxrwxrwx 1 root root 561 1月 29 22:46 ./struct/s1.c -rwxrwxrwx 1 root root 236 1月 29 22:19 ./struct/st.c
1.查找目录下含有某字符的
查找/root/find下 含有php字符的文件
find /root/find|xargs grep -si "php"
grep -r 'php' /root/find
只在.php文件里查找
find /root/find -name "*.php"|xargs grep -si "php"
匹配以数字开头的行
find /root/find |xargs grep -si '^[0-9]'
-s:不显示不存在或无匹配文本的错误信息
-i: 不区分大小写
-n: 显示行号
·
2.磁盘监控
df -h|awk -F '[ %]+' '{print $5}'|grep -vi use|grep -E [0-9]
3.获取本机ip
ip(){ eth=$1 ifconfig|grep $eth -A1|tail -1|awk '{print $2}'|cut -d ':' -f2 }