七、搜索查找类
# find 指令将从指定目录向下递归地遍历其各个子目录,将满足条件的文件或者目录显示在终端。 # 基本语法: find [搜索范围] [选项] # 查找整个 linux 系统下大于 200M 的文件(+n 大于 -n 小于 n 等于, 单位有 k,M,G)
[root@WANFYONG /home]# ls bbb hello.c info.txt mycal mydata.txt wangwang wangyong wangyongyong [root@WANFYONG /home]# [root@WANFYONG /home]# [root@WANFYONG /home]# find /home -name hello.c /home/bbb/hello.c /home/hello.c [root@WANFYONG /home]# [root@WANFYONG /home]# [root@WANFYONG /home]# find /home -user root /home /home/mycal /home/bbb /home/bbb/hello.c /home/hello.c /home/mydata.txt /home/info.txt [root@WANFYONG /home]# [root@WANFYONG /home]# [root@WANFYONG /home]# find / -size +200M /proc/kcore find: ‘/proc/17331/task/17331/fd/5’: 没有那个文件或目录 find: ‘/proc/17331/task/17331/fdinfo/5’: 没有那个文件或目录 find: ‘/proc/17331/fd/6’: 没有那个文件或目录 find: ‘/proc/17331/fdinfo/6’: 没有那个文件或目录 /run/media/root/CentOS 7 x86_64/LiveOS/squashfs.img [root@WANFYONG /home]#
# locate 指令可以快速定位文件路径。locate 指令利用事先建立的系统中所有文件名称及路径的 locate 数据库实现快速 定位给定的文件。Locate 指令无需遍历整个文件系统,查询速度较快。为了保证查询结果的准确度,管理员必须定期更 新 locate 时刻 # 基本语法: locate 搜索文件 # 由于 locate 指令基于数据库进行查询,所以第一次运行前,必须使用 updatedb 指令创建 locate 数据库。 [root@WANFYONG /home]# updatedb [root@WANFYONG /home]# [root@WANFYONG /home]# locate hello.c /home/hello.c /home/bbb/hello.c [root@WANFYONG /home]# [root@WANFYONG /home]#
# which 指令,可以查看某个指令在哪个目录下,比如 ls 指令在哪个目录 [root@WANFYONG /home]# which ls alias ls='ls --color=auto' /usr/bin/ls [root@WANFYONG /home]#
# grep 过滤查找 , 管道符,"|",表示将前一个命令的处理结果输出传递给后面的命令处理 # 基本语法: grep [选项] 查找内容 源文件
[root@WANFYONG /home]# ls bbb hello.c info.txt mycal mydata.txt wangwang wangyong wangyongyong [root@WANFYONG /home]# [root@WANFYONG /home]# [root@WANFYONG /home]# cat hello.c #include<stdio.h> int main() { printf("Hello World\n"); return 0; } [root@WANFYONG /home]# [root@WANFYONG /home]# [root@WANFYONG /home]# cat hello.c | grep "main" int main() [root@WANFYONG /home]# grep -n "main" hello.c 3:int main() [root@WANFYONG /home]# [root@WANFYONG /home]# [root@WANFYONG /home]# cat hello.c | grep -n "main" 3:int main() [root@WANFYONG /home]#






浙公网安备 33010602011771号