- find dir [option] 内容
- -name 按照名字进行查找
root@ubuntu:/home# find ./ -name "*.c"
./c.c
./a.c
-
-type 按照类型查找
-
f---普通文件
-
d---目录文件
-
l---符号链接
-
b---块设备
-
c---字符设备
-
p---管道设备
-
s---本地套接字
-
查找普通文件
root@ubuntu:~/Test# find -type f
./hello.c.hard
./hello.c.hard1
./shell
./hello.c
- -size 按照大小进行查找
搜索大于1M的文件
root@ubuntu:~# find ./ -size +1M
搜索大于1M小于3M的文件
root@ubuntu:~# find ./ -size +1M -size -3M
- 注意:如果直接是find ./ -size 1M这样,代表的是搜索等于1M的文件,但是不精确。
-maxdepth 最深路径
1代表只查找当前路径下的一级,如果为2,则查找当前路径下的两级
find ./ -maxdepth 1 -size +1M
- xargs和find配合使用---xargs将find命令查找的结果分成若干块输出给后面的指令
root@ubuntu:~# find ./ -type l |xargs ls -l
lrwxrwxrwx 1 root root 7 10月 27 14:43 ./Test/hello.c.soft -> hello.c
- grep命令 内容过滤
- grep [option] 内容 dir|filename
root@ubuntu:~/Test# ls
hello.c hello.c.hard hello.c.hard1 hello.c.soft shell
root@ubuntu:~/Test# find ./ -type f |grep hello
./hello.c.hard
./hello.c.hard1
./hello.c
查找内容
root@ubuntu:~/Test# cat hello.c | grep "main"
int main()
追踪日志文件
root@ubuntu:~/Test# tail -f hello.c | grep main
int main()
-
-r---递归了目录
-
-n---显示行号
root@ubuntu:~/Test# tail -f hello.c | grep -rn main
hello.c.hard:4:int main()
hello.c.hard1:4:int main()
hello.c:4:int main()