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
上一篇:如何选择阿里云服务器操作系统?阿里云操作系统说明指南


下一篇:如何用.NET生成二维码?