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

相关推荐

  • N21天天第十四周课程练习

    系统的INPUT和OUTPUT默认策略为DROP; #把默认策略设置为DROP [root@localhost ~]# iptables -P INPUT DROP [root@localhost ~]# iptables -P OUTPUT DROP 1、限…

    Linux干货 2016-12-05
  • Linux入门基础知识

    1、计算机的组成及其功能。         计算机系统主要分为硬件系统和软件系统两部分。         (1)硬件系统由五部分组成,其中包括:         控制器:调度程序、数据、地址,协调计算机各部分工作及内存与外设的访问;         运算器:对数据进行加工处理;         存储器:存储程序、信号、命令,数据等信息,并在需要时提供这些信息…

    Linux干货 2018-02-25
  • Linux权限基本介绍,管理

     Linux权限机制采用UGO模式。其中 u(user)表示所属用户、g(group)表示所属组、o(other)表示除了所属用户、所属组之外的情况。 u、g、o 都有读(read)、写(write)、执行(excute) 三个权限,所以UGO模式是三类九种基本权限。         用命令 ls …

    Linux干货 2017-07-22
  • yum源设置

      yum是我们经常用到的一个程序,我们主要用它来安装或删除安装包,下面我来介绍一下怎样配置yum安装源?    配置yum安装源主要有两种方法:一种是用本地镜像做安装源,二是用提供镜像下载的网站做安装源。    一 配置本地安装源    本地安装源需要有系统镜像,操作步骤如下:…

    Linux干货 2016-01-16
  • 第五周:grep和find的使用练习

    1、显示当前系统上root、fedora或user1用户的默认shell; grep -E "^(root|fedora|user1)" /etc/passwd | cut -d: -f7 grep -E "^root|fedora|use…

    Linux干货 2016-10-25
  • 马哥教育网络班22期+第四周课程练习

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 [root@localhost ~]# cp -rf /etc/skel/ /home/tuser1 [root@localhost ~]# chmod&…

    Linux干货 2016-09-19