N25 – Week 4 blog

第四周博客作业了,感觉前面的有好多都忘掉了,但是没有时间补以前的啊……好郁闷,幸好今天周五,明天又是圣诞节,从马云爸爸买了一颗圣诞树,今晚回家装上N25 - Week 4 blog

1. 复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其他用户均没有任何访问权限

[root@dhcp-10-129-6-166 ~]# install -d -m u=rwx,go= /etc/skel /home/tuser1;ll -d /home/tuser1
drwx------. 2 root root 6 12月 23 14:09 /home/tuser1
[root@dhcp-10-129-6-166 ~]#

2. 编辑/etc/group文件,添加组hadoop

[root@dhcp-10-129-6-166 home]# echo "hadoop:x:3100:" >> /etc/group
[root@dhcp-10-129-6-166 home]# tail -1 /etc/group
hadoop:x:3100:
[root@dhcp-10-129-6-166 home]#

3. 手动编辑/etc/passwd文件新增一行,添加用户hadoop,,其基本组ID为hadoop组的ID号,其家目录为/home/hadoop

[root@dhcp-10-129-6-166 home]# tail /etc/passwd
mysql:x:996:994::/home/mysql:/bin/nologin
mariadb:x:995:993::/home/mariadb:/sbin/nologin
gentoo:x:2004:2004::/users/gentoo:/bin/bash
fedora:x:2005:2005::/users/fedora:/bin/bash
centos:x:2006:2006::/home/centos:/bin/bash
bash:x:2007:2007::/home/bash:/bin/bash
testbash:x:2008:2008::/home/testbash:/bin/bash
basher:x:2009:2009::/home/basher:/bin/bash
nologin:x:2010:2010::/home/nologin:/sbin/nologin
Bash:x:3001:3001::/home/Bash:/bin/bash
[root@dhcp-10-129-6-166 home]# echo "hadoop:x:3100:3100::/home/hadoop:/bin/bash" >> /etc/passwd
[root@dhcp-10-129-6-166 home]# tail -1 /etc/passwd
hadoop:x:3100:3100::/home/hadoop:/bin/bash

4. 复制/etc/skel目录为/home/hadoop, 要求修改hadoop目录的属组和其他用户没有任何访问权限

[root@dhcp-10-129-6-166 home]# install -d -m go-rwx /etc/skel /home/hadoop
[root@dhcp-10-129-6-166 home]# ll -d /home/hadoop
drwx------. 2 root root 6 12月 23 13:54 /home/hadoop
[root@dhcp-10-129-6-166 home]#

5. 修改/home/hadoop目录及其内部所有文件的属主为hadoop,属组为hadoop

[root@dhcp-10-129-6-166 home]# ll /home/hadoop
总用量 0
-rw-r--r--. 1 root root 0 12月 23 13:36 file1
-rw-r--r--. 1 root root 0 12月 23 13:36 file2
-rw-r--r--. 1 root root 0 12月 23 13:36 file3
-rw-r--r--. 1 root root 0 12月 23 13:36 file4
[root@dhcp-10-129-6-166 home]# chown -R hadoop:hadoop /home/hadoop;ll -r /home/hadoop
总用量 0
-rw-r--r--. 1 hadoop hadoop 0 12月 23 13:36 file4
-rw-r--r--. 1 hadoop hadoop 0 12月 23 13:36 file3
-rw-r--r--. 1 hadoop hadoop 0 12月 23 13:36 file2
-rw-r--r--. 1 hadoop hadoop 0 12月 23 13:36 file1
[root@dhcp-10-129-6-166 home]#

6. 显示/proc/meminfo文件中以大写或小写S开头的行,用两种方式

[root@dhcp-10-129-6-166 ~]# grep "^[sS]" /proc/meminfo
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:             13104 kB
Slab:              73684 kB
SReclaimable:      36116 kB
SUnreclaim:        37568 kB
[root@dhcp-10-129-6-166 ~]# grep "^(s|S)" /proc/meminfo
[root@dhcp-10-129-6-166 ~]# grep -E "^(s|S)" /proc/meminfo
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:             13104 kB
Slab:              73684 kB
SReclaimable:      36116 kB
SUnreclaim:        37568 kB

