馬哥教育網絡班21期+第五周課程練習

1、顯示/boot/grub/grub.conf中以至少一個空白字符開頭的行;

~]# egrep ^[[:space:]] /boot/grub/grub.conf

2、顯示/etc/rc.d/rc.sysinit文件中以#開頭,后面跟至少一個空白字符,而后又有至少一個非空白字符的行;

~]# egrep ^#[[:space:]]+[^[:space:]]+ /etc/rc.d/rc.sysinit

3、打出netstat -tan命令執行結果中以‘LISTEN’,后或跟空白字符結尾的行;

~]# netstat -tan | egrep "LISTEN[[:space:]]+"

4、添加用戶bash, testbash, basher, nologin (此一個用戶的shell為/sbin/nologin),而后找出當前系統上其用戶名和默認shell相同的用戶的信息;

#!/bin/bash
#
for i in bash testbash basher nologin;do
      if ! id $i &> /dev/null;then
          if [ $i == nologin ];then
          useradd -s /sbin/nologin $i
          else
          useradd $i
          fi
     else
        echo "$i exist"
          if [ $i == nologin ];then
            userdel -r $i
            useradd -s /sbin/nologin $i
            echo "$i reinstitute"
          fi
       fi

done
  egrep "^([[:alnum:]]+\>).*\1$"  /etc/passwd

5、顯示當前系統上root、fedora或user1用戶的默認shell;

~]# egrep "^root\>|^fedora\>|^user1\>" /etc/passwd | cut -d: -f7

6、找出/etc/rc.d/init.d/functions文件中某單詞后面跟一組小括號的行,形如:hello();

~]# grep  "\<[[:alpha:]]\+()" /etc/init.d/functions

7、使用echo命令輸出一個絕對路徑,使用grep取出其基名;

    擴展:取出其路徑名

取其基名
~]#  echo /etc/rc.d/rc3.d/K01smartd | grep -o "[^/]\+$"
取其路徑名
~]# echo /etc/rc.d/rc3.d/K01smartd | grep -o "[/][^/]\+.*[/]"|cut -d"/" -f1-4

8、找出ifconfig命令結果中的1-255之間數字;

~]# ifconfig |egrep  "\<[1-9][0-9]\>|\<[0-9]\>|\<[1][0-9][0-9]\>|\<[2][0-4][0-9]\>|\<[2][5][0-5]\>"

9、挑戰題:寫一個模式,能匹配合理的IP地址;

~]# ifconfig |egrep -o "[1-2]?[0-9]{,2}\.[1-2]?[0-9]{,2}\.[1-2]?[0-9]{,2}\.[1-2]?[0-9]{,2}"
192.168.0.108
192.168.0.255
255.255.255.0
192.168.160.160
192.168.160.255
255.255.255.0
127.0.0.1
255.0.0.0

10、挑戰題:寫一個模式,能匹配出所有的郵件地址;

[root@linux tmp]# cat mail.txt 
zhangsan@163.com
lisi123@123.com
123456@yahoo.com
wangwusf.hiya
huohuo.huo.huo
huo99@mage.com
[root@linux tmp]# egrep  "^[[:alnum:]]+@[[:alnum:]]+\.[[:alnum:]]+$"  ./mail.txt 
zhangsan@163.com
lisi123@123.com
123456@yahoo.com
huo99@mage.com

11、查找/var目錄下屬主為root,且屬組為mail的所有文件或目錄

~]# find /var -user root -a -group mail -ls

12、查找當前系統上沒有屬主或屬組的文件;

[root@linux tmp]# find / -type f -nouser -a -nogroup -ls 
261162    0 -rw-rw-r--   1 3007     3007            0 Aug  6 20:52 /tmp/test.txt
261169    0 -rw-rw-r--   1 3007     3007            0 Aug  6 20:52 /tmp/kkk

查找當前系統上沒有屬主或屬組,且最近3天內曾被訪問過的文件或目錄;

[root@linux tmp]# find / -nouser -a -nogroup -a -atime -3
/tmp/test.txt
/tmp/kkk

13、查找/etc目錄下所有用戶都有寫權限的文件;

~]# find / -type f -perm -222 -ls

