一、文件查找

(一)、命令文件

[root@linux ~]# chich ls                 //从PATH环境变量
[root@linux ~]# chereis vim [root@linux ~]# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

二、任意文件

A. locate (查询的数据库: /var/lib/mlocate/mlocate.db)
计划任务:每天自动更新数据库 /etc/cron.daily/mlocate.cron
              手动更新数据库:updatedb
              # locate ifcfg-eth0
              # locate ifcfg-enp0s25

B. find
find [options] [path...] [expression] [action]

(一)、按文件名:

[root@linux ~]# find /etc -name "ifcfg-eth0"
[root@linux ~]# find /etc -iname "ifcfg-eth0" //-i忽略大小写
[root@linux ~]# find /etc -iname "ifcfg-eth*"

(二)、按文件大小:

[root@linux ~]# find /etc -size +5M                        //大于5M
[root@linux ~]# find /etc -size 5M
[root@linux ~]# find /etc -size -5M
[root@linux ~]# find /etc -size +5M -ls //-ls找到的处理动作

(三)、指定查找的目录深度:

-maxdepth levels
-mindepth levels
[root@linux ~]# find / -maxdepth -a -name "ifcfg-eth0"  //深度3

(四)、按时间找(atime,mtime,ctime):

[root@linux ~]# find /etc -mtime +                     //修改时间超过5天
[root@linux ~]# find /etc -mtime //修改时间等于5天
[root@linux ~]# find /etc -mtime - //修改时间5天以内

(五)、按文件属主、属组找:

[root@linux ~]# find /home -user jack                    //属主是jack的文件
[root@linux ~]# find /home -group hr //属组是hr组的文件
[root@linux ~]# find /home -user jack -group hr
[root@linux ~]# find /home -user jack -a -group hr
[root@linux ~]# find /home -user jack -o -group hr
[root@linux ~]# find /home -nouser
[root@linux ~]# find /home -nogroup
[root@linux ~]# find /home -nouser -o -nogroup

(六)、按文件类型:

[root@linux ~]# find /dev -type f                           //f普通
[root@linux ~]# find /dev -type d   //d目录
[root@linux ~]# find /dev -type l //l链接
[root@linux ~]# find /dev -type b    //b块设备
[root@linux ~]# find /dev -type c //c字符设备
[root@linux ~]# find /dev -type s //s套接字
[root@linux ~]# find /dev -type p    //p管道文件

(七)、按文件权限:

[root@linux ~]# find . -perm  -ls
[root@linux ~]# find . -perm - -ls
[root@linux ~]# find . -perm - -ls
[root@linux ~]# find . -perm - -ls //全局可写
[root@linux ~]# find /usr/bin /usr/sbin -perm - -ls //包含set uid
[root@linux ~]# find /usr/bin /usr/sbin -perm - -ls //包含set gid
[root@linux ~]# find /usr/bin /usr/sbin -perm - -ls //包含sticky

(八)、按正则表达式:

-regex pattern
[root@linux ~]# find /etc -regex ' .* ifcfg-eth [0-9] '
.* 任意多个字符
[-] 任意一个数字 [root@linux ~]# find /etc -regex '.*ifcfg-enp0s25'
/etc/sysconfig/network-scripts/ifcfg-enp0s25 [root@linux ~]# find /etc -regex '.*ifcfg-enp0s[0-9]+'
/etc/sysconfig/network-scripts/ifcfg-enp0s25

三、查找之后

==找到后处理的动作 ACTIONS: (默认动作-print)==

-print
-ls
-delete
-exec 后面跟自定义的shell命令
-ok 后面跟自定义的shell命令
[root@linux ~]# find /etc -name "ifcfg*"
[root@linux ~]# find /etc -name "ifcfg*" -print
[root@linux ~]# find /etc -name "ifcfg*" -ls
[root@linux ~]# find /etc -name "ifcfg*" -exec cp -rvf {} /tmp \;
[root@linux ~]# find /etc -name "ifcfg*" -ok cp -rvf {} /tmp \; [root@linux ~]# find /etc -name "ifcfg*" -exec rm -rf {} \;
[root@linux ~]# find /etc -name "ifcfg*" -delete 扩展知识:find结合xargs
[root@linux ~]# find . -name "yang*.txt" |xargs rm -rf
[root@linux ~]# find /etc -name "ifcfg-eth0" |xargs -I {} cp -rf {} /var/tmp

