Linux Basics–part4

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

~]# cp -rf /etc/skel/ /home/tuser1 && chmod -R go=— /home/tuser1

[root@ronny1 ~]# ll -d /home/tuser1/

drwx——. 3 root root 78 8月  1 00:22 /home/tuser1/

[root@ronny1 ~]# ll -a /home/tuser1/

总用量 12

drwx——.  3 root root  78 8月  1 00:22 .

drwxr-xr-x. 17 root root 230 8月  1 00:22 ..

-rw——-.  1 root root  18 8月  1 00:22 .bash_logout

-rw——-.  1 root root 193 8月  1 00:22 .bash_profile

-rw——-.  1 root root 231 8月  1 00:22 .bashrc

drwx——.  4 root root  39 8月  1 00:22 .mozilla

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

~]# vim /etc/group     

###GG到最后一行  o进入编辑###

hadoop:x:5004:

~]# tail -n 1 /etc/group

hadoop:x:5004:

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

~]# vim /etc/passwd

###GG到最后一行  o进入编辑###

hadoop:x:2003:5004::/home/hadoop:/bin/bash

~]# tail -n 1 /etc/passwd

hadoop:x:2003:5004::/home/hadoop:/bin/bash

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

~]# cp -rf /etc/skel/ /home/hadoop && chmod -R go=— /home/hadoop

原理同1题

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

~]# chown -R hadoop:hadoop /home/hadoop/

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

~]# cat /proc/meminfo | grep  “^[sS]\+.*”

或

~]#cat /proc/meminfo | grep -i “^s\+.*”

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

~]# grep -v “/sbin/nologin$” /etc/passwd | cut -d: -f1

root

sync

shutdown

halt

amandabackup

ronny

ronny1.1

gentoo

fedora

www

centos

user1

mageia

slackware

hadoop

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

[root@ronny1 ~]# grep “/bin/bash$” /etc/passwd |cut -d: -f1

root

amandabackup

ronny

ronny1.1

gentoo

fedora

www

centos

user1

mageia

hadoop

9、找出/etc/passwd中的一位数或二位数

 ~]# grep -E -o “\<[0-9]\>|\<[1-9][0-9]\>” /etc/passwd | sort -n

0

0

0

0

0

0

1

1

1

1

2

……

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

~]# grep -E “^[[:space:]]+” /boot/grub/grub.conf

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

~]# grep -E “^#[[:space:]]+.*[^[:space:]]+” /etc/rc.d/rc.sysinit

12、打出netstat -tan命令执行结果中以“Listen”,后或跟空白字符结尾的行

~]# netstat -tan | grep -E  “.*LISTEN[[:space:]]+$”

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

~]# useradd bash

~]# useradd testbash

~]# useradd basher

~]# 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

nologin:x:4009:4009::/home/nologin:/sbin/nologin

bash:x:4011:4011::/home/bash:/bin/bash

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

赞 (0)
N27_ronnyN27_ronny
上一篇 2017-08-07 02:17
下一篇 2017-08-07 08:21

相关推荐

  • N25-第四周博客作业

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

    Linux干货 2016-12-25
  • DNS服务和搭建

    DNS服务:        名字解析        DNS 服务        实现主从服务器        实现子域        实现view  …

    2017-04-16
  • yum安装报错

    我的系统是centos 6.8 x86 安装bind时出错如下: [root@Ams ~]# yum install bind -y Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Install Process Loading mirror speeds from…

    Linux干货 2016-08-02
  • 文本处理工具之grep

                    文本处理工具之grep 一、grep的简介 1、grep是一个文本过滤器的工具,它根据用户指定的模式(pattern)对目标文本进行匹配检查,并将匹配的行打印到标准输出或输出重定向。 2、模式:由文本字符或正则表达式组成 3、正则表达式分…

    2017-05-06
  • 01葵花宝典之Linux基础知识

    linux, ifconfig, man, pwd, echo, date, hwclock, fhs

    2018-03-01
  • 点名脚本

    脚本要求:1、随机抽点80以内的随机证书;                2、可以一次抽取多个随机数;同时间抽取的随机数要唯一;                3、被抽取之后的随机数,之后不会再抽取;…

    2017-05-08

评论列表(1条)

  • 马哥教育
    马哥教育 2017-08-20 19:07

    这次作业考察的是些基础的操作命令,熟练掌握,在以后的工作中会更加的得心应手。