Linux总结(七):文本搜索(grep)和文件搜索(locate,find,which,whereis)
来源:互联网 发布:淘宝修改发货地址 编辑:程序博客网 时间:2024/06/03 19:35
1.文本搜索
grep是根据文件的内容进行查找,会对文件的每一行按照给定的模式(patter)进行匹配查找。
格式:grep 关键字 目录
#在目录所在文件里搜索关键字,如(abc是单个单词不用加单引号): grep abc /etc/passwd
#常用参数:
-i 在搜索时忽略大小写
-n 显示结果所在行数
-v 输出不带关键字的行
-Ax 在输出的时候包含结果所在行 之后的指定行数(x 代表数字)
-Bx 在输出的时候包含结果所在行 之前的指定行数(x 代表数字)
关于grep推荐一篇博客linux grep。
2.文件搜索
locate配合数据库查看文件位置,find根据文件的属性精确查找文件名,which查看可执行文件的位置,whereis查看文件的位置 。
- 使用 locate 命令配合数据库查找文件、目录
locate keyword(关键字)
#此命令需要预先建立数据库,默认数据库每天更新一次,我们可以用 updatedb命令手动更新- 使用 find 命令精确查找文件、目录
# 如:
find . -name “*keyword*”(关键字)
find / -name *.conf
find / -perm 777 (查找权限是 777 的文件)
find / -type d (查找所有的目录)
find . -name “a*” -exec ls -l {} \; (查找以 a 开头的文件,并查看他们的 ls)
find . -user tom (查找用户属于 tom 的文件)
find . -group tom (查找属组是 tom 的文件)
find . -ctime +2|wc -l (查找最近两天修改的文件,并统计个数)
find . -size 30[cwbkMG] (查找指定大小的文件)
- 使用 which 命令查看可执行文件的位置
# which 是通过 PATH 环境变量到该路径内查找可执行文件,所以基本功能是查找可执行文件;
- 使用 whereis 命令查看文件的位置
#常用参数:
-b 只查找二进制文件
-s 只查找源文件
# whereis 与 locate 的查找方式一样,都是通过数据库查找
0 0
- Linux总结(七):文本搜索(grep)和文件搜索(locate,find,which,whereis)
- Linux 搜索命令(locate/find/whereis/which/grep)
- linux命令:文件搜索(locate、whereis、which、find、grep)
- linux中文件搜索命令(whereis,locate,which,find)
- linux中文件搜索相关的locate,find,whereis与which,grep的使用
- Linux学习之文件搜索命令(二)其他搜索命令 locate |which|whereis|grep
- 五、Linux常用命令之文件搜索篇(which、whereis、find、locate、grep、man、info、whatis、--help、apropos、help)
- linux下文件的查询(find,which,whereis,locate)
- Linux常用命令002之搜索命令locate、whereis、which、find、grep
- Linux常用命令002之搜索命令locate、whereis、which、find、grep
- linux 查找命令(find which whereis grep locate type)
- Linux下各种查找命令(find, grep, which, whereis, locate)
- linux常用命令(locate,whereis,which,find,grep)
- Linux :grep find locate whereis which
- Linux文件搜索之 find / locate / whereis / which
- Linux文件搜索之 find / locate / whereis / which
- Linux文件搜索之 find / locate / whereis / which
- Linux下搜索文件find、which、whereis、locate
- Spring javaBean关于属性命名的特殊规范
- HDFS 上的数据导入到Hbase
- daemon守护进程中将stdin,stdout,stderr重定向到/dev/null的问题
- SimpleArrayMap源码解析
- ext2 、ext3 、ext4
- Linux总结(七):文本搜索(grep)和文件搜索(locate,find,which,whereis)
- dubbo项目启动报无法读取方案文档 'http://code.alibabatech.com/schema/dubbo/dubbo.xsd', 原因为 1) 无法找到文档; 2) 无法读取文档;
- Android 中读写excel 中的类容
- 最近收集的一些面试题
- AngularJs指令之scope属性详解---看完这篇,都不好意思说自己没学会!
- 基本数学概念——数列
- 无废话MVC入门教程三[路由设置及视图入门]
- 安装APK文件
- Linux-Vim编辑器之高级功能入门