Linux基础文件查找的更多相关文章

  1. linux 批量文件查找并替换

    linux 批量文件查找并替换 sed -i "s/oldstring/newstring/g" `grep oldstring -rl path` 如: sed -i " ...

  2. Linux操作系统的文件查找工具locate和find命令常用参数介绍

    Linux操作系统的文件查找工具locate和find命令常用参数介绍 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.非实时查找(数据库查找)locate工具  locate命 ...

  3. Linux 执行文件查找命令 which 详解

    某个文件不知道放在哪里了,通常可以使用下面的一些命令来查找: which  查看可执行文件的位置 whereis 查看文件的位置 locate   配合数据库查看文件位置 find   实际搜寻硬盘查 ...

  4. [Linux] find文件查找和grep文件内容查找

    在使用linux时,经常需要进行文件查找.其中查找的命令主要有find和grep.两个命令是有区别的: (1)find命令:根据文件的属性进行查找,如文件名,文件大小,所有者,所属组,是否为空,访问时 ...

  5. Linux下文件查找命令find笔记

    在Linux命令下如果需要快速自己系统所需要处理的文件,可以通过find命令快速进行检索. 如果想在某个路径下查找相应的文件可以执行如下命令: find path -name filename # p ...

  6. linux之文件查找find grep详解,以及压缩归档

    .find linux里的实时查找工具,通过制定路径完成文件查找. find[options]...[查找路径] [查找条件] [处理动作] 查找路径:查找的位置,默认是当前文件夹. 查找条件:指定查 ...

  7. linux通过文件查找依赖关系

    通过文件查找安装包安装缺少libstdc++6这个文件在ls /usr/lib/libstd*下有两个文件/usr/lib/libstdc++.so.6 /usr/lib/libstdc++.so.6 ...

  8. linux下文件查找工具--find

    常用的文件查找命令有:which,locate,find 1.which命令 查找二进制数或二进制命令,由PATH给出 2.loacte 特点: 1.非实时,每天在系统上生成数据库,通过数据库查询 2 ...

  9. linux中文件查找、whereis、which、输出命令

    1.文件查找(find):find是最常⻅和最强⼤的查找命令 格式:find / -name  文件名,比如:find / -name mysql.  (1).模糊查找:*是代表所有的,?是代表⼀个字 ...

随机推荐

  1. golang开发:类库篇(二) Redis连接池的使用

    为什么要使用连接池 一个数据库服务器只拥有有限的连接资源,一旦所有的连接资源都在使用,那么其它需要连接的资源就只能等待释放连接资源.所以,在连接资源有限的情况下,提高单位时间的连接的使用效率,缩短连接 ...

  2. cocopods新建或者更新远端库主要操作步骤

    1.搭建远程仓库(私有或者公有项目): 2.使用sourceTree拉去远程仓库: 3.打开拉去的项目仓库Finder,构建pod lib项目:pod lib create AFNetworking( ...

  3. FluentValidation:一个非常受欢迎的,用于构建强类型验证规则的.NET 库

    1. FluentValidation:一个非常受欢迎的,用于构建强类型验证规则的.NET 库 请求参数实体定义: FluentValidation 验证类定义: 过滤器:ActionFilter中O ...

  4. scrapy实战7爬取搜狗微信:

    爬取微信热门文章标题,内容,内容地址,微信公众号,公众号地址,发布日期等 如图 源码地址:https://github.com/huwei86/sougouweixin

  5. 在eclipse中使用git创建本地库,以及托管项目到GitHub超详细教程

    关于安装git的教程,由于比较简单,并且网上教程特别多,而且即使不按照网上教程,下载好的windows版本git,安装时候一路默认设置就行. 安装好之后,在桌面上有git图标:右键菜单中有Git Ba ...

  6. CS程序和BS程序文字转语音

    一.项目中一直用到了文字转语音的功能,需求也比较简单,就是将一段报警信息通过语音的方式播放出来,之前一直采用CS客户端,利用微软自带的Speech语音播放库就可以完成, 1.1 封装winSpedk类 ...

  7. 【全网首发】使用vs2017+qt5.12.4编译64位debug和release的qgis3.4.9

    一.摘要: 搜索网络没有发现一篇文章完整的介绍如何编译qgis3.4.x的debug版本,官方的指导也长时间不再更新. 所以前前后后花了4天搞定qgis的debug编译,并成功运行,废话不多说,直接上 ...

  8. c++学习书籍推荐《C++ GUI Qt 4编程(第2版)》下载

    下载地址:点我 百度云及其他网盘下载地址:点我 编辑推荐 <C++ GUI Qt 4编程(第2版)>讲授的大量Qt4编程原理和实践,都可以轻易将其应用于Qt4.4.Qt4.5及后续版本的Q ...

  9. AWS S3 上传文件

    一.获取签名的URL 通过后端给的接口拿到已经签名好的文件上传的URL地址 二.读取文件(注:AWS 接受的二进制,不能使用form-data) // 获取文件二进制 getFileMd5 = (ke ...

  10. 番外:深浅copy

    进击のpython 深浅copy copy是什么意思? 复制 (又学一个单词!开不开森) 那啥叫复制呢? 百度百科上给的解释是:仿原样品制造 我们曾经有过这样的印象 a = "zhangsa ...