一、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.www58058.com/37329
寫的很好,排版也很棒,加油