一、文件查找

(一)、命令文件

[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. PHP学习(1)

  2. 设计模式-解释器模式(Interpreter)

    解释器模式是行为型模式的一种.给定一个语言(如由abcdef六个字符组成的字符串集合),定义它的文法的一种表示(S::=abA*ef,A::=cd)并定义一个解释器,解释器使用该表示来解释语言中的句子 ...

  3. Codeforces 777D:Cloud of Hashtags(水题)

    http://codeforces.com/problemset/problem/777/D 题意:给出n道字符串,删除最少的字符使得s[i] <= s[i+1]. 思路:感觉比C水好多啊,大概 ...

  4. jsp传值

    是由a1.jsp发出请求然后由a2.jsp转发给ok.jsp,由ok.jsp响应a1.jsp. 但是这个转发过程是在服务端发生的,客户端不知道所以地址是不变的 转发请求的代码: request.get ...

  5. Python与C/C++相互调用

    参考链接:https://www.cnblogs.com/yanzi-meng/p/8066944.html

  6. 网络下载器 Pan Download v2.0.5 Lite 绿色便携版

    下载地址:点我 基本介绍 PanDownload最新版是一款能够快速下载百度网盘内资源的强大工具.PanDownload最新版能够无限速高速下载,满速下载百度云盘里的各种资源.而且PanDownloa ...

  7. WPF 入门笔记之布局

    一.布局原则: 1. 不应显示的设定元素的尺寸,反而元素可以改变它的尺寸,并适应它们的内容 2. 不应使用平布的坐标,指定元素的位置. 3. 布局容器和它的子元素是共享可以使用的空间 4. 可以嵌套的 ...

  8. Linux系统下word转pdf,xls转pdf,ppt转pdf

    word转换pdf的技术方案,供参考.[doc/docx/ppt/pptx/xls/xlsx均支持转换]           本方案是Java结合shell命令完成,不同于以往的仅依赖java组件转换 ...

  9. 【基础算法-模拟-例题-金币】-C++

    原题链接:P2669 金币 这道题目完全是一道模拟题,只要按照题目中的加金币的算法和sum累加就可以很轻易得出最终答案. 说一下有一些点需要注意: 1.用i来计每天发的金币数,n来计已经拿了金币的天数 ...

  10. OnCommandStateChange 不响应

    原因是我把原先的OnCommandStateChange( long nCommand, BOOL bEnable )大BOOL改成了小bool,回调不认识了.