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 ...
随机推荐
- opengl:初次接触
1.概述 OpenGL(Open Graphics Library),开放的图形程序接口,是编程接口的规范,并不是像OpenCV那样是库.GLFW是开源的基于opengl标准的库,并且是跨平台的.其开 ...
- C++复习11.函数的高级特性
C++ 函数的高级特性 20131002 C++函数增加了重载(override), inline, const, virtual四种机制,重载和内联机制既可以用于全局函数,也可以用于类的成员函数.c ...
- nfc功能读写 demo
点此下载//这个demo是把这个程序作为一个手机启动选择的,只要一扫到卡片就会跳转到这个Activity. 只在当前Activity中有效参考:http://blog.csdn.net/zoeice/ ...
- Ubuntu12.04 中文输入法设置
1.ibus输入法 Ubuntu系统安装后已经自带了ibus输入法,在英语环境下默认不启动. 配置ibus自动启动可 以在ubuntu系统菜单上选择System(系统)--- Preferences( ...
- 《利用Python进行数据分析》笔记---第2章--来自bit.ly的1.usa.gov数据
写在前面的话: 实例中的所有数据都是在GitHub上下载的,打包下载即可. 地址是:http://github.com/pydata/pydata-book 还有一定要说明的: 我使用的是Python ...
- FFmpeg再学习 -- FFmpeg解码知识
继续看雷霄骅的 课程资料 - 基于FFmpeg+SDL的视频播放器的制作 前面用了五个篇幅来讲 FFmpeg,其主要目的是为实现将图片转视频的功能. 总的来说,对于 FFmepg 多少有一些了解了.但 ...
- select2切换事件如何生效
1.问题背景 利用select2生成可搜索下拉框,并且绑定切换事件:但是直接绑定change事件,发现不起作用 2.问题原因 <!DOCTYPE html> <html> &l ...
- 强化学习使用pygame模块的安装
当你正想运行强化学习的游戏时,突然提示没有安装pygame模块怎么办呢? 其实很简单,通过下面的命令,就可以安装: D:\AI\sample\tensorforce>pip install py ...
- MongoDB使用笔记
先创建目录,创建log文件,然后启动服务 cd /d D:\Program Files\MongoDB\Server\3.4\bin\ mongod.exe --dbpath d:\data\db - ...
- Graham扫描法
Graham扫描法求凸包的模板 运行之后可以得到存有凸包顶点的栈s和栈顶指针top,n代表总点数 这个模板我当时调了很久,主要难点有两个,一个是正确的极角排序,一个是出栈入栈的细节操作,逆时针扫描,这 ...