1. grep 过滤
grep
选项:
-n
-v
-c
-i
-o
-w
-r
-A
-B
-C
^
$
-E
|
^$
.
*
.*
[root@CentOS7 ~]
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@CentOS7 ~]
1:root:x:0:0:root:/root:/bin/bash
10:operator:x:11:0:operator:/root:/sbin/nologin
[root@CentOS7 ~]
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
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-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
[root@CentOS7 ~]
2
[root@CentOS7 ~]
root
roottt
oldboy
olirl
oldgirl
ROOT
[root@CentOS7 ~]
root
roottt
ROOT
[root@CentOS7 ~]
root
root
root
root
[root@CentOS7 ~]
root
roottt
[root@CentOS7 ~]
root
[root@CentOS7 ~]
./.bash_history:find root
./.bash_history:find /root/
./.bash_history:find /root -type f
./.bash_history:find /root -type f -name "^.txt"
./.bash_history:[root@CentOS7 ~]
./.bash_history:-rw-r--r--. 1 root root 38607 Jul 9 2013 7f6f8291jw1ee8c5j55rzj21hc0u0gwq.jpg
./.bash_history:-rw-r--r--. 1 root root 974 Jul 10 11:00 passwd
./.bash_history:drwxr-xr-x. 2 root root 6 Jul 10 12:04 test
./.bash_history:[root@CentOS7 ~]
./test.txt:root:x:0:0:root:/root:/bin/bash
./passwd:root:x:0:0:root:/root:/bin/bash
./passwd:operator:x:11:0:operator:/root:/sbin/nologin
./file.txt:root
./file.txt:roottt
[root@CentOS7 ~]
root
roottt
oldboy
olirl
oldgirl
ROOT
[root@CentOS7 ~]
olirl
oldgirl
ROOT
[root@CentOS7 ~]
roottt
oldboy
olirl
[root@CentOS7 ~]
roottt
oldboy
olirl
oldgirl
ROOT
[root@CentOS7 ~]
root:x:0:0:root:/root:/bin/bash
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
rootttt
2. sed 增删改查 替换
sed
选项:
-n
-r
-i
-e
内部指令:
p
d
a
i
s
g
i
\n
\t
=
[root@CentOS7 ~]
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@CentOS7 ~]
root:x:0:0:root:/root:/bin/bash
[root@CentOS7 ~]
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
[root@CentOS7 ~]
sync:x:5:0:sync:/sbin:/bin/sync
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
[root@CentOS7 ~]
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
[root@CentOS7 ~]
root:x:0:0:root:/root:/bin/bash
[root@CentOS7 ~]
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
[root@CentOS7 ~]
root:x:0:0:root:/root:/bin/bash
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
[root@CentOS7 ~]
1 sync:x:5:0:sync:/sbin:/bin/sync
2 word
3 helld word
4 tail:root;mail;root
5 wordmagic
[root@CentOS7 ~]
sync:x:5:0:sync:/sbin:/bin/sync
word
helld word
wordmagic
[root@CentOS7 ~]
sync:x:5:0:sync:/sbin:/bin/sync
word
wordmagic
[root@CentOS7 ~]
word
wordmagic
[root@CentOS7 ~]
word
helld word
wordmagic
[root@CentOS7 ~]
tail:root;mail;root
wordmagic
[root@CentOS7 ~]
word
helld word
tail:root;mail;root
wordmagic
[root@CentOS7 ~]
tail:root;mail;root
wordmagic
[root@CentOS7 ~]
word
tail:root;mail;root
wordmagic
[root@CentOS7 ~]
[root@CentOS7 ~]
[root@CentOS7 ~]
word
tail:root;mail;root
wordmagic
[root@CentOS7 ~]
[root@CentOS7 ~]
1 word
2 tail:root;mail;root
3 wordmagic
4 hello word
[root@CentOS7 ~]
[root@CentOS7 ~]
yasuo
[root@CentOS7 ~]
[root@CentOS7 ~]
word
tail:root;mail;root zzc
oldboy
wordmagic
hello word
oldgirl
yasuo
[root@CentOS7 ~]
1 word
2 tail:root;mail;root
3 oldboy
4 hello word
5 wordmagic
6 hello word
7 oldgirl
8 yasuo
[root@CentOS7 ~]
1 word
2 tail:root;mail;root
3 oldboy
4 wordmagic
5 hello word
6 oldgirl
7 yasuo
8 oldgirl
1.
[root@CentOS7 ~]
1 word
2 tail:root;mail;root
3 dog
4 cat
5 oldboy
6 wordmagic
7 hello word
8 oldgirl
9 yasuo
2.
[root@CentOS7 ~]
1 word
2 tail:root;mail;root
3 oldboy
4 yasuo ruiwen
5 wordmagic
6 hello word
7 oldgirl
8 yasuo
3.
[root@CentOS7 ~]
1 word
2 tail:root;mail;root
3 oldboy
4 zzc
5 wordmagic
6 hello word
7 oldgirl
8 yasuo
[root@CentOS7 ~]
1 word
2 tail:root;mail;root
3 oldboy
4 wordmagic
5 hello word
6 oldgirl
7 yasuo
1.
[root@CentOS7 ~]
1 ruiwen
2 word
3 tail:root;mail;root
4 oldboy
5 wordmagic
6 hello word
7 oldgirl
8 yasuo
[root@CentOS7 ~]
1 yasuo ruiwen
2 word
3 tail:root;mail;root
4 oldboy
5 wordmagic
6 hello word
7 oldgirl
8 yasuo
2.
[root@CentOS7 ~]
1 word
2 tail:root;mail;root
3 mimu
4 oldboy
5 wordmagic
6 hello word
7 oldgirl
8 yasuo
3.
[root@CentOS7 ~]
1 word
2 tail:root;mail;root
3 oldboy
4 wordmagic
5 hello word
6 oldgirl
7 book
8 yasuo
4.
[root@CentOS7 ~]
1 ruiwen
2 yasuo
3 word
4 tail:root;mail;root
5 oldboy
6 wordmagic
7 hello word
8 oldgirl
9 yasuo
[root@CentOS7 ~]
1 yasuo ruiwen
2 word
3 tail:root;mail;root
4 oldboy
5 wordmagic
6 hello word
7 oldgirl
8 yasuo
5.根据字符串插入内容
[root@CentOS7 ~]
1 word
2 tail:root;mail;root
3 oldboy
4 wordmagic
5 zzc
6 hello word
7 oldgirl
8 yasuo
[root@CentOS7 ~]
word
tail:root;mail;root
oldboy
亚索
wordmagic
你好
hello word
oldgirl
yasuo
[root@CentOS7 ~]
word
tail:root;mail;root
oldboy
亚索
wordmagic
你好
hello word
oldgirl
yasuo
[root@CentOS7 ~]
word
tail:root;mail;root
oldboy
wordmagic
hello word
oldgirl
yasuo
[root@CentOS7 ~]
zzc
tail:root;mail;root
oldboy
zzcmagic
hello zzc
oldgirl
yasuo
[root@CentOS7 ~]
zzc
tail:root;mail;root
oldboy
wordmagic
hello word
oldgirl
yasuo
[root@CentOS7 ~]
root
tail:root;mail;root
oldboy
rootmagic
hello word
oldgirl
yasuo
[root@CentOS7 ~]
[root@CentOS7 ~]
word
tail:root;mail;root
oldboy
wordmagic
hello word
oldgirl
yasuo
WORD
[root@CentOS7 ~]
zzc
tail:root;mail;root
oldboy
zzcmagic
hello zzc
oldgirl
yasuo
zzc
[root@CentOS7 ~]
1 word
2 tail:root;mail;root
3 oldboy
4 wordmagic
5 hello word
6 oldgirl
7 yasuo
8 WORD
[root@CentOS7 ~]
1 word
2 tail:root;mail;root
3 oldboy
4 wordmagic
5 hello zzc
6 oldgirl
7 yasuo
8 zzc
[root@CentOS7 ~]
word
tail:root;zzc;root
oldboy
wordmagic
hello word
oldgirl
yasuo
WORD
[root@CentOS7 ~]
word
tail:root;mail;root
oldboy
wordmagic
hello word
oldgirl
yasuo
WORD
root:x:0:0:root:/root:/good/bash
[root@CentOS7 ~]
word
tail:rootabc;mail;rootabc
oldboy
wordmagic
hello word
oldgirl
yasuo
WORD
rootabc:x:0:0:rootabc:/rootabc:/bin/bash
[root@CentOS7 ~]
[root@CentOS7 ~]
word
tail:root;mail;root
oldboy
wordmagic
hello word
oldgirl
yasuo
WORD
root:x:0:0:root:/root:/bin/bash
[root@CentOS7 ~]
word
tail:;mail;
oldboy
wordmagic
hello word
oldgirl
yasuo
WORD
:x:0:0::/:/bin/bash
^
$
^$
[root@CentOS7 ~]
[root@CentOS7 ~]
前期定义 后期调用 \1 \2 第一个括号里面的内容 用 \1 第二个括号就是\2
[root@CentOS7 ~]
word
tail:root;mail;root zzc
oldboy
wordmagic
hello word
oldgirl
yasuo
WORD
root:x:0:0:root:/root:/bin/bash
[root@CentOS7 ~]
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.100 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::5169:baec:f4cd:6fb9 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:02:d2:3a txqueuelen 1000 (Ethernet)
RX packets 19638 bytes 1668558 (1.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 10764 bytes 1209273 (1.1 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@CentOS7 ~]
inet 10.0.0.100 netmask 255.255.255.0 broadcast 10.0.0.255
[root@CentOS7 ~]
10.0.0.100
[root@CentOS7 ~]
10.0.0.100
[root@CentOS7 ~]
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:02:d2:3a brd ff:ff:ff:ff:ff:ff
inet 10.0.0.100/24 brd 10.0.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::5169:baec:f4cd:6fb9/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@CentOS7 ~]
inet 10.0.0.100/24 brd 10.0.0.255 scope global noprefixroute eth0
[root@CentOS7 ~]
10.0.0.100
[root@CentOS7 ~]
10.0.0.100
[root@CentOS7 ~]
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
[root@CentOS7 ~]
/bin/bash:x:0:0:root:/root:root
/sbin/nologin:x:1:1:bin:/bin:bin
/sbin/nologin:x:2:2:daemon:/sbin:daemon
/sbin/nologin:x:3:4:adm:/var/adm:adm
/sbin/nologin:x:4:7:lp:/var/spool/lpd:lp
/bin/sync:x:5:0:sync:/sbin:sync
/sbin/shutdown:x:6:0:shutdown:/sbin:shutdown
/sbin/halt:x:7:0:halt:/sbin:halt
/sbin/nologin:x:8:12:mail:/var/spool/mail:mail
/sbin/nologin:x:11:0:operator:/root:operator
/sbin/nologin:x:12:100:games:/usr/games:games
/sbin/nologin:x:14:50:FTP User:/var/ftp:ftp
/sbin/nologin:x:99:99:Nobody:/:nobody
[root@CentOS7 ~]
1
word
2
tail:root;mail;root zzc
3
oldboy
4
wordmagic
5
hello word
6
oldgirl
7
yasuo
3. awk 擅长取列
awk
选项:
-F
-v
内部命令 内部变量
Fs
OFS
NR
NF
$0
$n
$NF
[root@CentOS7 ~]
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@CentOS7 ~]
root:x:0:0:root:/root:/bin/bash
adm:x:3:4:adm:/var/adm:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
[root@CentOS7 ~]
root:x:0:0:root:/root:/bin/bash
adm:x:3:4:adm:/var/adm:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
[root@CentOS7 ~]
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
[root@CentOS7 ~]
root:x:0:0:root:/root:/bin/bash
[root@CentOS7 ~]
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
[root@CentOS7 ~]
root:x:0:0:root:/root:/bin/bash
daemon:x:2:2:daemon:/sbin:/sbin/nologin
[root@CentOS7 ~]
1 word
2 tail:root;mail;root zzc
3 oldboy
4 wordmagic
5 hello word
6 oldgirl
7 yasuo
8 WORD
9 root:x:0:0:root:/root:/bin/bash
[root@CentOS7 ~]
hello word
oldgirl
yasuo
WORD
root:x:0:0:root:/root:/bin/bash
[root@CentOS7 ~]
word
tail:root;mail;root zzc
oldboy
[root@CentOS7 ~]
word
tail:root;mail;root zzc
oldboy
wordmagic
[root@CentOS7 ~]
wordmagic
hello word
oldgirl
yasuo
WORD
root:x:0:0:root:/root:/bin/bash
[root@CentOS7 ~]
oldboy
wordmagic
[root@CentOS7 ~]
word
yasuo
WORD
root:x:0:0:root:/root:/bin/bash
[root@CentOS7 ~]
word
tail:root;mail;root zzc
oldboy
wordmagic
hello word
oldgirl
yasuo
WORD
root:x:0:0:root:/root:/bin/bash
[root@CentOS7 ~]
1 word
2 tail:root;mail;root zzc
3 oldboy
4 wordmagic
5 hello word
6 oldgirl
7 yasuo
8 WORD
9 root:x:0:0:root:/root:/bin/bash
[root@CentOS7 ~]
word
oldboy
wordmagic
hello word
oldgirl
yasuo
WORD
[root@CentOS7 ~]
tail:root;mail;root zzc
oldboy
wordmagic
hello word
oldgirl
yasuo
WORD
root:x:0:0:root:/root:/bin/bash
[root@CentOS7 ~]
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
operator
games
ftp
nobody
systemd-network
dbus
polkitd
[root@CentOS7 ~]
root x
bin x
daemon x
adm x
lp x
sync x
shutdown x
halt x
mail x
operator x
games x
ftp x
nobody x
systemd-network x
dbus x
polkitd x
sshd x
postfix x
[root@CentOS7 ~]
/bin/bash
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/bin/sync
/sbin/shutdown
/sbin/halt
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
[root@CentOS7 ~]
/root
/bin
/sbin
/var/adm
/var/spool/lpd
/sbin
/sbin
/sbin
/var/spool/mail
/root
/usr/games
/var/ftp
/
/
/
/
/var/empty/sshd
/var/spool/postfix
[root@CentOS7 ~]
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.100 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::3310:9d15:9ee4:43e8 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:eb:ea:8d txqueuelen 1000 (Ethernet)
RX packets 15508 bytes 1698801 (1.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 10471 bytes 1145384 (1.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@CentOS7 ~]
inet 10.0.0.100 netmask 255.255.255.0 broadcast 10.0.0.255
[root@CentOS7 ~]
10.0.0.100
[root@CentOS7 ~]
10.0.0.100
[root@CentOS7 ~]
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:eb:ea:8d brd ff:ff:ff:ff:ff:ff
inet 10.0.0.100/24 brd 10.0.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::3310:9d15:9ee4:43e8/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@CentOS7 ~]
inet 10.0.0.100/24 brd 10.0.0.255 scope global noprefixroute eth0
[root@CentOS7 ~]
10.0.0.100
[root@CentOS7 ~]
10.0.0.100
[root@CentOS7 ~]
[root@CentOS7 ~]
// inet 10.0.0.100/24 brd 10.0.0.255 scope global noprefixroute eth0
[root@CentOS7 ~]
10.0.0.100
[root@CentOS7 ~]
10.0.0.100
[root@CentOS7 ~]
root:x
bin:x
daemon:x
adm:x
lp:x
sync:x
shutdown:x
halt:x
mail:x
operator:x
games:x
ftp:x
nobody:x
systemd-network:x
dbus:x
polkitd:x
sshd:x
postfix:x
[root@CentOS7 ~]
root脱产10期x
bin脱产10期x
daemon脱产10期x
adm脱产10期x
lp脱产10期x
sync脱产10期x
shutdown脱产10期x
halt脱产10期x
mail脱产10期x
operator脱产10期x
games脱产10期x
ftp脱产10期x
nobody脱产10期x
systemd-network脱产10期x
dbus脱产10期x
polkitd脱产10期x
sshd脱产10期x
postfix脱产10期x
[root@CentOS7 ~]
/bin/bash:x:0:0:root:/root:root
/sbin/nologin:x:1:1:bin:/bin:bin
/sbin/nologin:x:2:2:daemon:/sbin:daemon
rootroot
/sbin/nologin:x:3:4:adm:/var/adm:adm
/sbin/nologin:x:4:7:lp:/var/spool/lpd:lp
/bin/sync:x:5:0:sync:/sbin:sync
/sbin/shutdown:x:6:0:shutdown:/sbin:shutdown
/sbin/halt:x:7:0:halt:/sbin:halt
/sbin/nologin:x:8:12:mail:/var/spool/mail:mail
/sbin/nologin:x:11:0:operator:/root:operator
/sbin/nologin:x:12:100:games:/usr/games:games
/sbin/nologin:x:14:50:FTP User:/var/ftp:ftp
/sbin/nologin:x:99:99:Nobody:/:nobody
/sbin/nologin:x:192:192:systemd Network Management:/:systemd-network
/sbin/nologin:x:81:81:System message bus:/:dbus
/sbin/nologin:x:999:998:User for polkitd:/:polkitd
/sbin/nologin:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:tss
/sbin/nologin:x:173:173::/etc/abrt:abrt
/sbin/nologin:x:74:74:Privilege-separated SSH:/var/empty/sshd:sshd
/sbin/nologin:x:89:89::/var/spool/postfix:postfix
/sbin/nologin:x:38:38::/etc/ntp:ntp
/bin/bash:x:1000:1000::/home/zzc:zzc
4. 总结&排除空行
1. grep
选项:
-n
-i
-c
-v
-o
-w
-r
-A
-B
-C
-E
^
$
^$
.
*
.*
|
2. sed
选项:
-n
-r
-i
-e
内部命令:
p
d
s
g
i
a
i
\n
\t
=
后向引用:
[root@CentOS7 ~]
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.100 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::5169:baec:f4cd:6fb9 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:02:d2:3a txqueuelen 1000 (Ethernet)
RX packets 194 bytes 17674 (17.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 100 bytes 10541 (10.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@CentOS7 ~]
10.0.0.100
[root@CentOS7 ~]
10.0.0.100
[root@CentOS7 ~]
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:02:d2:3a brd ff:ff:ff:ff:ff:ff
inet 10.0.0.100/24 brd 10.0.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::5169:baec:f4cd:6fb9/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@CentOS7 ~]
10.0.0.100
[root@CentOS7 ~]
10.0.0.100
[root@CentOS7 ~]
File: ‘/etc/hosts’
Size: 158 Blocks: 8 IO Block: 4096 regular file
Device: 803h/2051d Inode: 17004494 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Context: system_u:object_r:net_conf_t:s0
Access: 2020-07-15 09:49:48.356726160 +0800
Modify: 2013-06-07 22:31:32.000000000 +0800
Change: 2020-07-06 09:29:45.882290124 +0800
Birth: -
[root@CentOS7 ~]
0644
3. awk
选项:
-F
-v
!
内部变量:
FS
OFS
NR
NF
$NF
$0
$n
1. 排除空行 存在空格和tab键的空行
[root@CentOS7 ~]
penBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $
1.
[root@CentOS7 ~]
[root@CentOS7 ~]
[root@CentOS7 ~]
[root@CentOS7 ~]
[root@CentOS7 ~]
[root@CentOS7 ~]
[root@CentOS7 ~]
[root@CentOS7 ~]
[root@CentOS7 ~]
2.
[root@CentOS7 ~]
penBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $
[root@CentOS7 ~]
penBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $
[root@CentOS7 ~]
penBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $
[root@CentOS7 ~]
penBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $
[root@CentOS7 ~]
penBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $
[root@CentOS7 ~]
penBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $
3.
[root@CentOS7 ~]
/bin/bash:x:0:0:root:/root:root
/sbin/nologin:x:1:1:bin:/bin:bin
/sbin/nologin:x:2:2:daemon:/sbin:daemon
/sbin/nologin:x:3:4:adm:/var/adm:adm
/sbin/nologin:x:4:7:lp:/var/spool/lpd:lp
/bin/sync:x:5:0:sync:/sbin:sync
/sbin/shutdown:x:6:0:shutdown:/sbin:shutdown
/sbin/halt:x:7:0:halt:/sbin:halt
/sbin/nologin:x:8:12:mail:/var/spool/mail:mail
/sbin/nologin:x:11:0:operator:/root:operator
/sbin/nologin:x:12:100:games:/usr/games:games
/sbin/nologin:x:14:50:FTP:User:/var/ftp:ftp
/sbin/nologin:x:99:99:Nobody:/:nobody
/sbin/nologin:x:192:192:systemd:Network:Management:/:systemd-network
/sbin/nologin:x:81:81:System:message:bus:/:dbus
/sbin/nologin:x:999:998:User:for:polkitd:/:polkitd
[root@CentOS7 ~]
/bin/bash:x:0:0:root:/root:root
/sbin/nologin:x:1:1:bin:/bin:bin
/sbin/nologin:x:2:2:daemon:/sbin:daemon
/sbin/nologin:x:3:4:adm:/var/adm:adm
/sbin/nologin:x:4:7:lp:/var/spool/lpd:lp