find命令常用来搜索目录树中的文件或者目录,并可对搜索出来的目录或文件执行某些操作。
命令格式:find pathname -options [-print -exec -ok…],其中pathname表示在pathname这个目录下寻找。
-options表示find命令的常用选项,主要有
(1)、-name 表明按文件或目录名来进行查找;
(2)、-type 表明将按文件类型来查找;
(3)、-perm 表明将按文件或目录权限来查找;
(4)、-user 表明将文件或目录的所有者查找;
(5)、-group 表明将按文件或目录所属的组来查找;
(6)、-mtime -n (或+n) 表明按照文件的更改时间来查找文件, 时间都是距离此刻的时间,- n表示文件更改时间距现在n天以内,+ n表示文件更改时间距现在n天以前。
2、-print表示将find命令匹配的文件输出到标准输出,
-> find . -name "*ptp*" -exec ls -l {} \;
-rw-r--r-- 1 huimingf ccase 139178 Dec 28 16:48 ./ptpdriver.cc
-rw-r--r-- 1 huimingf ccase 19047 Dec 28 16:48 ./ptpdriver.hh
-rw-r--r-- 1 huimingf ccase 7705 Dec 28 16:48 ./ptpevent.cc
-rw-r--r-- 1 huimingf ccase 1503 Dec 28 16:48 ./ptpevent.hh
-rw-r--r-- 1 huimingf ccase 2178 Dec 28 16:48 ./ptpmain.c
-rw-r--r-- 1 huimingf ccase 15278 Dec 28 16:48 ./ptptcdriver.cc
-rw-r--r-- 1 huimingf ccase 56432 Dec 28 16:48 ./ptputil.cc
-> find . -name "*ptp*" -ok rm {} \;
< rm ... ./ptpdriver.cc > ? y
-> find ptp/src -name "*ptp*" -ok grep -nr "string.h" {} \;
< grep ... ptp/src/ptpdriver.cc > ? y
14:#include <string.h>
18:#include <string.h>
< grep ... ptp/src/ptpdriver.hh > ? y
< grep ... ptp/src/ptpevent.cc > ? y
13:#include <string.h>
< grep ... ptp/src/ptpevent.hh > ? y
< grep ... ptp/src/ptpmain.c > ? y
< grep ... ptp/src/ptptcdriver.cc > ? y
3:#include <string.h>
7:#include <string.h>
< grep ... ptp/src/ptputil.cc > ? y
1:#include <string.h>
xargs命令是给其他命令传递参数的一个过滤器,常作为组合多个命令的一个工具。它主要用于将标准输入数据转换成命令行参数,xargs能够处理管道或者标准输入并将其转换成特定命令的命令参数
/home/huimingf/GitWorkSpace/test/app/ptp/src
-> find . -name "ptp*"| xargs grep "ptpdriver.hh" -ls
./ptpdriver.cc
./ptptcdriver.cc
./ptputil.cc
/home/huimingf/GitWorkSpace/test/app/ptp/src
-> find . -name "ptp*"| xargs grep "ptpdriver.hh"
./ptpdriver.cc:#include "ptpdriver.hh"
./ptptcdriver.cc:#include "ptpdriver.hh"
./ptputil.cc:#include "ptpdriver.hh"
-> find ./ -type f|xargs grep pattern -ls
./.git/info/exclude
./tps/siftester/tc_selection_ctags.py
./tps/siftester/tc_selection_nm.py
./clearcase/old/commitcheck
./rc.d/msys_bashrc
./ptplogger/ptpvisualizer.py
./ptplogger/old/ptpvisualizer_realtime.py
./ptplogger/old/ptp_plot_old.py
./ptplogger/old/ptp_plot_file.py
./pss/parseual.py