正则介绍_grep上& grep中 & grep下

在计算机科学中,对“正则表达式" 的定义是:它使用单个字符串来描述或匹配一系列符合某个句法规则的字符串。在不少文本编辑器或其余工具里,正则表达式一般用来检索和替换那些符合某个模式的文本内容。许多程序设计语言也都支持利用正则表达式进行字符串操做。对于系统管理员来说,正则表达式贯穿在咱们的平常运维工做中,不管是查找某个文档,仍是查询某个日志文件并分析其容,都会用到正则表达式。
其实正则表达式只是一种思想、一种表示方法。只要咱们使用的工具支持这种表示方法,那么这个工具就能够处理正则表达式的字符串。经常使用的工具备grep、sed、awk等,其中grep、sed和都是针对文本的行进行操做的。php

正则介绍_grep上
该命令的格式为:grep [-cinvABC]‘word’filenamehtml

经常使用的选项以下:
-c:表示打印符合要求的行数。
-i:表示不区分大小写。
-n:表示输出符合要求的行及其行号。
-v:表示打印不符合要求的行。
-r:遍历全部子目录。
-A:后面跟一个数字(有无空格均可以)。过滤出符合要求的行以及下面n行
-B:后面跟一个数字。过滤出符合要求的行以及上面n行
-C:后面跟一个数字。过滤出符合要求的行以及上面n行。java

grep中
方括号[ ]:匹配方括号里任意一个字符node



^x:匹配以x开头的字符linux

[^xyz]:非,匹配除方括号里xyz以外的任意字符串web

^[^xyz]:匹配以除方括号里xyz以外的任意字符开头的字符
点 .:匹配任意一字符
*:匹配星号左边的字符重复0到n次的字符串。
.*:表示零个或多个任意字符,空行也包含再内。
会把passwd文件里面的全部行都匹配到。正则表达式

grep下express

花括号 x\{ n\}:字符x重复n次。
x\{ n,m\}:字符x重复n-m次
egrep:是grep的扩展版本,能够完成grep不能完成的工做,能够不使用字符 \
grep –E 跟egrep使用效果同样
+:匹配加号左边的字符重复1到n次的字符串。
?:问号前面的字符重复的次数是0或者1。
|:或者apache

grep ‘[0-9]’ passwd #把passwd文件中含有数字的行过滤打印出来vim

grep ‘^#’ shadow #把shadow文件中以“#”号开头的行过滤打印出来

grep –v ‘^#’ shadow #把shadow文件中不以“#”开头的行过滤打印出来

grep ‘^[^0-9]’ shadow #把shadow文件中以非数字开头的行过滤打印出来

grep‘r.o'passwd#把passwd文件中r在前o在尾中间任意字符的字符串过滤打印出来

grep ‘o*o’passwd #把passwd文件中o重复n次且以o结尾的字符串过滤打印出来

grep ‘.*’ passwd #把passwd文件中任意字符创过滤打印出来

grep ‘o\{2\}’ passwd #把passwd文件中含有两个o的字符串过滤打印出来

egrep ‘o{2}’ passwd====grep ‘o\{2\}’passwd====grep –E ‘o{2}’ passwd

grep ‘o+o’ passwd #把passwd文件中o开头o结尾的字符串过滤打印出来

grep‘o?t’passwd #把passwd文件中有或者没有o开头以t结尾的字符过滤打印出来

egrep‘root|nologin’passwd #把passwd文件中匹配root或者nologin的字符
============================================================================================================================================================================================================
grep命令:
文件过滤分割与合并