7. 显示/etc/passwd文件中其默认shell为非/sbin/nologin的用户

[root@dhcp-10-129-6-166 system]# grep -v "/sbin/nologin$" /etc/passwd
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
mageia:x:1100:1100::/home/linux:/bin/bash
slackware:x:2002:2016::/home/slackware:/bin/bash
openstack:x:2003:2020::/home/openstack:/bin/bash
mysql:x:996:994::/home/mysql:/bin/nologin
gentoo:x:2004:2004::/users/gentoo:/bin/bash
fedora:x:2005:2005::/users/fedora:/bin/bash
centos:x:2006:2006::/home/centos:/bin/bash
bash:x:2007:2007::/home/bash:/bin/bash
testbash:x:2008:2008::/home/testbash:/bin/bash
basher:x:2009:2009::/home/basher:/bin/bash
hadoop:x:3000:3000::/home/hadoop:/bin/bash
Bash:x:3001:3001::/home/Bash:/bin/bash

8. 显示/etc/passwd文件中其默认shell为/bin/bash的用户

[root@dhcp-10-129-6-166 ~]# grep "/bin/bash$" /etc/passwd
root:x:0:0:root:/root:/bin/bash
mageia:x:1100:1100::/home/linux:/bin/bash
slackware:x:2002:2016::/home/slackware:/bin/bash
openstack:x:2003:2020::/home/openstack:/bin/bash
gentoo:x:2004:2004::/users/gentoo:/bin/bash
fedora:x:2005:2005::/users/fedora:/bin/bash
centos:x:2006:2006::/home/centos:/bin/bash
bash:x:2007:2007::/home/bash:/bin/bash
testbash:x:2008:2008::/home/testbash:/bin/bash
basher:x:2009:2009::/home/basher:/bin/bash
hadoop:x:3000:3000::/home/hadoop:/bin/bash

9. 找出/etc/passwd文件中的一位数或两位数

[root@dhcp-10-129-6-166 ~]# grep -E -o "\<[0-9]\>|\<[0-9][0-9]\>" /etc/passwd
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@dhcp-10-129-6-166 ~]#

10. 显示/boot/grub/grub.conf中以至少一个空白字符开头的行

[root@dhcp-10-129-6-166 ~]# grep "^[[:space:]]\+" /boot/grub2/grub.cfg
  load_env
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
   set default="${saved_entry}"
  menuentry_id_option="--id"
  menuentry_id_option=""
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
...

11. 显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后有至少一个非空白字符的行

[root@dhcp-10-129-6-166 ~]# grep "^#[[:space:]][^[:space:]]" /etc/rc.d/rc.sysinit

12. 打出netstat -tan命令执行结果中以'LISTEN',后或根空白字符结尾的行

[root@dhcp-10-129-6-166 system]# netstat -tan | grep "\<LISTEN\>[[:space:]]\+$"
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN
tcp6       0      0 :::22                   :::*                    LISTEN
tcp6       0      0 ::1:25                  :::*                    LISTEN

13. 添加用户Bash,testbash, basher, nologin(此一个用户的shell为/sbin/nologin), 而后找出当前系统上其用户名和默认shell相同的用户的信息

[root@dhcp-10-129-6-166 system]# grep -E "^(\<[^:]+\>).*\<\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:2007:2007::/home/bash:/bin/bash
nologin:x:2010:2010::/home/nologin:/sbin/nologin

14. 显示/proc/meminfo文件中以大写或小写S开头的行,用三种方式

[root@dhcp-10-129-6-166 system]# grep "^[sS]" /proc/meminfo
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:             13104 kB
Slab:              73876 kB
SReclaimable:      36340 kB
SUnreclaim:        37536 kB
[root@dhcp-10-129-6-166 system]# grep -E "^(s|S)" /proc/meminfo
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:             13104 kB
Slab:              73876 kB
SReclaimable:      36340 kB
SUnreclaim:        37536 kB
[root@dhcp-10-129-6-166 system]# grep -i "^s" /proc/meminfo
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:             13104 kB
Slab:              73876 kB
SReclaimable:      36340 kB
SUnreclaim:        37536 kB

