集中练习2

用户管理、文本处理、文件管理相关

(1) 复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其他用户均没有任何访问权限。
“`
~]# cp -r /etc/skel /home/tuser1
~]# touch /home/tuser1/{a,b,c}
~]# mkdir /home/tuser1/abc/db/dc -pv
~]# tree /home/tuser1
/home/tuser1
├── a
├── abc
│ └── db
│ └── dc
├── b
└── c
~]# ll /home/tuser1
total 0
-rw——-. 1 root root 0 Sep 19 19:13 a
drwx——. 3 root root 16 Sep 19 19:12 abc
-rw——-. 1 root root 0 Sep 19 19:13 b
-rw——-. 1 root root 0 Sep 19 19:13 c
~]# ls -ld /home/tuser1
drwx——. 4 root root 116 Sep 19 19:13 /home/tuser1
“`
(2) 编辑/etc/group文件,添加组hadoop。
“`
~]# vim /etc/group
在文件末尾添加一行:hadoop:x:1008:
~]# tail -1 /etc/group
hadoop:x:1008:
“`
(3) 手动编辑/etc/passwd文件新增一行,添加用户hadoop,其基本组ID为hadoop组的id号;其家目录为/home/hadoop。
“`
~]# vim /etc/passwd
在文件末尾添加一行:hadoop:x:1008:1008::/home/hadoop:/bin/bash
~]# tail -1 /etc/passwd
hadoop:x:1008:1008::/home/hadoop:/bin/bash
“`
(4) 复制/etc/skel目录为/home/hadoop,要求修改hadoop目录的属组和其他用户没有任何访问权限。
“`
~]# cp -r /etc/skel /home/hadoop
~]# chmod go-rwx /home/hadoop
~]# ls -ld /home/hadoop
drwx——. 3 root root 78 Sep 19 19:23 /home/hadoop
“`
(5) 修改/home/hadoop目录及其内部所有文件的属主为hadoop,属组为hadoop。
“`
~]# mkdir /home/hadoop/test
~]# touch /home/hadoop/test/{a,b,c,d}
~]# tree /home/hadoop
/home/hadoop
└── test
├── a
├── b
├── c
└── d
~]# chown -R hadoop:hadoop /home/hadoop
~]# ls -ld /home/hadoop
drwx——. 4 hadoop hadoop 90 Sep 19 19:28 /home/hadoop
~]# ll /home/hadoop/test/
total 0
-rw-r–r–. 1 hadoop hadoop 0 Sep 19 19:28 a
-rw-r–r–. 1 hadoop hadoop 0 Sep 19 19:28 b
-rw-r–r–. 1 hadoop hadoop 0 Sep 19 19:28 c
-rw-r–r–. 1 hadoop hadoop 0 Sep 19 19:28 d
“`
(6) 显示/proc/meminfo文件中以答谢或小写s开头的行;用两种方式。
“`
方法1:~]# grep -i “^s” /proc/meminfo
方法2:~]# grep -E “^(s|S)” /proc/meminfo
方法3:~]# grep “^[s,S]” /proc/meminfo
“`
(7) 显示/etc/passwd文件中其默认shell为非/sbin/nologin的用户。
“`
~]# grep -v “/sbin/nologin$” /etc/passwd | cut -d: -f1
root
sync
shutdown
halt
sapbcs
openstack
mariadb
gentoo
fedora
centos
tom
jerry
neo
hadoop
“`
(8) 显示/etc/passwd文件中其默认shell为/bin/bash的用户。
“`
~]# grep “/bin/bash$” /etc/passwd | cut -d: -f1
root
sapbcs
openstack
gentoo
fedora
centos
tom
jerry
neo
hadoop
“`
(9) 找出/etc/passwd文件中的一位数或两位数。
“`
~]# grep -E “\<[0-9]\>|\<[1-9][0-9]\>” /etc/passwd
“`
(10) 显示/boot/grub/grub.conf中至少一个空白字符开头的行。
“`
CentOS7没有题中的文件,我换了一个文件。
~]# grep -E “^[[:space:]]+” /boot/grub2/grub.cfg
“`
(11) 显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行。
“`
CentOS7中没有题中的文件,我换了一个文件
~]# grep -E “^#[[:space:]]+.*[^[:space:]]+” /etc/rc.d/rc.local
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
# Please note that you must run ‘chmod +x /etc/rc.d/rc.local’ to ensure
# that this script will be executed during boot.
“`
(12) 打出netstat -tan命令执行结果中以’LISTEN’,后或跟空白字符结尾的行。
“`
~]# netstat -tan | grep -E “LISTEN[[:space:]]+”
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 192.168.122.1:53 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
tcp6 0 0 :::111 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:631 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN
“`
(13) 添加用户bash,testbash,basher,nologin(此一用户的shell为/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户的信息。
“`
~]# useradd bash
~]# useradd testbash
~]# useradd basher
~]# useradd nologin -s /sbin/nologin
~]# grep -E “^(\<[[:alpha:]]+[^:]\>).*\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:1009:1009::/home/bash:/bin/bash
nologin:x:1012:1012::/home/nologin:/sbin/nologin
“`

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/87470

(0)
N27_sapbcsN27_sapbcs
上一篇 2017-09-20 17:49
下一篇 2017-09-20 17:51

相关推荐

  • MySQL高级特性-合并表

    1. Merge Tables         如果愿意的话,可以把合并表看成一种较老的、有更多限制的分区表,但是它们也有自己的用处,并且能提供一些分区表不能提供的功能。 合并表实际是容纳真正的表的容器。可以使用特殊的UNION语法来CREATE TABLE。下面是一个合并表的例子: mysql> &n…

    Linux干货 2015-04-13
  • shell编程之条件判断和find查询

    使用read 来把输入值分配给一个或多个shell 变量: -p 指定要显示的提示 -t TIMEOUT read 从标准输入中读取值,给每个单词分配一个变量 所有剩余单词都被分配给最后一个变量 read -p “Enter a filename: “ FILE   条件选择if语句  多分支 if  CONDITION1 ; …

    Linux干货 2016-08-18
  • Linux文件类型及颜色标示

    在Linux系统中,有多种文件类型,不同的文件类型有不同的颜色。 ls -l 目录,这个命令可以在显示的类容中的第一个位置查看目录里面文件的类型。 Linux下用字符表示的文件类型 -:普通文件 d:目录文件 l:链接文件 b:块设备文件 c:字符设备文件 p:管道文件 同时 白色:表示普通文件 蓝色:表示目录 绿色:表示可执行文件 红色:表示压缩文件 浅蓝…

    Linux干货 2016-10-17
  • Linux基础知识之cp mv rm

    该博文以CentOS6.8_x86_64系统为基础,Xshell 5远程连接CentOS系统,以root身份登录系统和sjsir普通用户身份登录系统。 为什么要学习cp、mv、rm命令?     cp、mv、rm命令为Linux系统使用最长使用的三个命令之一,复制、移动和删除是我们平时处理一些文件必须要学会的命令,应该用于熟练掌握和使用的…

    Linux干货 2016-07-29
  • Linux入门详解(第一周)

    Linux入门 1. 描述计算机的组成及其功能 计算机硬件的五大组成部分为:运算器、控制器、存储器、输入设备和输出设备; CPU:CPU是执行存储在主存中指令的引擎;内部又分为算数逻辑单元和控制单元,其中算数逻辑单元主要负责程序的运算与逻辑判断,控制单元则主要是协调各周边组件与各单元间的工作;此外CPU内还包含寄存器(如PC)和高速缓存等; 存储器:这里指主…

    Linux干货 2016-08-29
  • 系统基础之shell脚本编程详解4(数组及字符串处理,变量赋值和配置文件)

    系统基础之shell脚本编程详解4(数组及字符串处理,变量赋值和配置文件)     今天来讲shell脚本编程的最后一些内容,数组及字符串处理,变量赋值和配置文件.这些内容也是我们经常在工作中使用到的知识点.下面让我们来详细了解下: 数组:   程序=指令+数据        &…

    Linux干货 2016-08-24