shell三剑客之find
查找以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的更多相关文章
- shell三剑客之grep
背景 对于很多的测试人员来说,grep命令都很熟悉,用的最多的比如去查找指定的进程:ps -ef | grep *** ,其中***为进程名或进程号,这里我们只用到的grep的最基础功能-从标准输出中 ...
- shell三剑客之sed
背景 sed(Stream Editor 流编辑器),作为三剑客的一份子,主要的功能有增删改查.为什么称之为"流"编辑器呢?大家知道:在Linux文件系统中,一切都可以作为文件来处 ...
- shell 三剑客之 awk
awk 是shell 里的常用命令,非常强大!
- shell 三剑客之 sed
sed 在shell 编程里也很常用,功能强大! 同grep一样,sed提供两种方式: 方式一:stdout | sed [option] "pattern command" 从文 ...
- shell 三剑客之 grep
grep 的全称是 Globally search a Regular Expression and Print,是一种强大的文本搜索工具,它能使用特定模式匹配(包括正则表达式)搜索文本,并默认输出匹 ...
- Linux进阶之正则,shell三剑客(grep,awk,sed),cut,sort,uniq
一.正则表达式:Regular Expression 正则表达式:正则表达式使用单个字符串来描述.匹配一系列符合某个句法规则的字符串.在很多文本编辑器里,正则表达式通常被用来检索.替换那些符合某个模式 ...
- shell 三剑客
grep 过滤来自一个文件或标准输入匹配模式内容. 除了grep外,还有egrep.fgrep.egrep是grep的扩展,相当于grep -E.fgrep相当于grep -f,用的少. Usage: ...
- Shell三剑客之sed命令
Sed简介 Sed是Stream Editor(流编辑器)缩写,是操作.过滤和转换文本内容的强大工具,常用功能有增删改查. Sed命令执行流程 Sed语法格式 Sed [option] ‘[匹配][处 ...
- Shell—三剑客(grep、sed、awk)
grep命令详解 文本搜索工具,根据用户指定的“模式(pattern)”对目标文本进行过滤,显示被模式匹配到的行. 命令格式:grep [options] pattern filename.gr ...
随机推荐
- jquery extend源码解析
$.extend(obj1,0bj2,{"name":"s","age":22}) //target 要拷贝到哪个对象上 // i 要执行拷 ...
- ansible入门六(roles)
一.什么场景下会用roles? 假如我们现在有3个被管理主机,第一个要配置成httpd,第二个要配置成php服务器,第三个要配置成MySQL服务器.我们如何来定义playbook? 第一个play用到 ...
- 更改gitlab默认端口
若linux服务器的80和8080端口都已经被使用,则需修改gitlab监听的端口 修改路径文件:vim /etc/gitlab/gitlab.rb 1.修改external_url 'http:// ...
- Docker的大坑小洼(一)
Docker的大坑小洼 Posted on March 2, 2015March 2, 2015 by 孙宏亮 Docker成为云计算领域的新宠儿已经是不争的事实,作为高速发展的开源项目,难免存在这样 ...
- Git添加远程库
body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...
- powershell -enc参数无法解码base64编码payload的解决方案
powershell的-enc参数允许传入一个base64编码过的powershell脚本字符串作为参数来执行该powershell脚本,该方法常被用于绕过杀毒软件的主动防御机制. 今天下午在做一个后 ...
- 20165202 2017-2018-2 《Java程序设计》第7周学习总结
20165202 2017-2018-2 <Java程序设计>第7周学习总结 教材学习内容总结 Ch11 连接MySQL数据库 下载JDBC-MySQL数据库驱动 加载JDBC-MySQL ...
- flash cc新建swc文件
- c++下使用邮槽实现进程间通信
Windows API提供了邮槽和命名管道两种机制来实现进程间通信,在这里使用C++实现邮槽. 邮槽是Windows提供的一种进程间单向通信的机制,进程中的一方只能读取(或写入)数据,而另一方只能写入 ...
- ffmpeg+EasyDSS流媒体服务器实现稳定的rtmp推流直播
本文转自EasyDarwin团队成员Alex的博客:http://blog.csdn.net/cai6811376/article/details/74783269 需求 在做EasyDSS开发时,总 ...