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.www58058.com/37329

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

相關推薦

  • 密碼保護:ansible書籍部分目錄

    無法提供摘要。這是一篇受保護的文章。

    Linux干貨 2015-12-14
  • linux 磁盤管理

    1、查看系統存在硬盤:lsblk  2、對磁盤分區操作:fdisk /dev/sda p: 顯示當前硬件的分區,包括沒保存的改動 n: 創建新分區 e: 擴展分區 p: 主分區 d: 刪除一個分區 w: 保存退出 t: 修改分區類型 L:顯示所支持的所有類型 3、在CentOS 5和7 使用partprobe同步分區。 4、mkfs -t 文件類型…

    Linux干貨 2017-08-13
  • Windows與linux分區的區別:

        對于我們普通人來講,分區就是我們看到的“我的電腦”下面的C盤、D盤、E盤······,每個分區都有自己的區域,無法使用別的分區的空間,這樣可以起到保護分區中文件的作用。其實,這樣很容易理解。可是,對于linux初學者來講,因為使用習慣了windows,到了linux下面,一下子很難轉換過來。  &nb…

    2017-07-16
  • N25第六周總結:vim編輯器詳解

    vim編輯器 一、      大綱 1、   什么是vim編輯器 2、   為什么要使用vim編輯器 3、   vim編輯器能實現哪些功能 4、   vim編輯器詳解   二、   &nbs…

    Linux干貨 2017-01-12
  • Mysql cmake 編譯安裝、

    基于cmake的mysql安裝 1.1 前言 從mysql5.5起,mysql源碼安裝的編譯工具configure開始向cmake過渡。安裝方式和之前的略有不同。在這里簡單介紹總結下。 安裝之前,檢查下GNU make, GCC, Perl, libncurses5-dev,cmake-2.8.4是否都已經安裝,如果沒有安裝,用yum install 安裝補…

    Linux干貨 2017-08-29
  • Linux之查找命令find簡介

    查找命令find簡介    Linux使用過程中難免會遇到查找功能,類似于Windows中的搜索功能,如果想要找某個文件在什么地方,什么格式的文件等等。在Linux中我們可以使用find、locate、which、whereis等命令。接下來我們就簡單說一下如何使用這幾個命令查找文件。 一、which which命令的作用是,在PATH變…

    Linux干貨 2015-05-18

評論列表(1條)

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

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

欧美性久久久久