国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Linux > 正文

Linux中g(shù)rep和egrep命令詳解

2024-08-28 00:02:17
字體:
供稿:網(wǎng)友

rep / egrep

語法: grep  [-cinvABC]  'word'  filename

-c :打印符合要求的行數(shù)
-i :忽略大小寫
-n :在輸出符合要求的行的同時(shí)連同行號(hào)一起輸出
-v :打印不符合要求的行
-A :后跟一個(gè)數(shù)字(有無空格都可以),例如 A2則表示打印符合要求的行以及下面兩行
-B :后跟一個(gè)數(shù)字,例如 B2 則表示打印符合要求的行以及上面兩行
-C :后跟一個(gè)數(shù)字,例如 C2 則表示打印符合要求的行以及上下各兩行

把包含 ‘halt' 的行以及這行下面的兩行都打印出。

[root@localhost ~]# grep -A2 'halt' /etc/passwdhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinuucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin

把包含 ‘halt' 的行以及這行上面的兩行都打印出。

[root@localhost ~]# grep -B2 'halt' /etc/passwdsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/halt

 

把包含 ‘halt' 的行以及這行上面和下面的各兩行都打印出。

過濾出帶有某個(gè)關(guān)鍵詞的行并輸出行號(hào) 

[root@localhost ~]# grep -n 'root' /etc/passwd1:root:x:0:0:root:/root:/bin/bash11:operator:x:11:0:operator:/root:/sbin/nologin

過濾不帶有某個(gè)關(guān)鍵詞的行,并輸出行號(hào) 

[root@localhost ~]# grep -nv 'nologin' /etc/passwd1:root:x:0:0:root:/root:/bin/bash6:sync:x:5:0:sync:/sbin:/bin/sync7:shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown8:halt:x:7:0:halt:/sbin:/sbin/halt26:test:x:511:511::/home/test:/bin/bash27:test1:x:512:511::/home/test1:/bin/bash

過濾出所有包含數(shù)字的行 

[root@localhost ~]# grep '[0-9]' /etc/inittab# upstart works, see init(5), init(8), and initctl(8).# 0 - halt (Do NOT set initdefault to this)# 1 - Single user mode# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)# 3 - Full multiuser mode# 4 - unused# 5 - X11# 6 - reboot (Do NOT set initdefault to this)id:3:initdefault:

過濾出所有不包含數(shù)字的行 

[root@localhost ~]# grep -v '[0-9]' /etc/inittab# inittab is only used by upstart for the default runlevel.## ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.## System initialization is started by /etc/init/rcS.conf## Individual runlevels are started by /etc/init/rc.conf## Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf## Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,# with configuration in /etc/sysconfig/init.## For information on how to write upstart event handlers, or how## Default runlevel. The runlevels used are:#

把所有以 ‘#' 開頭的行去除 

[root@localhost ~]# grep -v '^#' /etc/inittabid:3:initdefault:

去除所有空行和以 ‘#' 開頭的行 

[root@localhost ~]# grep -v '^#' /etc/crontab |grep -v '^$'SHELL=/bin/bashPATH=/sbin:/bin:/usr/sbin:/usr/binMAILTO=rootHOME=/
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 石狮市| 年辖:市辖区| 舟山市| 西乌珠穆沁旗| 蕉岭县| 莲花县| 通化市| 高阳县| 如皋市| 仁寿县| 洛扎县| 奇台县| 乌海市| 秦皇岛市| 南安市| 麦盖提县| 通州区| 绥滨县| 花莲县| 营山县| 临邑县| 贵德县| 偃师市| 神木县| 镇江市| 绍兴县| 辽阳县| 阳西县| 正蓝旗| 察哈| 贺兰县| 峨边| 武宣县| 黎城县| 宜兰市| 遵义县| 博客| 西藏| 鞍山市| 高雄市| 冀州市|