find 查找文件或者目录
find指令将从指定目录向下递归地遍历其各个子目录,将满足条件的文件显示在终端。
-
基本语法
find [搜索范围] [选项] -
选项说明
| 选项 | 功能 |
|---|---|
| -name<查询方式> | 按照指定的文件名查找模式查找文件 |
| -user<用户名> | 查找属于指定用户名所有文件 |
| -size<文件大小> | 按照指定的文件大小查找文件。 |
- 案例实操
(1)按文件名:根据名称查找/目录下的filename.txt文件。
[root@hadoop101 ~]# find xiyou/ -name “*.txt”
(2)按拥有者:查找/opt目录下,用户名称为-user的文件
[root@hadoop101 ~]# find xiyou/ -user atguigu
(3)按文件大小:在/home目录下查找大于200m的文件(+n 大于 -n小于 n等于)
[root@hadoop101 ~]find /home -size +204800
grep 过滤查找及“|”管道符
管道符,“|”,表示将前一个命令的处理结果输出传递给后面的命令处理
-
基本语法
grep 选项 查找内容 源文件 -
选项说明
| 选项 | 功能 |
|---|---|
| -n | 显示匹配行及行号。 |
- 案例实操
(1)查找某文件在第几行
[root@hadoop100 ~]# ll
总用量 112
-rw-r--r--. 1 root root 0 2月 24 15:47 73
-rw-------. 1 root root 1248 2月 23 08:16 anaconda-ks.cfg
-rw-r--r--. 1 root root 6745 2月 23 14:40 forlearnsmartd.conf
-rw-r--r--. 1 root root 41954 2月 23 08:15 install.log
-rw-r--r--. 1 root root 9154 2月 23 08:11 install.log.syslog
drwxr-xr-x. 2 why root 4096 2月 24 15:06 learn
drwxr-xr-x. 3 why why 4096 2月 24 10:39 learndir
drwxr-xr-x. 2 root root 4096 2月 23 00:28 公共的
drwxr-xr-x. 2 root root 4096 2月 23 00:28 模板
drwxr-xr-x. 2 root root 4096 2月 23 00:28 视频
drwxr-xr-x. 2 root root 4096 2月 23 00:28 图片
drwxr-xr-x. 2 root root 4096 2月 23 00:28 文档
drwxr-xr-x. 2 root root 4096 2月 23 00:28 下载
drwxr-xr-x. 2 root root 4096 2月 23 00:28 音乐
drwxr-xr-x. 3 root root 4096 2月 23 18:23 桌面
[root@hadoop100 ~]# ll | grep -n learn
4:-rw-r--r--. 1 root root 6745 2月 23 14:40 forlearnsmartd.conf
7:drwxr-xr-x. 2 why root 4096 2月 24 15:06 learn
8:drwxr-xr-x. 3 why why 4096 2月 24 10:39 learndir
which 查找命令
查找命令在那个目录下
- 基本语法
which 命令 - 案例实操
[root@hadoop100 ~]# which ls
alias ls='ls --color=auto'
/bin/ls
引用自尚硅谷课件
本文深入讲解了Linux系统中find、grep和which等查找命令的使用方法,包括基本语法、选项功能及案例实操,帮助读者掌握高效文件搜索技巧。
490

被折叠的 条评论
为什么被折叠?