grep(global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来。

选项
-a 不要忽略二进制数据。
-A<显示列数> 除了显示符合范本样式的那一行以外,并显示该行以后的内容。
-b 在显示符合范本样式的那一行以外,并显示该行以前的内容。
-c 计算符合范本样式的列数。
-C<显示列数>或-<显示列数> 除了显示符合范本样式的那一列以外,并显示该列以前后的内容。
-d<进行动做> 当指定要查找的是目录而非文件时,必须使用这项参数,不然grep命令将回报信息并中止动做。
-e<范本样式> 指定字符串做为查找文件内容的范本样式。
-E 将范本样式为延伸的普通表示法来使用,意味着使用能使用扩展正则表达式。
-f<范本文件> 指定范本文件,其内容有一个或多个范本样式,让grep查找符合范本条件的文件内容,格式为每一列的范本样式。
-F 将范本样式视为固定字符串的列表。
-G 将范本样式视为普通的表示法来使用。
-h 在显示符合范本样式的那一列以前,不标示该列所属的文件名称。
-H 在显示符合范本样式的那一列以前,标示该列的文件名称。
-i 忽略字符大小写的差异。
-l 列出文件内容符合指定的范本样式的文件名称。
-L 列出文件内容不符合指定的范本样式的文件名称。
-n 在显示符合范本样式的那一列以前,标示出该列的编号。
-q 不显示任何信息。
-R/-r 此参数的效果和指定“-d recurse”参数相同。
-s 不显示错误信息。
-v 反转查找。
-w 只显示全字符合的列。
-x 只显示全列符合的列。
-y 此参数效果跟“-i”相同。
-o 只输出文件中匹配到的部分。
grep命令常见用法
在文件中搜索一个单词,命令会返回一个包含“match_pattern”的文本行:

grep match_pattern file_name
grep "match_pattern" file_name
在多个文件中查找:

grep "match_pattern" file_1 file_2 file_3 ...
输出除以外的全部行 -v 选项:

grep -v "match_pattern" file_name
标记匹配颜色 --color=auto 选项:

grep "match_pattern" file_name --color=auto
使用正则表达式 -E 选项:

grep -E "[1-9]+"

egrep "[1-9]+"
只输出文件中匹配到的部分 -o 选项:

echo this is a test line. | grep -o -E "[a-z]+\."
line.

echo this is a test line. | egrep -o "[a-z]+\."
line.
统计文件或者文本中包含匹配字符串的行数 -c 选项:

grep -c "text" file_name
输出包含匹配字符串的行数 -n 选项:

grep "text" -n file_name

cat file_name | grep "text" -n

#多个文件
grep "text" -n file_1 file_2
打印样式匹配所位于的字符或字节偏移:

echo gun is not unix | grep -b -o "not"
7:not

#一行中字符串的字符便宜是从该行的第一个字符开始计算,起始值为0。选项 -b -o 通常老是配合使用。
搜索多个文件并查找匹配文本在哪些文件中:

grep -l "text" file1 file2 file3...
grep递归搜索文件
在多级目录中对文本进行递归搜索:

grep "text" . -r -n
# .表示当前目录。
忽略匹配样式中的字符大小写:

echo "hello world" | grep -i "HELLO"
hello
选项 -e 制动多个匹配样式:

echo this is a text line | grep -e "is" -e "line" -o
is
line

#也可使用-f选项来匹配多个样式,在样式文件中逐行写出须要匹配的字符。
cat patfile
aaa
bbb

echo aaa bbb ccc ddd eee | grep -f patfile -o
在grep搜索结果中包括或者排除指定文件:

#只在目录中全部的.php和.html文件中递归搜索字符"main()"
grep "main()" . -r --include *.{php,html}

#在搜索结果中排除全部README文件
grep "main()" . -r --exclude "README"

#在搜索结果中排除filelist文件列表里的文件
grep "main()" . -r --exclude-from filelist
使用0值字节后缀的grep与xargs:

#测试文件:
echo "aaa" > file1
echo "bbb" > file2
echo "aaa" > file3

grep "aaa" file* -lZ | xargs -0 rm

#执行后会删除file1和file3,grep输出用-Z选项来指定以0值字节做为终结符文件名(\0),xargs -0 读取输入并用0值字节终结符分隔文件名,而后删除匹配文件,-Z一般和-l结合使用。
grep静默输出:

grep -q "test" filename

#不会输出任何信息,若是命令运行成功返回0,失败则返回非0值。通常用于条件测试。
打印出匹配文本以前或者以后的行:

#显示匹配某个结果以后的3行,使用 -A 选项:
seq 10 | grep "5" -A 3
5
6
7
8

#显示匹配某个结果以前的3行,使用 -B 选项:
seq 10 | grep "5" -B 3
2
3
4
5

#显示匹配某个结果的前三行和后三行,使用 -C 选项:
seq 10 | grep "5" -C 3
2
3
4
5
6
7
8

#若是匹配结果有多个,会用“--”做为各匹配结果之间的分隔符:
echo -e "a\nb\nc\na\nb\nc" | grep a -A 1
a
b
--
a
b

============================================================================================================================================================================================================
egrep命令:

文件过滤分割与合并

egrep命令用于在文件内查找指定的字符串。egrep执行效果与grep -E类似,使用的语法及参数可参照grep指令,与grep的不一样点在于解读字符串的方法。egrep是用extended regular expression语法来解读的,而grep则用basic regular expression 语法解读,extended regular expression比basic regular expression的表达更规范。

语法
egrep(选项)(查找模式)(文件名1,文件名2,……)
实例
显示文件中符合条件的字符。例如,查找当前目录下全部文件中包含字符串"Linux"的文件,可使用以下命令:

egrep Linux *
结果以下所示:

#如下五行为 testfile 中包含Linux字符的行
testfile:hello Linux!
testfile:Linux is a free Unix-type operating system.
testfile:This is a Linux testfile!
testfile:Linux
testfile:Linux

#如下两行为testfile1中含Linux字符的行
testfile1:helLinux!
testfile1:This a Linux testfile!

#如下两行为 testfile_2 中包含Linux字符的行
testfile_2:Linux is a free unix-type opterating system
testfile_2:Linux test

============================================================================================================================================================================================================

测试::::

[root@pantinglinux]# ls
1.txt 234 aa.txt anaconda-ks.cfg.1 新建文本文档_(2).txt
[root@pantinglinux]# mkdir grep
[root@pantinglinux]# cd grep/
[root@pantinglinux]# cp /etc/passwd .
[root@pantinglinux]# ls
passwd
[root@pantinglinux]# pwd
/root/grep
[root@pantinglinux]# ls
passwd
[root@pantinglinux]# grep 'nologin' passwd 
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:998:996:User for polkitd:/:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
chrony:x:997:995::/var/lib/chrony:/sbin/nologin
adkxx1:x:1006:1001::/home/adkxx:/sbin/nologin
[root@pantinglinux]# which grep 
alias grep='grep --color=auto'
/usr/bin/grep
[root@pantinglinux]# /usr/bin/grep 'nologin' passwd 
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:998:996:User for polkitd:/:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
chrony:x:997:995::/var/lib/chrony:/sbin/nologin
adkxx1:x:1006:1001::/home/adkxx:/sbin/nologin
[root@pantinglinux]# grep -c 'nologin' passwd 
18
[root@pantinglinux]# grep -n 'nologin' passwd 
2:bin:x:1:1:bin:/bin:/sbin/nologin
3:daemon:x:2:2:daemon:/sbin:/sbin/nologin
4:adm:x:3:4:adm:/var/adm:/sbin/nologin
5:lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
9:mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
10:operator:x:11:0:operator:/root:/sbin/nologin
11:games:x:12:100:games:/usr/games:/sbin/nologin
12:ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
13:nobody:x:99:99:Nobody:/:/sbin/nologin
14:systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin
15:systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
16:dbus:x:81:81:System message bus:/:/sbin/nologin
17:polkitd:x:998:996:User for polkitd:/:/sbin/nologin
18:tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
19:postfix:x:89:89::/var/spool/postfix:/sbin/nologin
20:sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
21:chrony:x:997:995::/var/lib/chrony:/sbin/nologin
24:adkxx1:x:1006:1001::/home/adkxx:/sbin/nologin
[root@pantinglinux]# vim passwd 
[root@pantinglinux]# grep -ni 'nologin' passwd 
3:daemon:x:2:2:daemon:/sbin:/sbin/nologin
4:adm:x:3:4:adm:/var/adm:/sbin/nologin
5:lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
9:mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
10:operator:x:11:0:operator:/root:/sbin/nologin
11:games:x:12:100:games:/usr/games:/sbin/nologin
12:ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
13:nobody:x:99:99:Nobody:/:/sbin/nologin
14:systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin
15:systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
16:dbus:x:81:81:System message bus:/:/sbin/nologin
17:polkitd:x:998:996:User for polkitd:/:/sbin/nologin
18:tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
19:postfix:x:89:89::/var/spool/postfix:/sbin/nologin
20:sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
21:chrony:x:997:995::/var/lib/chrony:/sbin/nologin
24:adkxx1:x:1006:1001::/home/adkxx:/sbin/nologin
[root@pantinglinux]# vim passwd 
[root@pantinglinux]# grep -ni 'nologin' passwd 
3:daemon:x:2:2:daemon:/sbin:/sbin/nologin
4:adm:x:3:4:adm:/var/adm:/sbin/nologin
5:lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
9:mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
10:operator:x:11:0:operator:/root:/sbin/nologin
11:games:x:12:100:games:/usr/games:/sbin/nologin
12:ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
13:nobody:x:99:99:Nobody:/:/sbin/nologin
14:systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin
15:systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
16:dbus:x:81:81:System message bus:/:/sbin/nologin
17:polkitd:x:998:996:User for polkitd:/:/sbin/nologin
18:tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
19:postfix:x:89:89::/var/spool/postfix:/sbin/nologin
20:sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
21:chrony:x:997:995::/var/lib/chrony:/sbin/nologin
24:adkxx1:x:1006:1001::/home/adkxx:/sbin/nologin
[root@pantinglinux]# vim passwd 
[root@pantinglinux]# grep -ni 'nologin' passwd 
2:bin:x:1:1:bin:/bin:/sbin/NOLOgin
3:daemon:x:2:2:daemon:/sbin:/sbin/nologin
4:adm:x:3:4:adm:/var/adm:/sbin/nologin
5:lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
9:mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
10:operator:x:11:0:operator:/root:/sbin/nologin
11:games:x:12:100:games:/usr/games:/sbin/nologin
12:ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
13:nobody:x:99:99:Nobody:/:/sbin/nologin
14:systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin
15:systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
16:dbus:x:81:81:System message bus:/:/sbin/nologin
17:polkitd:x:998:996:User for polkitd:/:/sbin/nologin
18:tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
19:postfix:x:89:89::/var/spool/postfix:/sbin/nologin
20:sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
21:chrony:x:997:995::/var/lib/chrony:/sbin/nologin
24:adkxx1:x:1006:1001::/home/adkxx:/sbin/nologin
[root@pantinglinux]# grep -vni 'nologin' passwd 
1:root:x:0:0:root:/root:/bin/bash
6:sync:x:5:0:sync:/sbin:/bin/sync
7:shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
8:halt:x:7:0:halt:/sbin:/sbin/halt
22:adkee:x:1000:1000::/home/adkee:/bin/bash
23:adkee1:x:1001:1002::/home/adkee1:/bin/bash
25:adkxx5:x:1007:1007::/home/adkxx5:/bin/bash
[root@pantinglinux]# grep -r 'root' /etc/
/etc/pki/ca-trust/ca-legacy.conf:# The upstream Mozilla.org project tests all changes to the root CA
/etc/pki/ca-trust/ca-legacy.conf:# to temporarily keep certain (legacy) root CA certificates trusted,
/etc/pki/ca-trust/ca-legacy.conf:# It may keep root CA certificate as trusted, which the upstream 
/etc/pki/ca-trust/extracted/README:root CA certificates.
/etc/pki/ca-trust/extracted/java/README:root CA certificates.
匹配到二进制文件 /etc/pki/ca-trust/extracted/java/cacerts
/etc/pki/ca-trust/extracted/openssl/README:root CA certificates.
/etc/pki/ca-trust/extracted/pem/README:root CA certificates.
/etc/pki/tls/certs/make-dummy-cert: echo root@localhost.localdomain
/etc/pki/tls/openssl.cnf:dir = ./demoCA # TSA root directory
/etc/rpm/macros.perl:%define perl_br_testdir %{buildroot}%{perl_testdir}/%{cpan_dist_name} \
/etc/rpm/macros.perl:%defattr(-,root,root,-)\
/etc/yum/pluginconf.d/fastestmirror.conf:# as root).
/etc/aliases:postmaster: root
/etc/aliases:bin: root
/etc/aliases:daemon: root
/etc/aliases:adm: root
/etc/aliases:lp: root
/etc/aliases:sync: root
/etc/aliases:shutdown: root
/etc/aliases:halt: root
/etc/aliases:mail: root
/etc/aliases:news: root
/etc/aliases:uucp: root
/etc/aliases:operator: root
/etc/aliases:games: root
/etc/aliases:gopher: root
/etc/aliases:ftp: root
/etc/aliases:nobody: root
/etc/aliases:radiusd: root
/etc/aliases:nut: root
/etc/aliases:dbus: root
/etc/aliases:vcsa: root
/etc/aliases:canna: root
/etc/aliases:wnn: root
/etc/aliases:rpm: root
/etc/aliases:nscd: root
/etc/aliases:pcap: root
/etc/aliases:apache: root
/etc/aliases:webalizer: root
/etc/aliases:dovecot: root
/etc/aliases:fax: root
/etc/aliases:quagga: root
/etc/aliases:radvd: root
/etc/aliases:pvm: root
/etc/aliases:amandabackup: root
/etc/aliases:privoxy: root
/etc/aliases:ident: root
/etc/aliases:named: root
/etc/aliases:xfs: root
/etc/aliases:gdm: root

etc/postfix/master.cf:# service type private unpriv chroot wakeup maxproc command + args
/etc/audit/auditd.conf:log_group = root
/etc/audit/auditd.conf:action_mail_acct = root
/etc/sudoers:## the root user, without needing the root password.
/etc/sudoers:## Allow root to run any commands anywhere
/etc/sudoers:root ALL=(ALL) ALL
/etc/sudoers:## cdrom as root
匹配到二进制文件 /etc/aliases.db
匹配到二进制文件 /etc/.profile.swp
/etc/updatedb.conf:PRUNEFS = "9p afs anon_inodefs auto autofs bdev binfmt_misc cgroup cifs coda configfs cpuset debugfs devpts ecryptfs exofs fuse fuse.sshfs fusectl gfs gfs2 gpfs hugetlbfs inotifyfs iso9660 jffs2 lustre mqueue ncpfs nfs nfs4 nfsd pipefs proc ramfs rootfs rpc_pipefs securityfs selinuxfs sfs sockfs sysfs tmpfs ubifs udf usbfs"
匹配到二进制文件 /etc/.fstab.swp
[root@pantinglinux]# grep 'root' /etc/
grep: /etc/: 是一个目录
[root@pantinglinux]# grep 'root' /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@pantinglinux]# grep 'root' /etc/ > /
.autorelabel etc/ media/ root/ sys/
bin/ home/ mnt/ run/ tmp/
boot/ lib/ opt/ sbin/ usr/
dev/ lib64/ proc/ srv/ var/
[root@pantinglinux]# grep 'root' /etc/ > /
.autorelabel etc/ media/ root/ sys/
bin/ home/ mnt/ run/ tmp/
boot/ lib/ opt/ sbin/ usr/
dev/ lib64/ proc/ srv/ var/
[root@pantinglinux]# grep 'root' /etc/ > /
.autorelabel etc/ media/ root/ sys/
bin/ home/ mnt/ run/ tmp/
boot/ lib/ opt/ sbin/ usr/
dev/ lib64/ proc/ srv/ var/
[root@pantinglinux]# grep 'root' /etc/ > /tmp/passwd.log
grep: /etc/: 是一个目录
[root@pantinglinux]# grep -r 'root' /etc/ > /tmp/passwd.log 
[root@pantinglinux]# grep passwd /tmp/passwd.log 
/etc/passwd:root:x:0:0:root:/root:/bin/bash
/etc/passwd:operator:x:11:0:operator:/root:/sbin/nologin
/etc/passwd-:root:x:0:0:root:/root:/bin/bash
/etc/passwd-:operator:x:11:0:operator:/root:/sbin/nologin
/etc/postfix/main.cf:# the system passwd file in the chroot jail is just not practical.
[root@pantinglinux]# grep -A2 'root' passwd 
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/NOLOgin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
--
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
[root@pantinglinux]# grep -nA2 'root' passwd 
1:root:x:0:0:root:/root:/bin/bash
2-bin:x:1:1:bin:/bin:/sbin/NOLOgin
3-daemon:x:2:2:daemon:/sbin:/sbin/nologin
--
10:operator:x:11:0:operator:/root:/sbin/nologin
11-games:x:12:100:games:/usr/games:/sbin/nologin
12-ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
[root@pantinglinux]# grep -nB2 'root' passwd 
1:root:x:0:0:root:/root:/bin/bash
--
8-halt:x:7:0:halt:/sbin:/sbin/halt
9-mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
10:operator:x:11:0:operator:/root:/sbin/nologin
[root@pantinglinux]# grep -nC2 'root' passwd 
1:root:x:0:0:root:/root:/bin/bash
2-bin:x:1:1:bin:/bin:/sbin/NOLOgin
3-daemon:x:2:2:daemon:/sbin:/sbin/nologin
--
8-halt:x:7:0:halt:/sbin:/sbin/halt
9-mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
10:operator:x:11:0:operator:/root:/sbin/nologin
11-games:x:12:100:games:/usr/games:/sbin/nologin
12-ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
[root@pantinglinux]# grep '[0-9]' passwd 
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/NOLOgin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:998:996:User for polkitd:/:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
chrony:x:997:995::/var/lib/chrony:/sbin/nologin
adkee:x:1000:1000::/home/adkee:/bin/bash
adkee1:x:1001:1002::/home/adkee1:/bin/bash
adkxx1:x:1006:1001::/home/adkxx:/sbin/nologin
adkxx5:x:1007:1007::/home/adkxx5:/bin/bash
[root@pantinglinux]# grep -v '[0-9]' passwd 
[root@pantinglinux]# grep -v '[0-9]' /etc/inittab 
# inittab is no longer used when using systemd.
#
# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target
#
# systemd uses 'targets' instead of runlevels. By default, there are two main targets:
#
#
# To view current default target, run:
# systemctl get-default
#
# To set a default target, run:
# systemctl set-default TARGET.target
#
[root@pantinglinux]# grep -vn '[0-9]' /etc/inittab 
1:# inittab is no longer used when using systemd.
2:#
3:# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
4:#
5:# Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target
6:#
7:# systemd uses 'targets' instead of runlevels. By default, there are two main targets:
8:#
11:#
12:# To view current default target, run:
13:# systemctl get-default
14:#
15:# To set a default target, run:
16:# systemctl set-default TARGET.target
17:#
[root@pantinglinux]# vim /etc/inittab 
[root@pantinglinux]# grep -n '^#' /etc/inittab 
1:# inittab is no longer used when using systemd.
2:#
3:# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
4:#
5:# Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target
6:#
7:# systemd uses 'targets' instead of runlevels. By default, there are two main targets:
8:#
9:# multi-user.target: analogous to runlevel 3
10:# graphical.target: analogous to runlevel 5
11:#
12:# To view current default target, run:
13:# systemctl get-default
14:#
15:# To set a default target, run:
16:# systemctl set-default TARGET.target
17:#
[root@pantinglinux]#

 

相关文章
相关标签/搜索