CentOS 文件管理命令(3)
source link: https://blog.51cto.com/baicia/5146120
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
文件过滤命令
|:管道符
# 作用:将管道符左边命令的标准输出,交给管道符右边命令的标准输入来处理
grep:过滤输出内容
## 符号
^:以...开头
$:以...结尾
*:匹配*前面的内容至少0次或多次
.:匹配任意字符
## 举例
^:以...开头
[root@localhost ~]# cat shi.txt
客从远方来,遗我一端绮。
相去万余里,故人心尚尔。
文采双鸳鸯,裁为合欢被。
著以长相思,缘以结不解。
以胶投漆中,谁能别离此?
[root@localhost ~]# grep '^客' shi.txt
客从远方来,遗我一端绮。
[root@localhost ~]# grep '^相' shi.txt
相去万余里,故人心尚尔。
$:以...结尾
root@localhost ~]# grep '。$' shi.txt
客从远方来,遗我一端绮。
相去万余里,故人心尚尔。
文采双鸳鸯,裁为合欢被。
著以长相思,缘以结不解。
[root@localhost ~]# grep '此?$' shi.txt
以胶投漆中,谁能别离此?
*:匹配*前面的内容至少0次或多次
[root@localhost ~]# grep '鸳鸯*' shi.txt
文采双鸳鸯,裁为合欢被。
[root@localhost ~]# grep '**' shi.txt
客从远方来,遗我一端绮。
相去万余里,故人心尚尔。
文采双鸳鸯,裁为合欢被。
著以长相思,缘以结不解。
以胶投漆中,谁能别离此?
.:匹配任意字符
[root@localhost ~]# grep '客.' shi.txt
客从远方来,遗我一端绮。
## 选项
-n:打印行号 number
-A:after 查看过滤内容的后N行
-B:before 查看过滤内容的前N行
-C:center 查看过滤内容的前、后N行
-v:取反
-E:可以过滤多个结果
-o:只打印出过滤内容
-i:不区分大小写
## 举例
-n:打印行号 number
[root@localhost ~]# grep -n '文' shi.txt
3:文采双鸳鸯,裁为合欢被。
[root@localhost ~]# grep -n '谁' shi.txt
5:以胶投漆中,谁能别离此?
-A:after 查看过滤内容的后N行
root@localhost ~]# grep -A 2 '故' shi.txt
相去万余里,故人心尚尔。
文采双鸳鸯,裁为合欢被。
著以长相思,缘以结不解。
[root@localhost ~]# grep -A 1 '为' shi.txt
文采双鸳鸯,裁为合欢被。
著以长相思,缘以结不解。
-B:before 查看过滤内容的前N行
[root@localhost ~]# grep -B 1 '为' shi.txt
相去万余里,故人心尚尔。
文采双鸳鸯,裁为合欢被。
[root@localhost ~]# grep -B 2 '故' shi.txt
客从远方来,遗我一端绮。
相去万余里,故人心尚尔。
-C:center 查看过滤内容的前、后N行(只能取均值)
[root@localhost ~]# grep -C 1 '故' shi.txt
客从远方来,遗我一端绮。
相去万余里,故人心尚尔。
文采双鸳鸯,裁为合欢被。
[root@localhost ~]# grep -C 2 '裁' shi.txt
客从远方来,遗我一端绮。
相去万余里,故人心尚尔。
文采双鸳鸯,裁为合欢被。
著以长相思,缘以结不解。
以胶投漆中,谁能别离此?
-v:取反
[root@localhost ~]# grep -v '裁' shi.txt
客从远方来,遗我一端绮。
相去万余里,故人心尚尔。
著以长相思,缘以结不解。
以胶投漆中,谁能别离此?
[root@localhost ~]# grep -v '客从远方来,' shi.txt
相去万余里,故人心尚尔。
文采双鸳鸯,裁为合欢被。
著以长相思,缘以结不解。
以胶投漆中,谁能别离此?
-E:可以过滤多个结果
[root@localhost ~]# grep -E '客从远|相去' shi.txt
客从远方来,遗我一端绮。
相去万余里,故人心尚尔。
-o:只打印出过滤内容
[root@localhost ~]# grep -o '客从远' shi.txt
客从远
[root@localhost ~]# grep -Eo '客从远|相去' shi.txt
客从远
相去
[root@localhost ~]# grep -o '故人' shi.txt
故人
-i:不区分大小写
root@localhost ~]# grep -i b /etc/sysconfig/network-scripts/ifcfg-ens33
BROWSER_ONLY="no"
BOOTPROTO="none"
IPV6_ADDR_GEN_MODE="stable-privacy"
UUID="3b3331d7-f120-4ff1-92e0-e81c80dcd4fe"
ONBOOT="yes
Recommend
-
9
centos安装tailf命令 作者: wencst 分类: linux 发布时间: 2020-06-22 21:53 阅读: 1,247 次 /* tailf...
-
14
1systemctl start firewalld.service1systemctl stop firewalld.service1systemctl restart firewalld.service12345...
-
0
CentOS 文件管理(2) 原创 白菜素三鲜丶 2022-03-23 17:08:10 ©著作权...
-
3
文件管理命令 原创 酱油拌饭 2022-03-23 18:34:50 ©著作权...
-
4
1. 通用基础知识 查询指令命令help,通过指令名 --help或者man 指令名。 例如,我们需要查询ls这个指令的参数用法以及作用,即通过ls --help即可得到...
-
5
wget 如何在CentOS 8安装wget命令 GNU Wget是一个命令行程序,用于从Web站点下载文件 ...
-
3
首页技术宅Centos使用pecl命令安装 PHP扩展 ,输入 php扩展 名称即可安装 Centos使用pecl命令安装 PHP扩展 ,输入 php扩展 名...
-
5
Redhat7/CentOS7 网络配置与管理(nmtui、nmcli、GNOME GUI、ifcfg文件、IP命令) 背景:作为系统管理员,需要经常处理主机网络问题,而配置与管理网络的方法和工具也有好几种,这里整理分享一下网络配置与管理的几种方式。 1、NetworkManager 概述...
-
1
首页技术宅CentOS/RedHat 与 Debian/Ubuntu 常用命令的区别 CentOS/RedHat 与 Debian/Ubuntu 常用命令的区别
-
3
五个应知应会的 Linux 文件和文件夹管理命令 作者:何威 2024-05-06 12:49:15 使用cd命令,可以在 Linux 文件系统层次结构中移动。然而,在某些时候,可能需要知道所在的目录,而终端不会给任何线索。
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK