一、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
评论列表(1条)
写的很好,排版也很棒,加油