Linux用户操作、文件操作、文件筛选

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

赞 (0)
TheoTheo
上一篇 2016-11-17 18:41
下一篇 2016-11-17 21:29

相关推荐

  • 编译安装Apache

    实验环境:CentOS 6 安装包版本:httpd-2.2.29.tar.bz2 一、安装前准备     (1)、获取httpd-2.2.29.tar.bz2安装包     (2)、准备开发工具,安装相应的包组 yum groupinstall -y&nbsp…

    Linux干货 2016-08-24
  • 初来乍到

    坐上了去往北方的火车,我不知道自己为什么会颤抖,也许是耳朵里那首汪峰的《北京,北京》震撼到了我,接着满脑子便是灯红酒绿的大街道和浮华的高楼大厦,我幻想着有一天能在这样的大城市中闯出一片天。梦醒了 ! 30个小时的路程确实是让我满脑子都是未来的自己。 对于我这个从来没有见过世面的人来说,第一次来到北京这座一线大城市,内心充满着无比的欣喜和激动,但更多的还是那份…

    Linux干货 2018-03-26
  • 常用命令总结

    ifconfig查看IP地址 date查看日期和时间 cd跳转到任何目录 useradd新建一个普通用户 passwd给用户设置密码 poweroff   halt    关机 reboot  重启 cal  查看日历 cal -y 查看一年日历 env  export&nbsp…

    Linux干货 2017-04-04
  • 压缩打包工具

    linux系统常见的压缩命令:compress、gzip、zcat、bzip2、xz、zip 打包命令:tar、cpio compress 语法:compress  [-dfvcVr]  [-b maxbits]  [file …]        …

    2017-08-12
  • N25_第五周

    1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行;grep -E "^[[:space:]]+" /boot/grub2/grub.cfg 2、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行;grep -E "^#[[:space:]…

    Linux干货 2017-01-08
  • 马哥教育网络班21期-第六周课程练习

    请详细总结vim编辑器的使用并完成以下练习题 vim编辑器的使用 vim模式:  a,编辑/命令模式;  b,insert/输入模式  c,末行模式 打开文件:  vim    [option]…    file…  +#:打开文件后,直接让光标…

    Linux干货 2016-08-22