N22-妙手 第4天视频课程练习

一、Globbing文件名通配练习

练习1:显示/var目录下所有以l开头,以一个小写字母结尾,且中间出现任意一位字符的目录

[root@localhost ~]# ls -d /var/l?[[:lower:]]
/var/lib  /var/log

练习2:显示/etc目录下,以任意一位数字开头,且以非数字结尾的文件或目录

[root@localhost ~]# ls -d /etc/[0-9]*[^0-9]
/etc/8sfsdf

练习3:显示/etc目录下,以非字母开头,后面跟一个字母及其他任意长度任意字符的文件或目录

[root@localhost ~]# ls /etc/[^[:alpha:]][[:alpha:]]*
/etc/8sfsdf

练习4:复制/etc目录下,所有以m开头,以非数字结尾的文件或目录至/tmp/magedu.com目录

[root@localhost ~]# mkdir /tmp/magedu.com
[root@localhost ~]# cp -r /etc/m*[^[:digit:]] /tmp/magedu.com
[root@localhost ~]# ls /tmp/magedu.com
machine-id  mail.rc                   maven        modprobe.d      mtab         my.cnf
magic       makedumpfile.conf.sample  mime.types   modules-load.d  mtools.conf  my.cnf.d
mailcap     man_db.conf               mke2fs.conf  motd            multipath

练习5:复制/usr/share/man目录下所有以man开头,后跟一个数字结尾的文件或目录至/tmp/man目录下

[root@localhost ~]# mkdir /tmp/man
[root@localhost ~]# cp -r /usr/share/man/man*[0-9] /tmp/man
[root@localhost ~]# ls /tmp/man
man1  man2  man3  man4  man5  man6  man7  man8  man9

练习6:复制/etc目录下,所有以.conf结尾,且已m,n,r,p开头的文件或目录至/tmp/conf.d/目录下

[root@localhost ~]# mkdir /tmp/conf.d
[root@localhost ~]# cp -r /etc/[mnrp]*.conf /tmp/conf.d
[root@localhost ~]# ls /tmp/conf.d
man_db.conf  nfsmount.conf  numad.conf    pnm2ppa.conf      resolv.conf
mke2fs.conf  nsswitch.conf  pbm2ppa.conf  radvd.conf        rsyncd.conf
mtools.conf  ntp.conf       pcp.conf      request-key.conf  rsyslog.conf

二、tee命令练习

练习1:把/etc/passwd文件的前6行的信息转换为大写字符后输出

[root@localhost ~]# head -6 /etc/passwd | tr a'a-z' 'A-Z'
SPPU:Y:0:0:SPPU:/SPPU:/CJO/CBTI
CJO:Y:1:1:CJO:/CJO:/TCJO/OPMPHJO
EBFNPO:Y:2:2:EBFNPO:/TCJO:/TCJO/OPMPHJO
BEN:Y:3:4:BEN:/WBS/BEN:/TCJO/OPMPHJO
MQ:Y:4:7:MQ:/WBS/TQPPM/MQE:/TCJO/OPMPHJO
TZOD:Y:5:0:TZOD:/TCJO:/CJO/TZOD

三、用户、用户组练习

练习1:创建用户gentoo,UID为4001,基本组为gentoo,附加组为distro9G(GID为5000)和peguin(GIDw为5001)

[root@localhost ~]# groupadd -g 5000 distro9G
[root@localhost ~]# groupadd peguin
[root@localhost ~]# useradd -u 4000 -G distro9G,peguin gentoo
[root@localhost ~]# id gentoo
uid=4000(gentoo) gid=4000(gentoo) groups=4000(gentoo),5000(distro9G),5001(peguin)

练习2:创建用户fedora,其注释信息为"Fedora Core",默认shell为/bin/tcsh

[root@localhost ~]# useradd -c "Fedora Core" -s /bin/tcsh fedora
[root@localhost ~]# id fedora
uid=4001(fedora) gid=4001(fedora) groups=4001(fedora)
[root@localhost ~]# tail -1 /etc/passwd
fedora:x:4001:4001:Fedora Core:/home/fedora:/bin/tcsh

练习3:修改用户gentoo的家目录为 /var/tmp/gentoo;要求其原有文件仍能被用户访问

[root@localhost ~]# usermod -d /var/tmp/gentoo gentoo
[root@localhost ~]# ls /var/tmp
[root@localhost ~]# tail -2 /etc/passwd
gentoo:x:4000:4000::/var/tmp/gentoo:/bin/bash
fedora:x:4001:4001:Fedora Core:/home/fedora:/bin/tcsh
[root@localhost ~]# ls /home/gentoo

练习4:为gentoo,新增附加组netadmin

[root@localhost ~]# groupadd netadmin
[root@localhost ~]# usermod -aG netadmin gentoo
[root@localhost ~]# id gentoo
uid=4000(gentoo) gid=4000(gentoo) groups=4000(gentoo),5000(distro9G),5001(peguin),5002(netadmin)

四、用户,用户组权限练习

1、新建系统组mariadb,新建系统用户mariadb,属于mariadb组,要求其没有家目录,且shell为/sbin/nologin;尝试root切换至此用户,查看其命令提示符

