美文网首页
cp,chmod,chown,chgrg,grep命令应用实例和

cp,chmod,chown,chgrg,grep命令应用实例和

作者: dxldeng | 来源:发表于2017-10-24 14:05 被阅读18次

1.复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的其他属组和其他用户没有任何访问权限。
[root@dxlcentOS ~]# cp -a /etc/skel/ /home/tuser1
[root@dxlcentOS ~]# chmod -R go= /home/tuser1 递归修改权限,g:组的权限,o其他人权限,后面没有加权限,表示取消他们的权限

2.编辑/etc/group文件,添加组hadood.
[root@dxlcentOS ~]# vim /etc/group
hadoop:x:2050:
加入一行hadoop:x:2050:,指定组名和组ID,组ID不能和存在的ID号相同,要是没有指定组ID,则是无效组,不能往里面添加用户。

3.手动编辑/etc/passwd文件新增一行,添加用户hadoop,其基本组为ID为hadoop组的ID号,其家目录为/home/hadoop。
[root@dxlcentOS ~]# vim /etc/passwd
hadoop:x:2049:2050::/home/hadoop:/bin/bash
Hadoop用户增加进用户信息库后,还没有家目录,还要复制/etc/skel过来

4.复制/etc/skel目录为/home/haddoop,要求/home/haddoop目录的属组和其他用户没有任何访问权限。
[root@dxlcentOS ~]# cp -a /etc/skel /home/hadoop
[root@dxlcentOS ~]# chmod go= /home/hadoop

5,修改/home/haddoop目录及其内部所有文件属主为hadoop,属组为hadoop。
[root@dxlcentOS ~]# chown -R hadoop /home/hadoop | chgrp -R hadoop /home/hadoop

6.显示/proc/meminfo文件中,所有以大写或小写S开头的行,两种方式。
[hadoop@dxlcentOS ~]$ grep -i "^s" /proc/meminfo
[hadoop@dxlcentOS ~]$ grep "^[Ss]" /proc/meminfo

7.显示/etc/passwd文件中默认shell为非/sbin/nologin的用户.
[hadoop@dxlcentOS ~]$ grep -v "/sbin/nologin" /etc/passwd

8.显示/etc/passwd文件中默认shell为/bin/bash的用户.
[root@dxlcentOS ~]# grep "/bin/bash" /etc/passwd
root:x:0:0:root:/root:/bin/bash
centos:x:1000:1000::/home/centos:/bin/bash

9.找出/etc/passwd文件中的一位数或二位数
[root@dxlcentOS ~]# grep "\<[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
.......

10.显示/boot/grub/grup.conf文件中,以至少一个空白字符开头的行.
[root@dxl ~ 12:33:45]# grep "^[[:space:]]\+" /boot/grub/grub.conf

11.显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后面至少有一个非空白字符的行.

 [root@dxl ~ 12:46:27]# grep "^[#][[:space:]]\+[^[:space:]]\+" /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

12.找出"netstat -tan"命令的结果中以'LISTEN',后跟空白字符结尾的行。

 [root@dxl ~ 12:59:51]# netstat -tan | grep "LISTEN[[:space:]]\+$"
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      

13.添加用户bash, testbash, basher以及nologin(其shell为/sbin/nologin);而后找出当前系统上其用户名和默认shell相同的用户信息。
第一步先添加用户bash, testbash, basher以及nologin
第二步

 [root@dxl ~ 13:24:53]# grep  -E "^([^:]+\>).*\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:504:504::/home/bash:/bin/bash
nologin:x:507:507::/home/nologin:/sbin/nologin

总结:通过编辑组信息库文件/etc/grouptonggu添加的组,其ID不能和存在的组ID相同。通过手动编辑用户信息库/etc/passwd文件添加的用户并指定家目录路径后,并不立即生效,还要复制复制/etc/skel目录为/home/haddoop,并修改其属主和属组为hadoop。

相关文章

网友评论

      本文标题:cp,chmod,chown,chgrg,grep命令应用实例和

      本文链接:https://www.haomeiwen.com/subject/qqsnuxtx.html