1.1用法與原理
•sed [option]… ‘script’ file
1.2經常使用選項
•-n:取消默認輸出
•-e:多點編輯
•-f :/PATH/TO/SCRIPT_FILE從指定文件中讀取編輯腳本
•-r:支持使用擴展正則表達式
1.3地址定界
•(1)不給地址:對全文進行處理
•(2)單地址:
#:指定的行
/pattern/:被此處模式所可以匹配到的每一行
•(3)地址範圍:
#,#
#,+#
/pat1/,/pat2/
#,/pat1/
#;#;#分隔的多行
1.3.1實踐操做
環境準備
[root@oldboyedu-02 oldboy]# cat person.txt
101,oldboy,CEO
102,zhangyao,CTO
103,Alex,COO
104,yy,CFO
105,feixue,CIO
•-n取消默認輸出,只打印想要的內容
[root@oldboyedu-02 oldboy]# sed '1p' person.txt
101,oldboy,CEO
101,oldboy,CEO
102,zhangyao,CTO
103,Alex,COO
104,yy,CFO
105,feixue,CIO
[root@oldboyedu-02 oldboy]# sed -n '1p' person.txt
101,oldboy,CEO
•連續多行
[root@oldboyedu-02 oldboy]# sed -n '2,4p' person.txt
102,zhangyao,CTO
103,Alex,COO
104,yy,CFO
•找出包含oldboy的行 到 包含104的行
[root@oldboyedu-02 oldboy]# sed -n '/oldboy/,/^104/p' person.txt
101,oldboy,CEO
102,zhangyao,CTO
103,Alex,COO
104,yy,CFO
[root@oldboyedu-01 ~]# awk '/root/,/operator/{print $0}' /etc/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
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
•包含oldboy的行 或 yy的行
[root@oldboyedu-02 oldboy]# sed -rn '/oldboy|yy/p' person.txt
101,oldboy,CEO
104,yy,CFO
[root@oldboyedu-02 oldboy]# egrep 'oldboy|yy' person.txt
101,oldboy,CEO
104,yy,CFO
•打印分隔的多行
[root@oldboyedu-02 oldboy]# sed -n '1p;2p;4p' person.txt
101,oldboy,CEO
102,zhangyao,CTO
104,yy,CFO
•打印第二行和後面三行
[root@oldboyedu-01 ~]# sed -n '2,+3p' /etc/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
•打印第二行到包含root的行
[root@oldboyedu-01 ~]# sed -n '2,/root/p' /etc/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
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
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
[root@oldboyedu-01 ~]# awk 'NR==2,/root/' /etc/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
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
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
1.4編輯命令
•d:刪除
•p:顯示模式空間中的內容
•a \text:在行後面追加文本,支持使用\n實現多行追加
•i \text:在行前面插入文本,支持使用\n實現多行插入
•c \text:替換行尾單行或多行文本
•w /path/to/somefile:保存模式空間匹配到的行到指定文件中
•r /path/from/somefile:讀取指定文件的文本流到模式空間中匹配到的行後
•=:爲模式空間中的行打印行號
•!:取反條件
•s///g:支持使用其餘分隔符,s###g,s@@@g
•s:替換每行的第一處匹配的內容
•g:行內全局替換
•p:顯示替換成功的行
•w:/path/to/somefile:將替換成功的結果保存到指定文件中
•&表示被替換的內容
1.4.1實踐操做
•a 追加append,在指定行後添加一行或多行文本
[root@oldboyedu-02 oldboy]# sed '3a 103.5,xiaoyu,CXO' person.txt
101,oldboy,CEO
102,zhangyao,CTO
103,Alex,COO
103.5,xiaoyu,CXO
104,yy,CFO
105,feixue,CIO
•i 插入insert,在指定行前添加一行或多行文本
[root@oldboyedu-02 oldboy]# sed '3i 103.5,xiaoyu,CXO' person.txt
101,oldboy,CEO
102,zhangyao,CTO
103.5,xiaoyu,CXO
103,Alex,COO
104,yy,CFO
105,feixue,CIO
單行追加
echo 'test' >>person.txt
•增長多行
[root@oldboyedu-02 oldboy]# sed '$a 106\n107\n108' person.txt
101,oldboy,CEO
102,zhangyao,CTO
103,Alex,COO
104,yy,CFO
105,feixue,CIO
106
107
108
下面比較經常使用
[root@oldboyedu-02 oldboy]# cat >>person.txt<<EOF
> 106 106
> 107 107
> EOF
•刪除
[root@oldboyedu-02 oldboy]# cat -A person.txt
101,oldboy,CEO$
$
102,zhangyao,CTO$
103,Alex,COO$
$
104,yy,CFO$
105,feixue,CIO$
106 106$
107 107$
[root@oldboyedu-02 oldboy]# sed '/^$/d' person.txt
101,oldboy,CEO
102,zhangyao,CTO
103,Alex,COO
104,yy,CFO
105,feixue,CIO
106 106
107 107
[root@oldboyedu-02 oldboy]# sed -n '/^$/p' person.txt
[root@oldboyedu-02 oldboy]# sed -n '/^$/!p' person.txt
101,oldboy,CEO
102,zhangyao,CTO
103,Alex,COO
104,yy,CFO
105,feixue,CIO
106 106
107 107
[root@oldboyedu-02 oldboy]# sed '$d' person.txt
101,oldboy,CEO
102,zhangyao,CTO
103,Alex,COO
104,yy,CFO
105,feixue,CIO
106 106
[root@oldboyedu-02 oldboy]# sed '$!d' person.txt
107 107
[root@oldboyedu-02 oldboy]#
[root@oldboyedu-02 oldboy]# awk '!/^$/' person.txt
101,oldboy,CEO
102,zhangyao,CTO
103,Alex,COO
104,yy,CFO
105,feixue,CIO
106 106
107 107
[root@oldboyedu-02 oldboy]# egrep -v '^$' person.txt
101,oldboy,CEO
102,zhangyao,CTO
103,Alex,COO
104,yy,CFO
105,feixue,CIO
106 106
107 107
•替換
-i修改文件內容
-i.bak 先把源文件備份,而後替換內容
s單獨使用,將每一行中的第一處匹配的字符串進行替換
g global 每一行進行所有替換
[root@oldboyedu-02 oldboy]# sed -i.bak 's#o#AAAAA#g' person.txt
[root@oldboyedu-02 oldboy]# cat person.txt.bak
101,oldboy,CEO
102,zhangyao,CTO
103,Alex,COO
104,yy,CFO
105,feixue,CIO
106 106
107 107
[root@oldboyedu-02 oldboy]# cat person.txt
101,AAAAAldbAAAAAy,CEO
102,zhangyaAAAAA,CTO
103,Alex,COO
104,yy,CFO
105,feixue,CIO
106 106
107 107
含有變量的替換時,要使用""
[root@oldboyedu-02 oldboy]# x=oldboy
[root@oldboyedu-02 oldboy]# y=oldgirl
[root@oldboyedu-02 oldboy]# cat person.txt
101,oldboy,CEO
102,zhangyao,CTO
103,Alex,COO
104,yy,CFO
105,feixue,CIO
106 106
107 107
[root@oldboyedu-02 oldboy]# sed "s#$x#$y#g" person.txt
101,oldgirl,CEO
102,zhangyao,CTO
103,Alex,COO
104,yy,CFO
105,feixue,CIO
106 106
107 107
•刪除/boot/grub/grub.conf文件中全部以空白開頭的行的行首的空表字符
[root@oldboyedu-01 oldboy]# cat /boot/grub/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/sda3
# initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS 6 (2.6.32-696.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-696.el6.x86_64 ro root=UUID=b3a88d2b-b491-46ff-96a1-a9eff1a5c3a5 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-696.el6.x86_64.img
[:blank:] 空白字符(空格和製表符)
[:space:] \s 全部空格符(比[:blank:]包含的範圍廣)
使用[:space:]
[root@oldboyedu-01 oldboy]# sed -r '#^[[:space:]]##g' /boot/grub/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/sda3
# initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS 6 (2.6.32-696.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-696.el6.x86_64 ro root=UUID=b3a88d2b-b491-46ff-96a1-a9eff1a5c3a5 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-696.el6.x86_64.img
[root@oldboyedu-01 oldboy]#
使用[ ]表明空格很差使,經過vim編輯器查看,也不是空格
[root@oldboyedu-01 oldboy]# sed -r 's#^[ ]+##g' /boot/grub/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/sda3
# initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS 6 (2.6.32-696.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-696.el6.x86_64 ro root=UUID=b3a88d2b-b491-46ff-96a1-a9eff1a5c3a5 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-696.el6.x86_64.img
[root@oldboyedu-01 oldboy]#
•刪除/etc/fstab文件中全部以#開頭,後面至少跟一個空白字符的行的行首的#和空白字符
[root@oldboyedu-01 oldboy]# cat /etc/fstab |sed -r 's#^[#][ ]+##g'
#
/etc/fstab
Created by anaconda on Mon Feb 18 12:19:50 2019
#
Accessible filesystems, by reference, are maintained under '/dev/disk'
See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=b3a88d2b-b491-46ff-96a1-a9eff1a5c3a5 / ext4 defaults 1 1
UUID=8848e519-989b-4a1f-9fdb-803f0b56db57 /boot ext4 defaults 1 2
UUID=b6a11888-75c1-4a5f-98fa-32c323404e4e swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
[root@oldboyedu-01 oldboy]# cat /etc/fstab |sed -r 's#^[#][[:space:]]+##g'
#
/etc/fstab
Created by anaconda on Mon Feb 18 12:19:50 2019
#
Accessible filesystems, by reference, are maintained under '/dev/disk'
See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=b3a88d2b-b491-46ff-96a1-a9eff1a5c3a5 / ext4 defaults 1 1
UUID=8848e519-989b-4a1f-9fdb-803f0b56db57 /boot ext4 defaults 1 2
UUID=b6a11888-75c1-4a5f-98fa-32c323404e4e swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
[root@oldboyedu-01 oldboy]#
要使用[[:space:]],以下[:space:]是無論用的
[root@oldboyedu-01 oldboy]# cat /etc/fstab |sed -r 's#^[#][:space:]+##g'
#
# /etc/fstab
# Created by anaconda on Mon Feb 18 12:19:50 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=b3a88d2b-b491-46ff-96a1-a9eff1a5c3a5 / ext4 defaults 1 1
UUID=8848e519-989b-4a1f-9fdb-803f0b56db57 /boot ext4 defaults 1 2
UUID=b6a11888-75c1-4a5f-98fa-32c323404e4e swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
[root@oldboyedu-01 oldboy]#
•echo一個絕對路徑給sed命令,取出其基名,取出其目錄名
[root@m01 oldboy]# echo "/opt/test/wew" |sed -r 's#.*/##g'
wew
•刪除UUID開頭的行
[root@m01 oldboy]# sed '/^UUID/d' /etc/fstab
#
# /etc/fstab
# Created by anaconda on Mon Feb 18 12:19:50 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
•刪除空白行
[root@m01 oldboy]# sed '/^$/d' /etc/fstab
#
# /etc/fstab
# Created by anaconda on Mon Feb 18 12:19:50 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=b3a88d2b-b491-46ff-96a1-a9eff1a5c3a5 / ext4 defaults 1 1
UUID=8848e519-989b-4a1f-9fdb-803f0b56db57 /boot ext4 defaults 1 2
UUID=b6a11888-75c1-4a5f-98fa-32c323404e4e swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
[root@m01 oldboy]#
•符合條件的行後面追加內容
[root@m01 oldboy]# sed '/^UUID/a wewewew' /etc/fstab
#
# /etc/fstab
# Created by anaconda on Mon Feb 18 12:19:50 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=b3a88d2b-b491-46ff-96a1-a9eff1a5c3a5 / ext4 defaults 1 1
wewewew
UUID=8848e519-989b-4a1f-9fdb-803f0b56db57 /boot ext4 defaults 1 2
wewewew
UUID=b6a11888-75c1-4a5f-98fa-32c323404e4e swap swap defaults 0 0
wewewew
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
[root@m01 oldboy]#
•打印符合條件行的行號
[root@m01 oldboy]# sed '/UUID/=' /etc/fstab
#
# /etc/fstab
# Created by anaconda on Mon Feb 18 12:19:50 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
9
UUID=b3a88d2b-b491-46ff-96a1-a9eff1a5c3a5 / ext4 defaults 1 1
10
UUID=8848e519-989b-4a1f-9fdb-803f0b56db57 /boot ext4 defaults 1 2
11
UUID=b6a11888-75c1-4a5f-98fa-32c323404e4e swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
[root@m01 oldboy]#
•!取反
[root@m01 oldboy]# sed -n '/UUID/p' /etc/fstab
UUID=b3a88d2b-b491-46ff-96a1-a9eff1a5c3a5 / ext4 defaults 1 1
UUID=8848e519-989b-4a1f-9fdb-803f0b56db57 /boot ext4 defaults 1 2
UUID=b6a11888-75c1-4a5f-98fa-32c323404e4e swap swap defaults 0 0
[root@m01 oldboy]# sed -n '/UUID/!p' /etc/fstab
#
# /etc/fstab
# Created by anaconda on Mon Feb 18 12:19:50 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
[root@m01 oldboy]#
•!替換追加,&表明前面匹配的內容
[root@m01 oldboy]# sed 's#UUID#&NEW#g' /etc/fstab
#
# /etc/fstab
# Created by anaconda on Mon Feb 18 12:19:50 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUIDNEW=b3a88d2b-b491-46ff-96a1-a9eff1a5c3a5 / ext4 defaults 1 1
UUIDNEW=8848e519-989b-4a1f-9fdb-803f0b56db57 /boot ext4 defaults 1 2
UUIDNEW=b6a11888-75c1-4a5f-98fa-32c323404e4e swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
[root@m01 oldboy]#
1.5sed後向引用
sed -n 's#()()#\1\2#gp' file
當在前面匹配部分用小括號的時候,第一個括號內容,能夠在後面部分用\1輸出
第二個括號內容,能夠在後面部分用\2輸出
[root@m01 oldboy]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:BE:11:5D
inet addr:10.0.0.61 Bcast:10.0.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:febe:115d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:10361 errors:0 dropped:0 overruns:0 frame:0
TX packets:7372 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:970097 (947.3 KiB) TX bytes:905329 (884.1 KiB)
eth1 Link encap:Ethernet HWaddr 00:0C:29:BE:11:67
inet addr:172.16.1.61 Bcast:172.16.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:febe:1167/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:1041 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:62568 (61.1 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:686 errors:0 dropped:0 overruns:0 frame:0
TX packets:686 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:60368 (58.9 KiB) TX bytes:60368 (58.9 KiB)
[root@m01 oldboy]# ifconfig|sed -nr 's/.*dr:(.*) Bc/\1/g'
[root@m01 oldboy]# ifconfig|sed -nr 's/.*dr:(.*) Bc/\1/gp'
10.0.0.61 ast:10.0.0.255 Mask:255.255.255.0
172.16.1.61 ast:172.16.1.255 Mask:255.255.255.0
[root@m01 oldboy]# ifconfig|sed -nr 's/.*dr:(.*) Bc.*/\1/gp'
10.0.0.61
172.16.1.61
[root@m01 oldboy]#
切換第一列和最後一列
[root@m01 oldboy]# sed -nr 's#(.*)(:.*:)(/.*$)#\3\2\1#gp' /etc/passwd
/bin/bash:/root:root:x:0:0:root
/sbin/nologin:/bin:bin:x:1:1:bin
/sbin/nologin:/sbin:daemon:x:2:2:daemon
/sbin/nologin:/var/adm:adm:x:3:4:adm
/sbin/nologin:/var/spool/lpd:lp:x:4:7:lp
/bin/sync:/sbin:sync:x:5:0:sync
/sbin/shutdown:/sbin:shutdown:x:6:0:shutdown