[root@localhost ~]# groupadd -r mariadb
[root@localhost ~]# useradd -r -M -g mariadb -s /sbin/nologin mariadb
[root@localhost ~]# id mariadb
uid=986(mariadb) gid=981(mariadb) groups=981(mariadb)
[root@localhost ~]# tail -1 /etc/passwd
mariadb:x:986:981::/home/mariadb:/sbin/nologin
[root@localhost ~]# su mariadb
This account is currently not available.
[root@localhost ~]# su - mariadb
Last login: Mon Aug 22 14:17:24 CST 2016 on pts/1
su: warning: cannot change directory to /home/mariadb: No such file or directory
This account is currently not available.

2、新建GID为6000的组mageedu,新建用户gentoo2,要求其家目录为/users/gentoo2,密码同用户名

[root@localhost ~]# groupadd -g 6000 mageedu
[root@localhost ~]# useradd -d /users/gentoo2 gentoo2
[root@localhost ~]# cd /users/gentoo2
[root@localhost gentoo2]# pwd
/users/gentoo2
[root@localhost gentoo2]# passwd gentoo2
Changing password for user gentoo2.
New password: 
BAD PASSWORD: The password contains the user name in some form
Retype new password: 
passwd: all authentication tokens updated successfully.

3、新建用户fedora,其家目录为/users/fedora,密码同用户名

[root@localhost ~]# useradd -d /users/fedora fedora
[root@localhost ~]# passwd fedora
Changing password for user fedora.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@localhost ~]# useradd -d /users/fedora fedora
[root@localhost ~]# passwd fedora
Changing password for user fedora.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.

4、新建用户www,其家目录为/users/www;删除www用户,但保留其家目录

[root@localhost fedora]# useradd -d /users/www www
[root@localhost fedora]# userdel www
[root@localhost fedora]# ls /users
fedora  gentoo  gentoo2  www

5、为用户gentoo和fedora新增附加组mageedu

[root@localhost fedora]# usermod -aG mageedu gentoo
[root@localhost fedora]# usermod -aG mageedu fedora
[root@localhost fedora]# id gentoo
uid=4003(gentoo) gid=4003(gentoo) groups=4003(gentoo),6000(mageedu)
[root@localhost fedora]# id fedora
uid=4005(fedora) gid=4005(fedora) groups=4005(fedora),6000(mageedu)

6、复制目录/var/log至/tmp/目录,修改/tmp/log及其内部的所有文件的属组为mageedu,并让属组对目录本身拥有写权限

[root@localhost ~]# cp -r /var/log /tmp/log_test
[root@localhost ~]# chgrp -R mageedu /tmp/log_test
[root@localhost ~]# ls -l /tmp/log_test
total 1276
drwxr-xr-x. 2 root mageedu    4096 Aug 22 14:35 anaconda
drwxr-x---. 2 root mageedu      22 Aug 22 14:35 audit
-rw-r--r--. 1 root mageedu   13601 Aug 22 14:35 boot.log
[root@localhost ~]# chmod g+w /tmp/log_test
[root@localhost ~]# ls -l /tmp
total 356
drwxr-xr-x.  2 root root       4096 Aug 22 13:47 conf.d
prw-------.  1 root root          0 Aug 19 01:52 hogsuspend
-rw-r--r--.  1 root root      13948 Aug 19 06:10 iop
drwxrwxr-x. 20 root distro9G   4096 Aug 19 02:15 log
drwxrwxr-x. 20 root mageedu    4096 Aug 22 14:35 log_test

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

(0)
mxb93mxb93
上一篇 2016-08-22 09:30
下一篇 2016-08-22 09:30

相关推荐

  • Codis集群3.03安装配置基础

    Codis基础 01.codis是一个分布式的Redis解决方案,对于上层的应用来说,连接Codis Proxy和连接原生的Redis Server没有明显的区别。 codis底层会处理请求的转发,不停机的数据迁移等工作,所有后边的一切事情,对于前面客户端来说是透明的,可以简单的认为后边连接是一个内存无限大的Redis服务。 codis架构图如下: 02.c…

    Linux干货 2016-09-26
  • Linux的常用的计划任务(一次任务与周期性任务) at & cron

      在Linux日常维护工作中,维护员不可能每时每刻都守在服务前前,但如果遇到例行的操作要进行怎么办?设定计划任务!     Linux任务计划、周期性任务执行     • 未来的某时间点执行一次任务:      &n…

    Linux干货 2016-09-09
  • memcache

      memcached: memcached is a high-performance, distributed memory object caching system, generic in nature, but&nbsp…

    Linux干货 2016-11-01
  • keepalived实现lvs的高可用

    lvs可以做到内核级别的四层负载均衡,具有非常强悍的负载均衡能力。但是,当我们构建lvs的负载均衡集群的时候也会面临一些很严重的问题: lvs的单点故障:当lvs负载均衡器出现故障的时候,那么后端所有的服务器都将无法访问; lvs对后台服务器没有健康监测机制:当后台服务器宕机之后lvs还是会调度服务到后台的服务器; 所以我们就需要一款工具来解决以上问题。 k…

    2017-07-03
  • linux终端类型

    终端分为:             ∟  物理终端         定义:可将显示器,键盘,鼠标直接接入主机接口的终端;     &nbsp…

    Linux干货 2016-10-18
  • old notes

    yum update: update software guest edition ***: how to install guest edition: 1) need to root: su – 2) yum install kernel-devel 3)yum install gcc* ( when don't remember n…

    Linux干货 2016-09-19

评论列表(1条)

  • 马哥教育
    马哥教育 2016-08-22 14:10

    写的很好,排版也很棒,加油