查找以ini结尾的文件
[root@iZj6cbstl2n6r280a27eppZ app]# find / -name "*.ini"
/app/myblog/config.ini

exec解释:
-exec 参数后面跟的是 command 命令,它的终止是以';'为结束标志的,所以这句命令后面的分号是不可缺少的,考虑到各个系统中分号会有不同的意义,所以前面加反斜杠。
{} 花括号代表前面find查找出来的文件名。

查找 /imes/ffdc文件下的txt文件,并以时间排序。

[root@tavli19 ~]# find /imes/ffdc -name "*.txt"|xargs ls -lta

-path 可以使用通配符来匹配文件路径。-name用给定的文件名进行匹配,-path则将文件路径作为一个整体进行匹配。

[root@SSAVL2734 ansible]# find /usr/lib/nagios/libexec/ -path "*/wechat_oms/*"
/usr/lib/nagios/libexec/wechat_oms/sendmail_weather.py
/usr/lib/nagios/libexec/wechat_oms/connectunix.py
/usr/lib/nagios/libexec/wechat_oms/checktablespace_multiple.py
/usr/lib/nagios/libexec/wechat_oms/connectoracle.py
/usr/lib/nagios/libexec/wechat_oms/.git

查找 /usr/lib/nagios/libexec下面  包含.py和.sh的文件

[root@SSAVL2734 ansible]# find /usr/lib/nagios/libexec/ -regex ".*\(\.py\|\.sh\)$"
/usr/lib/nagios/libexec/check_mysql_formal2.py
/usr/lib/nagios/libexec/check_oracle.py
/usr/lib/nagios/libexec/check_note_balance2.py
/usr/lib/nagios/libexec/check_note_balance.py
/usr/lib/nagios/libexec/checkbyjdbc/makefile.sh
/usr/lib/nagios/libexec/checkbyjdbc/Samples.sh

查找/usr/lib/nagios下面子目录下的包含py和sh的文件

[root@SSAVL2734 ansible]# find /usr/lib/nagios -maxdepth 2 -regex ".*\(\.py\|\.sh\)$"
/usr/lib/nagios/plugins/check_tomcat.py
/usr/lib/nagios/plugins/check_tomcat_threadpool_uname.py
/usr/lib/nagios/plugins/check_tomcatSessions.sh
/usr/lib/nagios/plugins/check_tomcat_memory.py
/usr/lib/nagios/plugins/check_tomcat_threadpool.py
/usr/lib/nagios/plugins/utils.sh

/usr/lib/nagios/libexec/check_procedure.py
/usr/lib/nagios/libexec/check_oracle_test.py

find 命令匹配到了当前目录下的所有普通文件,并在 -exec 选项中使用 ls -l 命令将它们列出。
[root@iZj6cbstl2n6r280a27eppZ tmp]# find . -type f -exec ls '{}' ';'
./pip-mQo5bs-unpack/uwsgi-2.0.15.tar.gz
./pip-VnYL06-unpack/Mezzanine-4.2.3-py2.py3-none-any.whl
./pip-RKCLec-unpack/Pygments-2.2.0-py2.py3-none-any.whl

[root@iZj6cbstl2n6r280a27eppZ tmp]# find . -type f -exec ls -l {} \;
-rw-r--r-- 1 root root 10240 9月 12 21:15 ./pip-mQo5bs-unpack/uwsgi-2.0.15.tar.gz
-rw-r--r-- 1 root root 194560 9月 12 20:30 ./pip-VnYL06-unpack/Mezzanine-4.2.3-py2.py3-none-any.whl

在目录中查找更改时间在5天以前后缀为pl的文件并删除
[root@iZj6cbstl2n6r280a27eppZ tmp]# find . -name "*.pl" -mtime +5 -exec rm {} \;

给出删之前的提示:
[root@iZj6cbstl2n6r280a27eppZ tmp]# find . -name "*.pl" -ok rm {} \;

查找/etc目录下的passwd文件,然后匹配文字中是否有root
[root@iZj6cbstl2n6r280a27eppZ tmp]# find /etc/ -name "passwd" -exec grep "root" {} ';'
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin

匹配当前目录的log文件,然后将这些log文件拷贝到/app目录中
[root@iZj6cbstl2n6r280a27eppZ tmp]# find . -name "*.log" -exec cp {} /app \;

查找/etc目录下的文件包含127.0.0.1
[root@iZj6cbstl2n6r280a27eppZ app]# find /etc -name \* -type f -print |xargs grep "127.0.0.1"
[root@iZj6cbstl2n6r280a27eppZ app]# find /etc -type f -print |xargs grep "127.0.0.1"
/etc/ntp.conf:restrict 127.0.0.1
/etc/sysconfig/network-scripts/ifcfg-lo:IPADDR=127.0.0.1
/etc/security/access.conf:#+ : root : 127.0.0.1
/etc/postfix/main.cf:#debug_peer_list = 127.0.0.1
/etc/cloud/templates/hosts.redhat.tmpl:127.0.0.1 {{fqdn}} {{hostname}}
/etc/hosts:127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4

[root@iZj6cbstl2n6r280a27eppZ tmp]# ls
Aegis-<Guid(5A2C30A2-A87D-490A-9281-6765EDAD7CBA)> pip-bVOjXv-unpack pip-Ya5KyM-unpack
a.txt pip-HOQ99u-unpack pythondy.log
b.txt

