栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

linux之find命令

linux之find命令

linux之find命令

find命令用于搜索文件或者目录,find命令的参数特别多,我们只列举常用的:

参数解释
-name以文件或者目录名称搜索
-user以文件所属用户搜索
-type限制文件类型,f为文件,d为文件夹
-maxdepth最大搜索深度
[root@linuxforliuhj test]# ll
total 0
-rw-r--r--. 1 root      root      0 Nov  3 00:10 Alis.txt
-rw-r--r--. 1 root      root      0 Nov  3 00:10 Bouch.sh
-rw-r--r--. 1 root      root      0 Nov  3 00:10 Count.jpg
-rw-r--r--. 1 hadoop101 hadoop101 0 Nov  3 00:10 Zero
-rw-r--r--. 1 hadoop101 hadoop101 0 Nov  3 00:09 alis.txt
-rw-r--r--. 1 root      root      0 Nov  3 00:10 bouch.sh
-rw-r--r--. 1 root      root      0 Nov  3 00:10 count.jpg
drwxr-xr-x. 2 root      root      6 Nov  3 00:39 dir1
drwxr-xr-x. 2 root      root      6 Nov  3 00:39 dir2
-rw-r--r--. 1 root      root      0 Nov  3 00:10 zero
[root@linuxforliuhj test]# 

命令find /test/ -maxdepth 3 -type f -name "*i*"
/test/ :表示在/test/目录下搜索
-maxdepth 3 : 最大搜索深度为3
-type f : 搜索类型为文件file
-name : 以文件名搜索,后面则是通配符

[root@linuxforliuhj test]# find /test/ -maxdepth 3 -type f -name "*i*"
/test/alis.txt
/test/Alis.txt
[root@linuxforliuhj test]# 

命令find /test/ -user hadoop101
/test/ :表示在/test/目录下搜索
-user : 搜索文件属主为hadoop101用户的文件

[root@linuxforliuhj test]# find /test/ -maxdepth 3 -type f -user hadoop101
/test/alis.txt
/test/Zero
[root@linuxforliuhj test]# 

注意
maxdepth参数尽量放在type、name/user参数之前,例如执行find /test/ -maxdepth 3 -type f -name "*i*"不会有任何报错,但是执行find /test/ -type f -maxdepth 3 -name "*i*"会有warning提示。

[root@linuxforliuhj test]# find /test/  -type f -maxdepth 3 -name "*i*"
find: warning: you have specified the -maxdepth option after a non-option argument -type, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it).  Please specify options before other arguments.

/test/alis.txt
/test/Alis.txt
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/434106.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号