(7)——文件查找与文件管理1
最后更新于:2022-04-01 14:44:22
## 一、可执行文件的搜索
which
显示一个可执行文件的完整路径
按照alias—>$PATH的顺序查找
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-06-14_575f8bb0b2fb7.jpg)
查看系统的环境变量
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-06-14_575f8bb0c8aef.jpg)
whereis
搜索一个可执行工具及其相关配置、帮助
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-06-14_575f8bb0dd6da.jpg)
slocate
slocate或locate 关键字
所有文件名及其所在路径包含关键字段的文件与目录都会显示
slocate先将当前目录结构做成一个数据库,然后在此数据库中搜索匹配记录
find
find [路径] [参数] [表达式]
从指定路径下递归向下搜索文件
支持按照各种条件方式搜索
支持对搜索得到的文件进一步用指令操作
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-06-14_575f8bb1042ad.jpg)
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-06-14_575f8bb116f2d.jpg)
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-06-14_575f8bb128e83.jpg)
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-06-14_575f8bb13a026.jpg)
以文件类型查找
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-06-14_575f8bb157af3.jpg)
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-06-14_575f8bb16a142.jpg)
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-06-14_575f8bb17f9ee.jpg)
## 二、操作找到的文件
语法: find [路径] [参数] [表达式] -exec 指令 {} \ ;
{} 代表find找到的文件
\ 禁止转意
; 表示本行命令的结束
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-06-14_575f8bb19594e.jpg)
## 三、常用的文件操作指令
wc 统计文字的行、词、字数
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-06-14_575f8bb1adced.jpg)
grep 显示文件中匹配关键字的行
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-06-14_575f8bb1bf983.jpg)
sort 按序重排文本并送显示
diff 报告文本差异内容
comp 报告文本差异位置
uniq 去除文件中的重复行
cut 显示文件中的某一列
paste 将文本按列拼接