Linux 習題練習-02(grep、find命令、yum源配置)

Liunx 習題練習02

  1. 返回initial-setup-ks.cfg文件中包含字符串 ‘boot’ 的行數

     [root@localhost ~]# grep 'boot' /root/initial-setup-ks.cfg | wc -l
     [root@localhost ~]# grep -c 'boot' /root/initial-setup-ks.cfg 
    
  2. 返回initial-setup-ks.cfg文件中包含字符串 ‘boot’ 的行與行號

     [root@localhost ~]# grep -n 'boot' /root/initial-setup-ks.cfg 
    
  3. 執行ps -aux命令,將文件內容保存到 /root/ps.log 中,查找該文件中包含1774或1775字符串的行

     [root@localhost ~]# ps -aux > /root/ps.log 
     [root@localhost ~]# grep '177[45]' ps.log 
    
  4. 在上述文件中查找包含一串包含四位數的字符串,並且這個字符串最後一個數字爲2

     [root@localhost ~]# grep '[0-9][0-9][0-9]2' /root/ps.log 
    
     [root@localhost ~]# grep '[0-9][0-9][0-9]...2' /root/ps.log 
     
     [root@localhost ~]# grep '[0-9][0-9][0-9]...[Ss]' /root/ps.log 
    
  5. 在當前目錄下查找除目錄以外的所有類型的文件

     [root@localhost ~]# find . ! -type d
    
  6. 找出所有用戶ruochen 擁有的文件,並且把它們拷貝到/root/finder怒罵中

     [root@localhost yum.repos.d]# find / -user harry -type f -exec cp {} /root/finder \; 2> /dev/null
    
  7. 查找文件更改時間比文件a.txt 新但比b.txt 文件舊的文件

    • -newr

    • find / - newer a.txt ! -newer b.txt

        [root@localhost ~]# find / -newer initial-setup-ks.cfg ! -newer ps.log -exec ls -lh {} \;
      
  8. 統計當前系統中一共有多少賬戶

    • /etc/passwd

    • wc -l /etc/passwd

        [root@localhost ~]# wc -l /etc/passwd
        39 /etc/passwd
      
  9. 配置本機yum 環境

     [root@localhost Desktop]# mkdir /mnt/cdrom
     [root@localhost Desktop]# mount /dev/sr0 /mnt/cdrom 
     [root@localhost yum]# cd /etc/yum.repos.d/
     [root@localhost yum.repos.d]# ls
     [root@localhost yum.repos.d]# rm -rf *
     [root@localhost yum.repos.d]# vim dvd.repo
     [dvd]
     name = dvd
     baseurl = file:///mnt/cdrom
     gpgcheck = 0
     enabled = 1
     [root@localhost yum.repos.d]# yum clean all
     [root@localhost yum.repos.d]# yum repolist all
    
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章