第四周作业

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

                使用到命令chmod

                    chmod 修改文件或目录权限

                        chmod [option] MODE    file

                                option

                                    -R 递归修改

[root@localhost ~]# cp -r /etc/skel /home/tuser1
[root@localhost ~]# ll /home/tuser1 -d
drwxr-xr-x 2 root root 59 Feb  2 12:30 /home/tuser1
[root@localhost ~]# chmod 700 /home/tuser1
[root@localhost ~]# ll /home/tuser1/ -d
drwx------ 2 root root 59 Feb  2 12:30 /home/tuser1/

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

[root@localhost ~]# echo "hadoop:x:3007:" >>/etc/group
[root@localhost ~]# tail -1 /etc/group

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

[root@localhost ~]# echo  "hadoop:x:3007::3007::/home/hadoop:/bin/bash" >> /etc/passwd

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

[root@localhost ~]# cp  -a /etc/skel/ /home/hadoop
[root@localhost ~]# chmod 700 /home/hadoop
[root@localhost ~]# ll -d /home/hadoop/
drwx------. 2 root root 59 Oct 27 18:20 /home/hadoop/

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

[root@localhost ~]# chown -R hadoop:hadoop /home/hadoop
[root@localhost ~]# ll -d /home/hadoop/
drwx------. 2 hadoop hadoop 59 Oct 27 18:20 /home/hadoop/

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

        使用到命令grep 文本过滤工具

                    grep [option] PATTERN file   

                        option

                                  -i  忽略大小写

                                 -o 只显示匹配到的文本

                                 -v 只显示不匹配的文本

                                 -E 支持扩展正则表达式

                                 -q 不输出任何内容

                                 -A #  后#行

                                 -B  # 前#行

                                 -C # 前后各#行

                        PATTERN支持使用正则表达式和扩展的正则表达式

方法1

[root@localhost ~]# grep -i ^s /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       1048572 kB
SwapFree:        1048572 kB
Shmem:              4676 kB
Slab:              51208 kB
SReclaimable:      26556 kB
SUnreclaim:        24652 kB

方法2

[root@localhost ~]# grep ^[s,S] /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       1048572 kB
SwapFree:        1048572 kB
Shmem:              4676 kB
Slab:              51208 kB
SReclaimable:      26556 kB
SUnreclaim:        24652 kB

  方法3

[root@localhost ~]# grep -E "^(s|S)" /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       1048572 kB
SwapFree:        1048572 kB
Shmem:              4676 kB
Slab:              51208 kB
SReclaimable:      26556 kB
SUnreclaim:        24652 kB

  

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

[root@localhost ~]# grep -v "/sbin/nologin" /etc/passwd| cut -d: -f 1
root
sync
shutdown
halt
mageia
slackware
clouds
openstack
hadoop

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

[root@localhost ~]# grep "/bin/bash" /etc/passwd| cut -d: -f 1
root
mageia
clouds
openstack
hadoop

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

[root@localhost ~]# grep -E "\<[0-9]{1,2}\>" /etc/passwd
root:x:0:0:root:/root:/bin/bash
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
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
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
dbus:x:81:81:System message bus:/:/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

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

[root@localhost ~]# grep -E ^" " /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
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
  set timeout_style=menu
  set timeout=5
  set timeout=5
  source ${prefix}/user.cfg
  if [ -n ${GRUB2_PASSWORD} ]; then
    set superusers="root"
    export superusers
    password_pbkdf2 root ${GRUB2_PASSWORD}
  fi
  source ${config_directory}/custom.cfg
  source $prefix/custom.cfg;
[root@localhost ~]# grep  ^" " /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
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
  set timeout_style=menu
  set timeout=5
  set timeout=5
  source ${prefix}/user.cfg
  if [ -n ${GRUB2_PASSWORD} ]; then
    set superusers="root"
    export superusers
    password_pbkdf2 root ${GRUB2_PASSWORD}
  fi
  source ${config_directory}/custom.cfg
  source $prefix/custom.cfg;

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

[root@localhost ~]# 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’,后或跟空白字符结尾的行;

