1、復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限。
[root@loalhost ~]# (umask 077; cp -r /etc/skel /home/user1)
2、編輯/etc/group文件,添加組hadoop。
[root@localhost ~]# sed -i '$a\hadoop:x:500' /etc/group [root@localhost ~]# tail -5 /etc/group mongodb:x:503: pns:x:504: xiaoxin:x:505: XIAOXIN:x:506: hadoop:x:500
3、手動編輯/etc/passwd文件新增一行,添加用戶hadoop,其基本組ID為hadoop組的id號;其家目錄為/home/hadoop。
[root@localhost ~]# sed -i '$a\hadoop:x:500:500::/home/hadoop:/bin/bash' /etc/passwd [root@localhost ~]# tail -1 /etc/group hadoop:x:500:500::/home/hadoop:/bin/bash
4、復制/etc/skel目錄為/home/hadoop,要求修改hadoop目錄的屬組和其它用戶沒有任何訪問權限。
[root@localhost ~]# (umask 077; cp -r /etc/skel /home/hadoop)
5、修改/home/hadoop目錄及其內部所有文件的屬主為hadoop,屬組為hadoop。
[root@localhost ~]# chown -r hadoop /home/hadoop
6、顯示/proc/meminfo文件中以大寫或小寫S開頭的行;用兩種方式;
[root@localhost ~]# grep \[sS\] /proc/meminfo Buffers: 172756 kB SwapCached: 3792 kB SwapTotal: 8327160 kB SwapFree: 8192284 kB AnonPages: 10195868 kB Shmem: 7096 kB Slab: 585472 kB SReclaimable: 537136 kB SUnreclaim: 48336 kB KernelStack: 12280 kB PageTables: 41752 kB NFS_Unstable: 0 kB Committed_AS: 25695728 kB VmallocUsed: 173456 kB AnonHugePages: 8472576 kB HugePages_Total: 0 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB
7、顯示/etc/passwd文件中其默認shell為非/sbin/nologin的用戶;
[root@localhost ~]# grep [^nologin]$ /etc/passwd root:x:0:0:root:/root:/bin/bash sync:x:5:0:sync:/sbin:/bin/sync
8、顯示/etc/passwd文件中其默認shell為/bin/bash的用戶;
[root@localhost ~]# grep bash$ /etc/passwd root:x:0:0:root:/root:/bin/bash ricci:x:140:140:ricci daemon user:/var/lib/ricci:/bin/bash
9、找出/etc/passwd文件中的一位數或兩位數;
[root@localhost ~]# grep -E --color "\<[0-9]{1,2}\>" /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
10、顯示/boot/grub/grub.conf中以至少一個空白字符開頭的行;
[root@localhost ~]# grep -E --color "^[[:space:]]+" /etc/grub.conf root (hd0,0) kernel /vmlinuz-2.6.32-358.el6.x86_64 ro root=UUID=ad5e4daa-0814-4b82-99c3-125cee3f3f76 rd_NO_LUKS rd_NO_LVM.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet initrd /initramfs-2.6.32-358.el6.x86_64.img
11、顯示/etc/rc.d/rc.sysinit文件中以#開頭,后面跟至少一個空白字符,而后又有至少一個非空白字符的行;
[root@localhost ~]# grep -E --color "^#[[:space:]]+[a-z]+" /etc/rc.d/rc.sysinit # mounted). Contrary to standard usage, # filesystems are NOT unmounted in single user mode. # let's dump the syslog ring somewhere so we can find it later # create the crash indicator flag to warn on crashes, offer fsck with timeout
12、打出netstat -tan命令執行結果中以‘LISTEN’,后或跟空白字符結尾的行;
[root@localhost ~]# netstat -nta|grep -E 'LISTEN[[:space:]]+$' tcp 0 0 0.0.0.0:9003 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:15915 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:40684 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:12812 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:3308 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:26926 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN
13、添加用戶bash, testbash, basher, nologin (此一個用戶的shell為/sbin/nologin),而后找出當前系統上其用戶名和默認shell相同的用戶的信息;
[root@localhost ~]# grep -E --color '^(\<[a-z]+\>).*\1$' /etc/passwd sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt bash:x:507:507::/home/bash:/bin/bash nologin:x:510:510::/home/nologin:/sbin/nologin
原創文章,作者:xiaoxin,如若轉載,請注明出處:http://www.www58058.com/43734
你也有grep -E的習慣哈,問下,帶參數-E和不帶參數,什么區別?
@馬哥教育:-E 支持擴展正則, 或者egrep 也可以, 基礎表達式,有些字符的轉義,不想用轉義