将当前目录下所有的.txt文件变为.txt_bak
[root@iZj6cbstl2n6r280a27eppZ tmp]# find . -name "*.txt" -exec mv {} {}_bak \;
[root@iZj6cbstl2n6r280a27eppZ tmp]# ls
Aegis-<Guid(5A2C30A2-A87D-490A-9281-6765EDAD7CBA)> pip-bVOjXv-unpack pip-Ya5KyM-unpack
a.txt_bak pip-HOQ99u-unpack pythondy.log
b.txt_bak

[root@iZj6cbstl2n6r280a27eppZ tmp]# find . -type -exec grep hello '{}' ';' -print

shell三剑客之find的更多相关文章

  1. shell三剑客之grep

    背景 对于很多的测试人员来说,grep命令都很熟悉,用的最多的比如去查找指定的进程:ps -ef | grep *** ,其中***为进程名或进程号,这里我们只用到的grep的最基础功能-从标准输出中 ...

  2. shell三剑客之sed

    背景 sed(Stream Editor 流编辑器),作为三剑客的一份子,主要的功能有增删改查.为什么称之为"流"编辑器呢?大家知道:在Linux文件系统中,一切都可以作为文件来处 ...

  3. shell 三剑客之 awk

    awk 是shell 里的常用命令,非常强大!

  4. shell 三剑客之 sed

    sed 在shell 编程里也很常用,功能强大! 同grep一样,sed提供两种方式: 方式一:stdout | sed [option] "pattern command" 从文 ...

  5. shell 三剑客之 grep

    grep 的全称是 Globally search a Regular Expression and Print,是一种强大的文本搜索工具,它能使用特定模式匹配(包括正则表达式)搜索文本,并默认输出匹 ...

  6. Linux进阶之正则,shell三剑客(grep,awk,sed),cut,sort,uniq

    一.正则表达式:Regular Expression 正则表达式:正则表达式使用单个字符串来描述.匹配一系列符合某个句法规则的字符串.在很多文本编辑器里,正则表达式通常被用来检索.替换那些符合某个模式 ...

  7. shell 三剑客

    grep 过滤来自一个文件或标准输入匹配模式内容. 除了grep外,还有egrep.fgrep.egrep是grep的扩展,相当于grep -E.fgrep相当于grep -f,用的少. Usage: ...

  8. Shell三剑客之sed命令

    Sed简介 Sed是Stream Editor(流编辑器)缩写,是操作.过滤和转换文本内容的强大工具,常用功能有增删改查. Sed命令执行流程 Sed语法格式 Sed [option] ‘[匹配][处 ...

  9. Shell—三剑客(grep、sed、awk)

    grep命令详解 文本搜索工具,根据用户指定的“模式(pattern)”对目标文本进行过滤,显示被模式匹配到的行. 命令格式:grep  [options]  pattern  filename.gr ...

随机推荐

  1. day29 主机管理-堡垒机2-原生ssh会话记录

    day29课堂代码:https://github.com/liyongsan/git_class/tree/master/day29 课堂笔记: 通过原生Ssh 记录会话1. 在我们自己的堡垒机交互脚 ...

  2. MyCat入门指南

    入门篇 1.       安装 1.1从https://github.com/MyCATApache/Mycat-download下载压缩包 1.2解压缩后复制到相应目录下面,比如/usr/local ...

  3. window.history.go(-1);

    history是你浏览过的网页的url(简单的说就是网址)的集合,也就是你的浏览器里的那个历史记录.它在js里是一个内置对象,就跟document一样,它有自己的方法,go就是其中一个. 这个方法的参 ...

  4. 010——数组(十)compact extract in_array

    <?php /** 10 数组 compact extract in_array */ //compact() (紧凑的,简洁的) 将变量转换为数组,变量名为数组键名,变量值为数组的键值. /* ...

  5. CI框架CodeIgniter伪静态各种服务器设置

    Apache服务器.htaccess伪静态设置 RewriteEngine on RewriteCond $1 !^(index\\.php|system\\.php|images|skin|js|l ...

  6. C++中几个值得分析的小问题(1)

    下面3个小问题都是我认为C++ Beginner应该能够解答或辨别清楚的.希望我们能通过题目挖掘更多的信息,而不仅仅局限在解题.我最喜欢说的话:能力有限,所以作为抛砖引玉,希望共同讨论,指出错误. 另 ...

  7. is null 和=null的区别

    数据库中 null 表示 不可知,不确定 所以 判断都用 字段 is null的方式进行判断 而 = null .<> null 的判断结果,仍然是不可知,不确定,所以 不会返回任何结果. ...

  8. New Concept English there (9)

    31 65% Cats never fail to fascinate human beings. They can be friendly and affectionate towards huma ...

  9. PostgreSQL资料汇总

    慢慢积累一些有用的资料: https://postgrespro.ru

  10. SpringMVC札集(07)——JSON数据

    自定义View系列教程00–推翻自己和过往,重学自定义View 自定义View系列教程01–常用工具介绍 自定义View系列教程02–onMeasure源码详尽分析 自定义View系列教程03–onL ...