[root@localhost ~]# netstat -tan|grep "LISTEN"' '*$
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@localhost ~]# grep -E "^(\<[[:alnum:]]+\>).*\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:3007:3008::/home/bash:/bin/bash
nologin:x:3010:3011::/home/nologin:/sbin/nologin
[root@localhost ~]# grep "^\([[:alnum:]]\+\>\).*\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:3007:3008::/home/bash:/bin/bash
nologin:x:3010:3011::/home/nologin:/sbin/nologin

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

方法1
[root@localhost ~]# grep -i ^s /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       1048572 kB
SwapFree:        1048572 kB
Shmem:              4676 kB
Slab:              51208 kB
SReclaimable:      26556 kB
SUnreclaim:        24652 kB
方法2
[root@localhost ~]# grep ^[s,S] /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       1048572 kB
SwapFree:        1048572 kB
Shmem:              4676 kB
Slab:              51208 kB
SReclaimable:      26556 kB
SUnreclaim:        24652 kB
  方法3
[root@localhost ~]# grep -E "^(s|S)" /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       1048572 kB
SwapFree:        1048572 kB
Shmem:              4676 kB
Slab:              51208 kB
SReclaimable:      26556 kB
SUnreclaim:        24652 kB

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

[root@localhost ~]# grep -E "/sbin/nologin$" /etc/passwd |cut -d: -f1
bin
daemon
adm
lp
mail
operator
games
ftp
nobody
avahi-autoipd
systemd-bus-proxy
systemd-network
dbus
polkitd
tss
postfix
sshd
mysql
nologin

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

[root@localhost ~]# grep -E "/bin/bash$" /etc/passwd |cut -d: -f1
root
mageia
clouds
openstack
hadoop
bash
testbash
basher

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

[root@localhost ~]# grep -E "\<[0-9]{1,2}\>" /etc/passwd
root:x:0:0:root:/root:/bin/bash
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
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
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
dbus:x:81:81:System message bus:/:/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

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

(0)
胡安慧胡安慧
上一篇 2017-02-02 20:33
下一篇 2017-02-03 14:28

相关推荐

  • shell编程进阶

    2、编写脚本/root/bin/yesorno.sh,提示用户输入yes或no,并判断用户输入的是yes还是no,或是其它信息 read -p “Enter you choice yes|no:” Choice Choice1=`echo $Choice | tr ‘[a-z]’ ‘[A-Z]&#8…

    2017-09-16
  • 马哥教育网络班20期+第6周课程练习

    vim编辑器使用总结 一、文件的打开与关闭             打开文件:                 # vim [OPTION]… FILE…      …

    Linux干货 2016-07-17
  • 实现CA和证书申请,

    接下来讲的是在centos7.3和centos6.8中实现CA和证书申请,centos7.3作为主机,centos6.8作为客户端 首先你授权客户端CA证书,必须本身主机也具有CA,自己证明自己,先CA自签证书,然后在7.3创建私钥 为了方便以后的操作CD进入 cd /etc/pki/CA   生成自签名证书 -new:  生成…

    2017-04-11
  • mongodb数据库切分

    前言:  相信维护过有大数据的MySQL的运维人员一定对sharding这个非常了解,MySQL数据库切分自身没有工具需要借助第三方工具进行;MySQL切片是一件非常头疼而又难做的一件事,一旦切分错误,不仅不能优化数据库,反而会加剧数据库负载;mongodb相对于MySQL来说,数据库切分是mongodb与生俱来的功能,mongodb会自动切分数据…

    Linux干货 2015-09-05
  • 第四周小结

    这周我们主要学习了写脚本的简单语法,写了一些简单的脚本,下面就由我来简单介绍一下: 第一步使用文本编辑来创建脚本: 创建好后在里面写想要运行的脚本即可,然后按Esc—wq退出保存即可。也可以按q不保存退出;q!不保存强制退出;wq!保存强制退出。 第二步运行脚本,给予执行权限,在命令行上指定脚本的相对路径和绝对路径 对了,当在脚本里输入内容时,要Ese&#8…

    2017-08-06
  • Linux 文本编辑器三剑客之 sed

    参考手册: http://www.gnu.org/software/sed/manual/sed.html 转载请注明:马哥教育!!

    Linux干货 2017-01-12