LInux習題練習-04(yum源、用戶和組、文件權限、find)

習題練習-04

yum 練習題

  • 利用 yum 安裝tree 工具包與http 服務
    在web服務初期,由於經常編輯Apache配置文件,請爲該配置文件定義別名congfighttp
    /etc/httpd/conf/httpd.conf

      # 先進行yum源配置
      [root@localhost ~]# mkdir /mnt/cdrom
      [root@localhost ~]# mount /dev/sr0 /mnt/cdrom
      mount: /dev/sr0 is write-protected, mounting read-only
      [root@localhost ~]# cd /etc/yum.repos.d/
      [root@localhost yum.repos.d]# rm -rf *
      [root@localhost yum.repos.d]# vim yum_con.repo
      [yum_config]
      name = yum_config
      baseurl = file:///mnt/cdrom
      gpgcheck = 0
      enabled = 1
      [root@localhost yum.repos.d]# yum clean all
      [root@localhost yum.repos.d]# yum repolist all
    
      安裝tree
      [root@localhost yum.repos.d]# yum install tree -y
    
      [root@localhost yum.repos.d]# tree /root/
    
      安裝http 服務
      [root@localhost ~]# yum install httpd -y
    
      # 重命名配置文件
      [root@localhost ~]# vim /etc/bashrc 
      # 最後一行加入		
      alias confighttp='vim /etc/httpd/conf/httpd.conf'
    

用戶和組練習題

  1. 創建指定用戶和組

    • 增加urergrp組,GID號爲6000

        [root@localhost ~]# groupadd -g 6000 usergrp
      
    • 新增user1用戶,UID號爲6000,密碼爲空,並將其附屬組加入usergrp組中

        [root@localhost ~]# useradd -u 6000 -G usergrp user1
      
    • 新增user2用戶,密碼爲password,將用戶的附屬組加入root和usergrp組,用戶的主目錄爲/user2目錄

        [root@localhost ~]# useradd -d /user2 -G root,usergrp user2
        [root@localhost ~]# echo 'password' | passwd --stdin user2
      
    • 新增user3用戶,不爲用戶建立並初始化宿主目錄,用戶不允許登錄到系統的shell

        [root@localhost ~]# useradd -M -s /sbin/nologin user3
      
  2. 設置用戶的密碼期限

    • 設置user1用戶,在下此登錄時必須強制更改密碼

        [root@localhost ~]# chage -d 0 user1
      
    • 設置user2用戶,密碼30必須更改密碼,賬號在2016年10月10日過期

        [root@localhost ~]# chage -d 30 -E 2016-10-10 user2
      

文件權限練習題


  1. 新建目錄/var/www/user1,並設置如下權限

    • 將此目錄的所有者設置爲user1,並設置讀寫執行權限

    • 將此目錄的組設置爲usergrp,並設置讀執行權限

    • 將其他用戶的權限設置爲只讀

        [root@localhost ~]# mkdir /var/www/user1
        [root@localhost ~]# chown user1:usergrp /var/www/user1/
        [root@localhost ~]# chmod 754 /var/www/user1/
      
  2. 創建一個共享組ateam,該組中擁有兩個新用戶andy與alice,這兩個賬號的密碼是password

    • 在/home中創建名爲 ateam-text的目錄

    • 將ateam-text目錄的組所有權限更改爲ateam

    • 確保ateam-text的權限允許組成員創建和刪除文件

    • 確保ateam-text的權限禁止其他人訪問其文件

        [root@localhost ~]# groupadd ateam 
        [root@localhost ~]# useradd -G ateam andy
        [root@localhost ~]# useradd -G ateam alice
        [root@localhost ~]# echo 'password' | passwd --stdin andy
        Changing password for user andy.
        passwd: all authentication tokens updated successfully.
        [root@localhost ~]# echo 'password' | passwd --stdin alice
        Changing password for user alice.
        passwd: all authentication tokens updated successfully.
        [root@localhost ~]# mkdir /home/ateam-text
        [root@localhost ~]# chown :ateam /home/ateam-text/
        [root@localhost ~]# chmod g+w /home/ateam-text/
        [root@localhost ~]# chmod 770 /home/ateam-text/
      

其他練習題

  • find
    • 找出當前目錄下的目錄和普通文件

    • 找出當前目錄下10天沒有改變,大小小於4K的普通文件或目錄

      [root@localhost ~]# find . -type d -o -type f -size +4k ! -mtime -10

stat filename 查看文件狀態

關於Linux下三種時間的簡單介紹

  • atime(access time)
    • 顯示文件中的數據最後被訪問的時間,example: 可執行腳本文件
      • 此時最後被訪問時間是進程調用/腳本執行,不是查看(cat)
  • mtime(modify time)
    • 顯示文件內容最後一次被修改的時間,example: vim編輯文件
  • ctime(change time)
    • 顯示文件的權限,擁有者,所屬的組,鏈接數發生改變的時間(內容改變也會隨之改變)

[root@localhost ~]# touch aa.txt
[root@localhost ~]# stat aa.txt
Access: 2020-05-22 08:20:38.488730387 -0400
Modify: 2020-05-22 08:20:38.488730387 -0400
Change: 2020-05-22 08:20:38.488730387 -0400

[root@localhost ~]# vim aa.txt
print ‘Hello linux!!!’
[root@localhost ~]# stat aa.txt
Access: 2020-05-22 08:26:45.115458651 -0400
Modify: 2020-05-22 08:26:45.115458651 -0400
Change: 2020-05-22 08:26:45.116458648 -0400

[root@localhost ~]# python aa.txt
Hello linux!!!
Access: 2020-05-22 08:27:32.967636929 -0400
Modify: 2020-05-22 08:26:45.115458651 -0400
Change: 2020-05-22 08:26:45.116458648 -0400

[root@localhost ~]# cat aa.txt
print ‘Hello linux!!!’
Access: 2020-05-22 08:27:32.967636929 -0400
Modify: 2020-05-22 08:26:45.115458651 -0400
Change: 2020-05-22 08:26:45.116458648 -0400

  • 用三種方法在文件hello.txt 中增加一行內容

      vim/gedit hello.txt
      echo 'linux' >> hello.txt
      cat >> hello.txt << END
    
    
      [root@localhost ~]# vim hello.txt
      這是vim寫的
      [root@localhost ~]# echo '這是echo寫的' >> hello.txt 
      [root@localhost ~]# cat hello.txt 
      這是vim寫的
      這是echo寫的
      [root@localhost ~]# cat >> hello.txt 
      cat寫的
      
      
      ^C
      [root@localhost ~]# cat hello.txt 
      這是vim寫的
      這是echo寫的
      cat寫的
      
      
      [root@localhost ~]# cat >> hello.txt << END
      > 111
      > 222
      > 333
      > END
      [root@localhost ~]# cat hello.txt 
      這是vim寫的
      這是echo寫的
      cat寫的
      
      
      111
      222
      333
    
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章