14、查找/etc目錄下大于1M,且類型為普通文件的所有文件

[root@linux ~]# find /etc -type f -size +1M |xargs ls -lh
-rw-r--r--. 1 root root 1.3M Aug  4 22:22 /etc/gconf/gconf.xml.defaults/%gconf-tree.xml
-rw-r--r--. 1 root root 1.1M Apr 24  2015 /etc/pki/tls/certs/ca-bundle.trust.crt
-rw-r--r--. 1 root root 8.0M Aug  4 08:54 /etc/selinux/targeted/modules/active/policy.kern
-rw-r--r--. 1 root root 8.0M Aug  4 08:54 /etc/selinux/targeted/policy/policy.24

15、查找/etc/init.d/目錄下,所有用戶都有執行權限,且其它用戶有寫權限的文件;

~]# find /etc/init.d/ -perm -113 -ls
393283    0 -rwxr-xrwx   1 root     root            0 Aug  6 21:15 /etc/init.d/test.txt

16、查找/usr目錄下不屬于root、bin或hadoop的文件

~]# ~]# find /usr  -not -user root -a -not -user bin -a -not -user hadoop -ls

17、查找/etc/目錄下至少有一類用戶沒有寫權限的文件;

~]# find /etc -not -perm -222 -ls

18、查找/etc目錄下最近一周內其內容被修改過,且不屬于root或hadoop的文件;

~]# find /etc -mtime -7 -a -not -user root -not -user hadoop

原創文章,作者:微,如若轉載,請注明出處:http://www.www58058.com/30301

(0)
微
上一篇 2016-08-08
下一篇 2016-08-08

相關推薦

  • keepalived+lvs-dr實現高可用負載均衡

    keepalived+lvs-dr實現高可用負載均衡 實驗拓撲 實驗要求 RS1與RS2地址為172.18.27.201/202 VS1和VS2地址為172.18.27.103/200,VIP為172.18.27.254 VS1和VS2實現lvs-dr負載均衡及高可用性,且vs為sorry sever。 keepalived是單主模式。 實驗步驟 各個主機安…

    2017-05-14
  • The second week’s homework

    一.linux上的文件管理類命令都有哪些,其常用的使用方法及其相關示例演示。 Linux 文件與目錄管理 我們知道Linux的目錄結構為樹狀結構,最頂級的目錄為根目錄 /。 其他目錄通過掛載可以將它們添加到樹中,通過解除掛載可以移除它們。 首先需要知道什么是絕對路徑與相對路徑。 絕對路徑: 路徑的寫法,由根目錄 / 寫起,例如: /usr/shar…

    Linux干貨 2016-12-12
  • 磁盤管理

    硬盤物理結構      扇區  磁頭  磁道   柱面   磁道數      扇區*一個磁道上的扇區個數*磁頭數=柱面      柱面*磁道數=硬盤大小      一個扇區512字節   &…

    Linux干貨 2017-08-26
  • Python函數式編程指南:目錄和參考

    目錄: 概述 這一篇簡要地描述了函數式編程和一些相關的概念。 函數 這一篇展示了關于函數可能不常用到的部分特征并嘗試引導諸位使用函數式的思維解決問題,并介紹了諸多有用的內建函數。 迭代器 這一篇介紹了迭代器以及Python對迭代器的語法級的支持,還包括了內置模塊itertools的介紹。 生成器 這一篇介紹了自定義的迭代器——生成器,并展示了生成器的用途和使…

    Linux干貨 2015-03-11
  • Linux網絡簡單設置

     修改IP地址:臨時修改IP地址(centenos 7以前版本)ifconfig eth0 x.x.x.x netmask x.x.x.x                   修改…

    Linux干貨 2017-08-19
  • 關于shell腳本基礎第二篇

                          shell腳本編程基礎第二篇 read命令 使用read來把輸入的值非配給一個或者多個shell變量,可以提示用戶輸入一些參數等,此時我們可以使用read命令來完成此功能 re…

    系統運維 2016-08-19

評論列表(1條)

  • 馬哥教育
    馬哥教育 2016-08-08 17:02

    寫的很好,排版也很棒,加油,匹配ip地址不對

欧美性久久久久