四剑客_正则

news/2025/7/9 11:29:00/文章来源:https://www.cnblogs.com/daofaziran/p/18405162

1 四剑客

1.1 概述

1.2 find命令基本用法

1.2.1 找出/etc/目录下面以.conf结尾的文件⭐⭐⭐⭐⭐
[root@Kylin-V10-sp3 ~/test]# find /etc/ -type f -name *.conf | head -5
/etc/resolv.conf
/etc/dnf/protected.d/systemd.conf
/etc/dnf/protected.d/sudo.conf
/etc/dnf/protected.d/dnf.conf
/etc/dnf/protected.d/yum.conf
1.2.2 找出/etc/目录下面以.conf结尾的文件文件大小大于10k⭐⭐⭐⭐
[root@Kylin-V10-sp3 ~/test]# find /etc/ -type f -name *.conf -size +10k | head -5
/etc/lvm/lvm.conf
/etc/httpd/conf/httpd.conf
/etc/asciidoc/asciidoc.conf
/etc/asciidoc/docbook45.conf
/etc/asciidoc/docbook5.conf
1.2.3 找出/var/log下面以.log结尾的文件并且修改时间大于3天⭐⭐⭐⭐⭐
[root@Kylin-V10-sp3 ~/test]# find /etc/ -type f -name *.conf -mtime +3 | head -5
/etc/dnf/protected.d/systemd.conf
/etc/dnf/protected.d/sudo.conf
/etc/dnf/protected.d/dnf.conf
/etc/dnf/protected.d/yum.conf
/etc/dnf/plugins/copr.conf
1.2.4 查找文件或目录的时候不区分大小写⭐⭐⭐⭐⭐
[root@Kylin-V10-sp3 ~/test]# find /etc/ -iname *.conf | head -5  
/etc/resolv.conf
/etc/dnf/protected.d/systemd.conf
/etc/dnf/protected.d/sudo.conf
/etc/dnf/protected.d/dnf.conf
/etc/dnf/protected.d/yum.conf
1.2.5 根据深度查找文件
[root@Kylin-V10-sp3 ~/test]# find /etc/ -maxdepth 2 -type f -size +20k -name *.conf -mtime +3 | head -5
/etc/lvm/lvm.conf
/etc/asciidoc/docbook45.conf
/etc/asciidoc/docbook5.conf
/etc/asciidoc/html5.conf
/etc/asciidoc/xhtml11.conf
[root@Kylin-V10-sp3 ~/test]# 

1.3 find与其他命令配合

