查找以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. DNS污染——domain name的解析被劫持了返回无效的ip

    看下dns污染: bash-3.2$ dig twitter.com +trace ; <<>> DiG 9.10.6 <<>> twitter.com ...

  2. 【zznu-2093】毁掉这颗二叉树

    题目描述 广寒宫下有株二叉树,树上共有n个节点,通过n-1条树枝连接,树下有一只玉兔,吴刚提着斧子站在一旁. 他恼恨一切同他争夺嫦娥的事物,所以他决定通过砍二叉树上的n-1条树枝来毁掉这颗二叉树. 妙 ...

  3. 十、dbms_shared_pool(提供了对共享池的一些过程和函数访问)

    1.概述 作用:提供了对共享池的一些过程和函数访问,它使用户可以显示共享池中的对象尺寸,绑定对象到共享池,清除绑定到共享池的对象.为了使用该包,必须运行dbmspool.sql脚本来建立该包. 2.包 ...

  4. 通过网页或Serverice远程系统网站(服务)所在服务器本地的应用程序(未成功)

    近日接了一个奇葩需求,内容如题. 实现过程中遇到一些问题,特将实现过程记录于此,供备忘及参考. 首先尝试了正常启动进程的方法,代码如下: public string RunSPApp() { Proc ...

  5. Linux(CentOS7)下发送邮件(使用Gmail作为发件服务器)

    参考下述文章的思路,补充了在Gmail上的相关设置 https://gist.github.com/ilkereroglu/aa6c868153d1c5d57cd8 1.安装mailx yum ins ...

  6. MetaPost使用

    简介 MetaPost是一种制图语言,由John D. Hobby开发. 如果你要学习它,可以去下面的网址看看. 官网:http://tug.org/metapost 权威手册:http://tug. ...

  7. JDBC的步骤

    使用jdbc步骤 a.导入数据库厂商提供的驱动程序(导入jar包) b.加载驱动程序 Class.forName("驱动程序类") c.获得连接 Connection conn=D ...

  8. js 要写严格模式

    js 为了能在移动端通用,要写严格模式: 这里多了个逗号,在pc上浏览器可以通过,但是在手机端就不能.

  9. MySQL存储引擎(engine:处理表的处理器)

    1.基本的操作命令: 1.查看所有存储引擎 show engines: 2.查看已有表的存储引擎: show create table 表名: 3.创建表指定的存储引擎 create table 表名 ...

  10. bytes 与 str的区别以及装换

    bytes 和 str 的区别: bytes 存储字节( 通常值在 range(0, 256)) str 存储unicode字符( 通常值在0~65535) bytes 与 str 的转换 编码(en ...