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.178linux.com/59558