Linux中find命令详解 | 您所在的位置:网站首页 › linux中查找命令 › 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 Gfind ./ -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.avifind中的rm 不会提示交互信息 慎用[root@oldboyedu ~]# find ./ -name "test.avi"./test.avi[root@oldboyedu ~]# find ./ -name "test.avi"|xargs rm[root@oldboyedu ~]# ll test.avils: cannot access test.avi: No such file or directory |
CopyRight 2018-2019 实验室设备网 版权所有 |