Linux用戶操作、文件操作、文件篩選
編輯/etc/group文件,添加組hadoop。手動編輯/etc/passwd文件新增一行,添加用戶hadoop,其基本組ID為hadoop組的id號;其家目錄為/home/hadoop。
vim /etc/group hadoop:x:1001: vim /etc/passwd hadoop:x:1003:1001::/home/hadoop:/bin/bash
復制/etc/skel目錄為/home/hadoop,要求修改hadoop目錄的屬組和其它用戶沒有任何訪問權限。
cp -r /etc/skel/. /home/hadoop/ | chmod g=---,o=--- /home/hadoop -R
修改/home/hadoop目錄及其內部所有文件的屬主為hadoop,屬組為hadoop。
[root@chenjianhang ~]# chown -R hadoop:hadoop /home/hadoop/. [root@chenjianhang ~]# ll -a /home/hadoop/ total 12 drwx------. 2 hadoop hadoop 59 Nov 8 23:01 . drwxr-xr-x. 6 root root 61 Nov 8 22:37 .. -rw-------. 1 hadoop hadoop 18 Nov 8 23:01 .bash_logout -rw-------. 1 hadoop hadoop 193 Nov 8 23:01 .bash_profile -rw-------. 1 hadoop hadoop 231 Nov 8 23:01 .bashrc [root@chenjianhang ~]#
顯示/proc/meminfo文件中以大寫或小寫S開頭的行;用三種方式;
[root@chenjianhang ~]# cat /proc/meminfo | grep "^[Ss]\+" SwapCached: 0 kB SwapTotal: 2097148 kB SwapFree: 2097148 kB Shmem: 13212 kB Slab: 63916 kB SReclaimable: 29576 kB SUnreclaim: 34340 kB [root@chenjianhang ~]#
[root@chenjianhang ~]# cat /proc/meminfo | grep "^[Ss].*" SwapCached: 0 kB SwapTotal: 2097148 kB SwapFree: 2097148 kB Shmem: 13212 kB Slab: 63916 kB SReclaimable: 29576 kB SUnreclaim: 34340 kB [root@chenjianhang ~]#
[root@chenjianhang ~]# cat /proc/meminfo | grep "^[Ss].*" SwapCached: 0 kB SwapTotal: 2097148 kB SwapFree: 2097148 kB Shmem: 13212 kB Slab: 63916 kB SReclaimable: 29576 kB SUnreclaim: 34340 kB [root@chenjianhang ~]#
顯示/etc/passwd文件中其默認shell為非/sbin/nologin的用戶;
[root@chenjianhang ~]# cat /etc/passwd | grep -v "/sbin/nologin" root:x:0:0:root:/root:/bin/bash sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt chenjianhang:x:1000:1000::/home/chenjianhang:/bin/bash test:x:1001:1002::/home/test:/bin/bash test1:x:1002:1003::/home/test1:/bin/bash hadoop:x:1003:1001::/home/hadoop:/bin/bash [root@chenjianhang ~]#
顯示/etc/passwd文件中其默認shell為/bin/bash的用戶;
[root@chenjianhang ~]# cat /etc/passwd | grep "/bin/bash" root:x:0:0:root:/root:/bin/bash chenjianhang:x:1000:1000::/home/chenjianhang:/bin/bash test:x:1001:1002::/home/test:/bin/bash test1:x:1002:1003::/home/test1:/bin/bash hadoop:x:1003:1001::/home/hadoop:/bin/bash [root@chenjianhang ~]#
找出/etc/passwd文件中的一位數或兩位數;
[root@chenjianhang ~]# cat /etc/passwd | grep -o "\<[0-9]\{1,2\}\>" 0 0 1 1 2 2 3 4 4 7 5 0 6 0 7 0 8 12 11 0 12 14 50 99 99 81 81 59 59 89 89 74 74 [root@chenjianhang ~]#
顯示/boot/grub/grub.conf中以至少一個空白字符開頭的行;
注意,在CentOS5上有這個文件,CentOS7上沒有了。
[root@localhost ~]# cat /boot/grub/grub.conf | grep "^[[:space:]]\+" root (hd0,0) kernel /vmlinuz-2.6.18-398.el5 ro root=LABEL=/ rhgb quiet initrd /initrd-2.6.18-398.el5.img [root@localhost ~]#
顯示/etc/rc.d/rc.sysinit文件中以#開頭,后面跟至少一個空白字符,而后又有至少一個非空白字符的行;
[root@localhost ~]# cat /etc/rc.d/rc.sysinit | grep "^#[[:space:]]\+[[:graph:]]"
打出netstat -tan命令執行結果中以‘LISTEN’,后或跟空白字符結尾的行;
[root@localhost ~]# netstat -tan | grep "LISTEN[[:space:]]\+$" tcp 0 0 0.0.0.0:933 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp 0 0 :::22 :::* LISTEN [root@localhost ~]#
添加用戶bash, testbash, basher, nologin (此一個用戶的shell為/sbin/nologin),而后找出當前系統上其用戶名和默認shell相同的用戶的信息;
[root@chenjianhang ~]# cat /etc/passwd | grep "^\([[:alnum:]]\+\).*\1$" sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt nobody:x:99:99:Nobody:/:/sbin/nologin hadoop:x:1003:1001::/home/hadoop:/bin/bash bash:x:1004:1004::/home/bash:/bin/bash basher:x:1006:1006::/home/basher:/bin/bash nologin:x:1007:1007::/home/nologin:/sbin/nologin [root@chenjianhang ~]#
原創文章,作者:Theo,如若轉載,請注明出處:http://www.www58058.com/59558