打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Linux中find命令详解

find命令

find 命令用于查找文件或目录

语法格式:

find ./ -type f -name '文件名’

参数依次是:find命令,这里的./指的是当前路径,-type是选择文件类型,文件类型可以是 f 、d、 l,f是文件类型,d是目录类型,l是链接类型等。-name 按照名称查找,文件名称要加引号。

-type #按照类型查找

​ find ./ -type f # 查找当前目录 并且显示隐藏文件 默认显示目录及目录以下所有符合的文件

-name #按照名称查找

​ find ./ -type f -name "1.txt" # 按照名称查找

​ find ./ -type f -name "*.txt" # 匹配以.txt结尾的文件

​ find ./ -type f -name "1.t?t" # 通配符匹配 ?代表任意单个字符 大部分命令都支持

-size # 按照大小查找 k M G
find ./ -size +50M

     find ./ -size +50M -size -100M		  # 并且关系 查找文件大于50 并且小于100

查找大于80并且小于90的文件

​ find ./ -type f -size +80M -size -90M

-maxdepth # 按照深度等级查找
find ./ -maxdepth 1 -size +50M # 查找1及目录大于50M的文件

​ find ./ -maxdepth 2 -size +50M # 查找2及目录大于50M的文件

find查找到的文件 如何cp rm move

   cp       方法1: cp
			      [root@oldboyedu ~]# find ./ -type f -name "test.sh"|xargs -i cp {} /opt
		    方法2: cp
				  [root@oldboyedu ~]# find ./ -type f -name "test.sh" -exec cp {} /tmp \;
					
			方法3: cp
				  [root@oldboyedu ~]# cp `find ./ -type f -name "test.sh"`  /etc/
                    
   mv        
            方法1:mv
                  [root@oldboyedu ~]# find ./ -type f -name "test.sh"|xargs -i mv {} /opt
            方法2:mv
                  [root@oldboyedu ~]# find /opt -size +50M -exec mv {} ./ \;
            方法3:mv
                  [root@oldboyedu ~]# mv `find ./ -type f -name "test.sh"`  /opt

在find中所有的别名失效

 [root@oldboyedu ~]# find ./ -name "test.avi"|xargs ll
  xargs: ll: No such file or directory
 [root@oldboyedu ~]# find ./ -name "test.avi"|xargs ls -l
  -rw-r--r--. 1 root root 5 Nov  5 10:35 ./test.avi

find中的rm 不会提示交互信息 慎用
[root@oldboyedu ~]# find ./ -name "test.avi"
./test.avi
[root@oldboyedu ~]# find ./ -name "test.avi"|xargs rm
[root@oldboyedu ~]# ll test.avi
ls: cannot access test.avi: No such file or directory

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
shell学习——xargs
shell find一段时间内哪些文件被修改过
Linux文件查找命令find,xargs详述 | LinuxSir.Org
linux查找目录下的所有文件中是否含有某个字符串
Linux下常用命令和脚本备忘
linux中find命令高级用法
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服