集中练习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

相关推荐

  • AWK文本工具和软件包管理

    AWK文本工具 两种版本1.nawk   2.gawk gawk    模式扫描和处理语言 选项: -F 指明输入时用到的字段分隔符 -v  var=value:自定义变量 基本格式: awk [options] ’program’   file…. program:pattern{action statrments;………

    Linux干货 2018-03-15
  • 管道及重定向

    管道及重定向 1、重定向 在Linux中有时我们在命令的执行过程中,不想将执行结果显示到屏幕上,或者将其结果输出到其他位置 这时就需要重定向来解决这个问题了 首先了解一下Linux中的3种I/O设备: 0:标准输入 1:标准输出 2:标准错误输出 输出重定向:> >> 输入重定向: < << >:将标准输出重定向到文…

    Linux干货 2017-07-28
  • 操作系统文件管理

      在现代计算机系统中,要用到大量的程序和数据,因内存容量有限,且不能长期保存,故而平时总是把它们以文件的形式存放在外存中,需要时再随时将它们调入内存。如果由用户直接管理外存上的文件,不仅要求用户熟悉外存特性,了解各种文件的属性,以及它们在外存上的位置,而且在多用户环境下,还必须能保持数据的安全性和一致性。显然,这是用户所不能胜任、也不愿…

    Linux干货 2015-04-13
  • Bash Shell详解

    引言:什么是Shell? Linux的命令行接口归结起来就是各种Shell,那么到底什么是Shell?Shell,译为外壳,是用户直接连入计算机所使用的计算机程序,负责解析用户提供的命令,如词法分析、语法分析、句法分析。 1.Shell的分类 Linux 的命令 shell 是与操作系统相分离的一层。不同的 shell 环境影响您具备不同的功能,比如可编辑的…

    2017-09-07
  • Linux文件管理命令与bash的工作特性

    Shell程序在接受到用户执行命令的请求时,在分析完成之后,最左侧的字符串会被当作命令;
    命令查找机制:查找内部命令时,根据PATH环境变量中设定的目录,从左至右逐个搜索目录下的文件名;

    2018-03-11
  • nginx 配置参数说明和实验

    nginx.org 实验版本: 1.10.2 相关命令: # nginx -t //检查配置文件格式 #nginx -s reload //重新载入配置文件 实验: 主配文件大概组成 主配置文件的设定 /etc/nginx/nginx.conf events{..} //事件驱动相关 http{..} //网站服务相关 全局配置段解读与实验: user ng…

    2017-05-12