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
下一篇 2016-08-22

相关推荐

  • 有关磁盘管理与文件系统

    硬盘物理结构      扇区  磁头  磁道   柱面   磁道数      扇区*一个磁道上的扇区个数*磁头数=柱面      柱面*磁道数=硬盘大小      一个扇区512字节   &…

    2017-08-19
  • 第七周作业

    1、创建一个10G分区,并格式为ext4文件系统;   (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;   (2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳; [root@localhost ~]# fdis…

    Linux干货 2017-07-04
  • Linux文本编辑器之 vi vim 详谈

    Linux文本编辑器之 vi vim         vi :Visual Interface,它与sed不同,sed是功能比较简单的行编辑器,而vi是一个功能强大的全屏文本编辑器,它还有一个增强版vim (Vi IMproved).在vim里,有很多功能强大的文本编辑…

    Linux干货 2016-08-15
  • LVS:三种模式的原理、调度算法、及应用介绍

    LVS三种模式原理(nat/dr/tun) LVS/NAT:   如上图,客户通过virtual IP (虚拟服务的IP地址,公网地址),访问网络服务时,请求报文到达调度器,调度器根据连接调度算法从一组真实服务器中选出一台服务器,将报文的目标地址VIP,改写成选定服务器的地址(RIP),报文的目标端口改写成选定服务器的相应端口,最后将修改…

    Linux干货 2016-10-30
  • 什么是Ansible?

    自动化工具——ansible   ansibleArchitecture ansibleProject 1. 什么是ansible ansible是个什么东西呢?官方的title是“Ansible is Simple IT Automation”——简单的自动化IT工具。这个工具的目标有这么几项:让我们自动化部署APP;自动化管理配置项;自动化的持…

    2017-09-24
  • Net-25第5周作业

    1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行; grep -E "^[[:space:]]+" /boot/grub/grub.conf 2、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行; grep&nbsp…

    Linux干货 2017-01-03

评论列表(1条)

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

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