15. 显示/etc/passwd文件中其默认shell为非/sbin/nologin的用户

[root@dhcp-10-129-6-166 system]# grep "/sbin/nologin$" /etc/passwd
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin
systemd-network:x:998:996:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:997:995:User for polkitd:/:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
mariadb:x:995:993::/home/mariadb:/sbin/nologin
nologin:x:2010:2010::/home/nologin:/sbin/nologin

16. 显示/etc/passwd文件中其默认shell为/bin/bash的用户

[root@dhcp-10-129-6-166 system]# grep "/bin/bash$" /etc/passwd
root:x:0:0:root:/root:/bin/bash
mageia:x:1100:1100::/home/linux:/bin/bash
slackware:x:2002:2016::/home/slackware:/bin/bash
openstack:x:2003:2020::/home/openstack:/bin/bash
gentoo:x:2004:2004::/users/gentoo:/bin/bash
fedora:x:2005:2005::/users/fedora:/bin/bash
centos:x:2006:2006::/home/centos:/bin/bash
bash:x:2007:2007::/home/bash:/bin/bash
testbash:x:2008:2008::/home/testbash:/bin/bash
basher:x:2009:2009::/home/basher:/bin/bash
hadoop:x:3000:3000::/home/hadoop:/bin/bash
Bash:x:3001:3001::/home/Bash:/bin/bash

17. 找出/etc/passwd文件中的一位数或两位数

[root@dhcp-10-129-6-166 ~]# grep -E -o "\<[0-9]{1,2}\>" /etc/passwd
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@dhcp-10-129-6-166 ~]#

原创文章,作者:JL,如若转载,请注明出处:http://www.178linux.com/64267

(0)
JLJL
上一篇 2016-12-20
下一篇 2016-12-20

相关推荐

  • 第5周

    1, ~]# grep "^root\>" /etc/passwd | cut -d: -f7 4,~]# ifconfig | grep "\<[0-9][0-9][0-9]\>" 7, ~]# find /var -user root -group mail 8,~]# fin…

    Linux干货 2016-09-15
  • httpd服务——CentOS7

    httpd-2.4 新特性:      (1)MPM支持运行为DSO机制;以模块形式按需加载      (2)event MPM生产环境可用      (3)异步读写机制      (4)支持每个模块…

    Linux干货 2016-10-12
  • 文件处理命令作业题

    练习题    1.找出ifconfig命令结果中的本机的所有ipv4地址4    2.查出分区空间使用率的最大百分比值    3.查找用户UID最大值的用户名、UID及shell类型    4.查出/tmp的权限。以数字方式显示    5.统计当前链接本机的每…

    Linux干货 2016-08-08
  • grub启动

    grub: GRandUnified Bootloader(统一的引导模式分为3个阶段) grub 0.97: grub legacy grub 2.x: grub2 grub legacy: stage1: mbr stage1_5: mbr之后的扇区,让stage1中的bootloader能识别stage2所在的分区上的文件系统 stage2:磁盘分区(…

    Linux干货 2017-05-15
  • M21-陆东贵操作类作业

    1.     设置自己的终端提示符,要求字符终端登录时: a> 需要带颜色 b> 需要显示当前执行到了第几条命令 c> 显示当前登录终端,主机名和当前时间 解答:[root@localhost  13:19:55 37 ~]# PS1="[\[\e[1;31m\]\u@\h&nbs…

    Linux干货 2016-10-18
  • Linux文件查找

    什么是文件查找     在文件系统中查找符合条件的文件; 文件查找分为:     实时查找:遍历所有文件进行条件匹配(find)     非实时查找:根据索引查找(locate) locate  查询系统上预建的文件索引数据库 …

    Linux干货 2016-08-15