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

相关推荐

  • Linux下常用压缩工具总结

    gzip: 1)只能针对普通文件进行压缩,对文件夹、符号链接无效。 2)如果想对多个文件一起压缩并打包,gzip是无法办到的,需要结合tar进行 [root@mysql-master databackup]# ll 总用量 32 drwx—— 2 root root 4096&nb…

    Linux干货 2016-12-05
  • 马哥教育网络班22期+第1周课程练习

    1、描述计算机的组成及其功能 CPU:运算器、控制器、寄存器、缓存 存储器:内存,RAM(Random Access Memory) Input:下指令,提供数据等 Output:输出数据加工的结果 2、按系列罗列Linux的发行版,并描述不同发行版之间的联系与区别 Debian系列         ubuntu &n…

    Linux干货 2016-08-15
  • CentOS 5和6的启动流程

    Linux: kernel+rootfs  kernel: 进程管理、内存管理、网络管理、驱动程序、文件系统、安全功能 rootfs: glibc 库:函数集合, function, 调用接口 过程调用:procedure 函数调用:function 程序  内核设计流派: 单内核设计:Linux 把所有功能集成于同一个程序; 微内核设计…

    Linux干货 2016-08-23
  • 设计模式 ( 十二 ) 职责链模式(Chain of Responsibility)(对象行为

    1.概述        你去政府部门求人办事过吗?有时候你会遇到过官员踢球推责,你的问题在我这里能解决就解决,不能解决就推卸给另外个一个部门(对象)。至于到底谁来解决这个问题呢?政府部门就是为了可以避免屁民的请求与官员之间耦合在一起,让多个(部门)对象都有可能接收请求,将这些(部门)对象连接成一条链,并且沿着这条链传递…

    Linux干货 2015-07-15
  • N25-第三周作业

      列出当前系统上所有已经登陆的用户的用户名,注意:同一个用户登陆多次,则只显示一次即可。     2.取出最后登陆到当前系统的用户的相关信息。     3.取出当前系统上被用户当作其默认shell的最多的那个shell.     4.将/etc/password中的第三个字段数值最大的后…

    Linux干货 2016-12-19
  • shell脚本编程之if条件判断与for、while、until循环

    一、if语句 语法: if 测试条件1 ; then        分支1 elif  测试条件2; then        分支2 … else&nbsp…

    Linux干货 2015-08-24