1.3.1 find找出文件后进行删除 ⭐⭐⭐⭐⭐
# 创建测试环境
[root@Kylin-V10-sp3 ~/test]# pwd
/root/test
[root@Kylin-V10-sp3 ~/test]# touch {01..10}.txt
[root@Kylin-V10-sp3 ~/test]# ll
total 8
-rw-r--r-- 1 root root    0 Sep  9 08:59 01.txt
-rw-r--r-- 1 root root    0 Sep  9 08:59 02.txt
-rw-r--r-- 1 root root    0 Sep  9 08:59 03.txt
-rw-r--r-- 1 root root    0 Sep  9 08:59 04.txt
-rw-r--r-- 1 root root    0 Sep  9 08:59 05.txt
-rw-r--r-- 1 root root    0 Sep  9 08:59 06.txt
-rw-r--r-- 1 root root    0 Sep  9 08:59 07.txt
-rw-r--r-- 1 root root    0 Sep  9 08:59 08.txt
-rw-r--r-- 1 root root    0 Sep  9 08:59 09.txt
-rw-r--r-- 1 root root    0 Sep  9 08:59 10.txt
[root@Kylin-V10-sp3 ~/test]# # 方法01: find与反引号 ⭐ ⭐ ⭐ ⭐ ⭐
[root@Kylin-V10-sp3 ~/test]# rm -f `find /root/test/ -type f -name '*.txt' `
[root@Kylin-V10-sp3 ~/test]# 
[root@Kylin-V10-sp3 ~/test]# ll
total 4
-rw-r--r-- 1 root root 1220 Sep  8 07:48 msg.log
[root@Kylin-V10-sp3 ~/test]# # 方法02: find 管道 ⭐ ⭐ ⭐ ⭐ ⭐
'''
| 与|xargs 区别
|传递的是字符串,文字符号
|xargs 传递是参数 命令后面文件,目录
'''
[root@Kylin-V10-sp3 ~/test]# touch {01..10}.txt
[root@Kylin-V10-sp3 ~/test]#   
[root@Kylin-V10-sp3 ~/test]# find /root/test/ -type f -name '*.txt' | xargs rm -f 
[root@Kylin-V10-sp3 ~/test]# 
[root@Kylin-V10-sp3 ~/test]# ll
total 4
-rw-r--r-- 1 root root 1220 Sep  8 07:48 msg.log
[root@Kylin-V10-sp3 ~/test]# # 方法03: find选项 -exec
'''
-exec 命令 {} \;
{} 前面find找出的文件内容
\; 结尾标记.
{} +   + 先执行前面命令执行完成,结果一次性通exec传递给后面命令.
'''
[root@Kylin-V10-sp3 ~/test]# touch {01..10}.txt
[root@Kylin-V10-sp3 ~/test]# 
[root@Kylin-V10-sp3 ~/test]# ll
total 4
-rw-r--r-- 1 root root    0 Sep  9 09:06 01.txt
-rw-r--r-- 1 root root    0 Sep  9 09:06 02.txt
-rw-r--r-- 1 root root    0 Sep  9 09:06 03.txt
-rw-r--r-- 1 root root    0 Sep  9 09:06 04.txt
-rw-r--r-- 1 root root    0 Sep  9 09:06 05.txt
-rw-r--r-- 1 root root    0 Sep  9 09:06 06.txt
-rw-r--r-- 1 root root    0 Sep  9 09:06 07.txt
-rw-r--r-- 1 root root    0 Sep  9 09:06 08.txt
-rw-r--r-- 1 root root    0 Sep  9 09:06 09.txt
-rw-r--r-- 1 root root    0 Sep  9 09:06 10.txt
-rw-r--r-- 1 root root 1220 Sep  8 07:48 msg.log
[root@Kylin-V10-sp3 ~/test]# 
[root@Kylin-V10-sp3 ~/test]# find /root/test/ -type f -name '*.txt' -exec rm -f {} +
[root@Kylin-V10-sp3 ~/test]# 
[root@Kylin-V10-sp3 ~/test]# ll
total 4
-rw-r--r-- 1 root root 1220 Sep  8 07:48 msg.log
[root@Kylin-V10-sp3 ~/test]# 
1.3.2 找出/etc/下以.conf结尾的文件与打包压缩/backup/ ⭐⭐⭐⭐⭐
# 方法01:find+反引号⭐ ⭐ ⭐ ⭐ ⭐
[root@Kylin-V10-sp3 /backup]# tar zcvf /backup/`date +%F_%w`.tar.gz `find /etc/ -type f -name '*.conf'`
# 检查压缩包
[root@Kylin-V10-sp3 /backup]# tar tf 2024-09-09_1.tar.gz# 方法02:find |xargs⭐ ⭐ ⭐ ⭐ ⭐
[root@Kylin-V10-sp3 /backup]# find /etc/ -type f -name '*.conf' | xargs tar zcvf /backup/`date +%F_%w`.tar.gz
[root@Kylin-V10-sp3 /backup]# ll
total 244
-rw-r--r-- 1 root root 151626 Sep  9 09:28 2024-09-09_1.tar.gz
-rw-r--r-- 1 root root  92160 Sep  8 06:45 etc_conf.tar.gz# 方法03: find -exec'''
有坑,用 {} \; 发现打包压缩后只有1个文件.
find 与-exe执行流程
find找出1个文件 exec执行1次命令
{} + + 先执行前面命令执行完成,结果一次性通exec传递给后面命令. 
'''[root@Kylin-V10-sp3 /backup]# find /etc/ -type f -name '*.conf' -exec tar zcvf /backup/`date +%F_%w`.tar.gz {} +
1.3.3 find命令与cp/mv
'''
背景:
开启yum缓存
vim /etc/yum.conf
keepcache=1 #开启缓存软件包功能
缓存/var/cache/yum目录 以.rpm结尾.find与|xargs传参
cp /backup/rpms/ 参数 ... . .. . . .
cp 文件 目录 目标(目录)
cp -t 目标(目录) 文件 目录
'''
#需求:把/var/cache/yum目录 以.rpm结尾,复制/移动到指定的目录/backup/rpms/方法01: find+反引号
[root@Kylin-V10-sp3 /backup/rpms]# cp `find /var/cache/yum/ -type f -name *.rpm` /backup/rpms/
[root@Kylin-V10-sp3 /backup/rpms]# ll
total 9068
-rw-r--r-- 1 root root  140704 Sep  9 09:41 createrepo_c-0.16.0-3.p01.ky10.x86_64.rpm
-rw-r--r-- 1 root root   60128 Sep  9 09:41 drpm-0.5.0-1.ky10.x86_64.rpm
-rw-r--r-- 1 root root  271828 Sep  9 09:41 gperftools-libs-2.8-1.ky10.x86_64.rpm
-rw-r--r-- 1 root root   56364 Sep  9 09:41 libunwind-1.3.1-3.ky10.x86_64.rpm
-rw-r--r-- 1 root root   83736 Sep  9 09:41 lrzsz-0.12.20-46.ky10.x86_64.rpm
-rw-r--r-- 1 root root  505932 Sep  9 09:41 nginx-1.21.5-2.p02.ky10.x86_64.rpm
-rw-r--r-- 1 root root    8248 Sep  9 09:41 nginx-all-modules-1.21.5-2.p02.ky10.noarch.rpm
-rw-r--r-- 1 root root    9288 Sep  9 09:41 nginx-filesystem-1.21.5-2.p02.ky10.noarch.rpm
-rw-r--r-- 1 root root   17808 Sep  9 09:41 nginx-mod-http-image-filter-1.21.5-2.p02.ky10.x86_64.rpm
-rw-r--r-- 1 root root   27480 Sep  9 09:41 nginx-mod-http-perl-1.21.5-2.p02.ky10.x86_64.rpm
-rw-r--r-- 1 root root   16504 Sep  9 09:41 nginx-mod-http-xslt-filter-1.21.5-2.p02.ky10.x86_64.rpm
-rw-r--r-- 1 root root   49608 Sep  9 09:41 nginx-mod-mail-1.21.5-2.p02.ky10.x86_64.rpm
-rw-r--r-- 1 root root   72068 Sep  9 09:41 nginx-mod-stream-1.21.5-2.p02.ky10.x86_64.rpm
-rw-r--r-- 1 root root 6146064 Sep  9 09:41 nmap-7.92-1.p01.ky10.x86_64.rpm
-rw-r--r-- 1 root root   64340 Sep  9 09:41 telnet-0.17-77.ky10.x86_64.rpm
-rw-r--r-- 1 root root   52192 Sep  9 09:41 tree-1.8.0-2.ky10.x86_64.rpm
-rw-r--r-- 1 root root 1664616 Sep  9 09:41 vim-enhanced-9.0-19.p03.ky10.x86_64.rpm
[root@Kylin-V10-sp3 /backup/rpms]# 方法02:find+|xargs
[root@Kylin-V10-sp3 /backup/rpms]# find /var/cache/yum/ -type f -name *.rpm | xargs cp -t /backup/rpms/
[root@Kylin-V10-sp3 /backup/rpms]# 
[root@Kylin-V10-sp3 /backup/rpms]# ll
total 9068
-rw-r--r-- 1 root root  140704 Sep  9 09:42 createrepo_c-0.16.0-3.p01.ky10.x86_64.rpm
-rw-r--r-- 1 root root   60128 Sep  9 09:42 drpm-0.5.0-1.ky10.x86_64.rpm
-rw-r--r-- 1 root root  271828 Sep  9 09:42 gperftools-libs-2.8-1.ky10.x86_64.rpm
-rw-r--r-- 1 root root   56364 Sep  9 09:42 libunwind-1.3.1-3.ky10.x86_64.rpm
-rw-r--r-- 1 root root   83736 Sep  9 09:42 lrzsz-0.12.20-46.ky10.x86_64.rpm
-rw-r--r-- 1 root root  505932 Sep  9 09:42 nginx-1.21.5-2.p02.ky10.x86_64.rpm
-rw-r--r-- 1 root root    8248 Sep  9 09:42 nginx-all-modules-1.21.5-2.p02.ky10.noarch.rpm
-rw-r--r-- 1 root root    9288 Sep  9 09:42 nginx-filesystem-1.21.5-2.p02.ky10.noarch.rpm
-rw-r--r-- 1 root root   17808 Sep  9 09:42 nginx-mod-http-image-filter-1.21.5-2.p02.ky10.x86_64.rpm
-rw-r--r-- 1 root root   27480 Sep  9 09:42 nginx-mod-http-perl-1.21.5-2.p02.ky10.x86_64.rpm
-rw-r--r-- 1 root root   16504 Sep  9 09:42 nginx-mod-http-xslt-filter-1.21.5-2.p02.ky10.x86_64.rpm
-rw-r--r-- 1 root root   49608 Sep  9 09:42 nginx-mod-mail-1.21.5-2.p02.ky10.x86_64.rpm
-rw-r--r-- 1 root root   72068 Sep  9 09:42 nginx-mod-stream-1.21.5-2.p02.ky10.x86_64.rpm
-rw-r--r-- 1 root root 6146064 Sep  9 09:42 nmap-7.92-1.p01.ky10.x86_64.rpm
-rw-r--r-- 1 root root   64340 Sep  9 09:42 telnet-0.17-77.ky10.x86_64.rpm
-rw-r--r-- 1 root root   52192 Sep  9 09:42 tree-1.8.0-2.ky10.x86_64.rpm
-rw-r--r-- 1 root root 1664616 Sep  9 09:42 vim-enhanced-9.0-19.p03.ky10.x86_64.rpm
[root@Kylin-V10-sp3 /backup/rpms]#方法03:find+ exec
[root@Kylin-V10-sp3 /backup/rpms]# rm -f *.rpm
[root@Kylin-V10-sp3 /backup/rpms]# 
[root@Kylin-V10-sp3 /backup/rpms]# ll
total 0
[root@Kylin-V10-sp3 /backup/rpms]# 
[root@Kylin-V10-sp3 /backup/rpms]# find /var/cache/yum/ -type f -name *.rpm -exec cp -t /backup/rpms/ {} +
[root@Kylin-V10-sp3 /backup/rpms]# 
[root@Kylin-V10-sp3 /backup/rpms]# ll
total 9068
-rw-r--r-- 1 root root  140704 Sep  9 09:44 createrepo_c-0.16.0-3.p01.ky10.x86_64.rpm
-rw-r--r-- 1 root root   60128 Sep  9 09:44 drpm-0.5.0-1.ky10.x86_64.rpm
-rw-r--r-- 1 root root  271828 Sep  9 09:44 gperftools-libs-2.8-1.ky10.x86_64.rpm
-rw-r--r-- 1 root root   56364 Sep  9 09:44 libunwind-1.3.1-3.ky10.x86_64.rpm
-rw-r--r-- 1 root root   83736 Sep  9 09:44 lrzsz-0.12.20-46.ky10.x86_64.rpm
-rw-r--r-- 1 root root  505932 Sep  9 09:44 nginx-1.21.5-2.p02.ky10.x86_64.rpm
-rw-r--r-- 1 root root    8248 Sep  9 09:44 nginx-all-modules-1.21.5-2.p02.ky10.noarch.rpm
-rw-r--r-- 1 root root    9288 Sep  9 09:44 nginx-filesystem-1.21.5-2.p02.ky10.noarch.rpm
-rw-r--r-- 1 root root   17808 Sep  9 09:44 nginx-mod-http-image-filter-1.21.5-2.p02.ky10.x86_64.rpm
-rw-r--r-- 1 root root   27480 Sep  9 09:44 nginx-mod-http-perl-1.21.5-2.p02.ky10.x86_64.rpm
-rw-r--r-- 1 root root   16504 Sep  9 09:44 nginx-mod-http-xslt-filter-1.21.5-2.p02.ky10.x86_64.rpm
-rw-r--r-- 1 root root   49608 Sep  9 09:44 nginx-mod-mail-1.21.5-2.p02.ky10.x86_64.rpm
-rw-r--r-- 1 root root   72068 Sep  9 09:44 nginx-mod-stream-1.21.5-2.p02.ky10.x86_64.rpm
-rw-r--r-- 1 root root 6146064 Sep  9 09:44 nmap-7.92-1.p01.ky10.x86_64.rpm
-rw-r--r-- 1 root root   64340 Sep  9 09:44 telnet-0.17-77.ky10.x86_64.rpm
-rw-r--r-- 1 root root   52192 Sep  9 09:44 tree-1.8.0-2.ky10.x86_64.rpm
-rw-r--r-- 1 root root 1664616 Sep  9 09:44 vim-enhanced-9.0-19.p03.ky10.x86_64.rpm
[root@Kylin-V10-sp3 /backup/rpms]# 
[root@Kylin-V10-sp3 /backup/rpms]# 

1.4 特殊符号之引号系列

四剑客命令单独记忆.

1.5 特殊符号之重定向符号系列

2 正则

2.1 为何使用正则

2.2 正则分类

2.3 基础正则

2.4 扩展正则

2.5 正则总结

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/794656.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

今日总结

今天进行了java代码的编写,我学会了很多,我认为我还有很多的不足 我要继续的学习java,我对它的了解还是不够的深

课堂测试

今天的题我没写出来,还是没学明白。之前的题仅仅只是看了看答案,没有自己尝试写一遍,导致今天调试的时候出现错误,最后没整出来,不开心

用Python实现阿拉伯数字转换成中国汉字

本文简要介绍了要将阿拉伯数字转换成中国汉字表示的数字的方法,我们需要一个映射表来转换每个数字,并且处理不同位数的数字(如十、百、千、万等),给出了详细的代码示例和解释。要将阿拉伯数字转换成中国汉字表示的数字,我们需要一个映射表来转换每个数字,并且处理不同位…

P1066

布什各门,阿? 令人惊奇的题解 标程:某个姓组合的数学+高精 here

springmvc配置静态资源访问-三种方式

https://blog.csdn.net/m0_47010003/article/details/124577219 另外: 添加 tomcat servlet web.xml<!--在conf/web.xml中的DefaultServlet的定义--> <servlet> <servlet-name>default</servlet-name> <servlet-class>org.apache.catalina.serv…

9.9日总结

今天上午有刘丹老师为我们讲述了数据结构这门课程的组成,其中主要是讲关于数据结构与算法之间的关系 下午便是java的开学考试,对于开学考试题目与放假之前所发题目类型相似,但数据量相对多一点,其次便是逻辑关系要稍微复杂一点,基本的功能相似并无太大出入 接下来将对代码…