網絡班N22期第五周博客作業

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

[root@bogon ~]# cat /etc/passwd | grep -E "^(root|fedora|user1)\>" | cut -d: -f 7
/bin/bash
/bin/bash

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

[root@bogon ~]# cat /etc/rc.d/init.d/functions | grep "\<[[:alpha:]]*()" | cut -d' ' -f1
checkpid()
daemon()
killproc()
pidfileofproc()
pidofproc()
status()
success()
failure()
passed()
warning()
action()
strstr()
confirm()

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

[root@bogon ~]# echo "/etc/sysconfig/network-scripts/ifcfg-eth0" | grep -o "[^/]\+$"
ifcfg-eth0

取出其路徑名

[root@bogon ~]# echo "/etc/sysconfig/network-scripts/ifcfg-eth0" | grep -o "^.*/"
/etc/sysconfig/network-scripts/


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

[root@bogon ~]# ifconfig | egrep -o "\<[1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5]\>"
29
1
10
10
10
100
10
10
10
255
255
255
255
80
20
29
1
64
150

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

[root@bogon ~]# ifconfig | egrep -o "[1-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?"
10.10.10.100
10.10.10.255
255.255.255.0
10.10.10.101
255.255.255.0
192.168.1.234
255.255.255.0
127.0.0.1
255.0.0.0


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

[root@bogon ~]# cat mail.txt 
asbd@qq.com
dsaf@139.com
mage@edu.com
test@163.com
dhskhdkf
kskshgksjgdh
[root@bogon ~]# cat mail.txt | egrep "[[:alnum:]]+@[[:alnum:]]+"
asbd@qq.com
dsaf@139.com
mage@edu.com
test@163.com

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

[root@bogon ~]# find /var -user root -group mail -ls
263166    4 drwxrwxr-x   2 root     mail         4096 Nov 28 04:17 /var/spool/mail
263915   72 -rw-------   1 root     mail        72437 Jun  3 02:00 /var/spool/mail/root

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

[root@bogon ~]# find / -nouser -o -nogroup 
/test.txt
/test
/root/nload-0.7.2
/root/nload-0.7.2/install-sh
/root/nload-0.7.2/aclocal.m4
/root/nload-0.7.2/ChangeLog
......
[root@bogon ~]# ll /test.txt 
-rw-r--r-- 1 5025 5025 15 Nov 21 13:01 /test.txt

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

[root@bogon ~]# find / -nouser -o -nogroup -a -atime -3
/test.txt
/test
/root/test.txt
......

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

[root@bogon ~]# touch /etc/test.txt
[root@bogon ~]# chmod 666 /etc/test.txt
[root@bogon ~]# find /etc -type f -perm -222 -ls
396003    4 -rw-rw-rw-   1 root     root            7 Nov 28 06:39 /etc/test.txt

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

[root@bogon ~]# find /etc -type f -size +1M -ls
394863 7124 -rw-r--r--   1 root     root      7292689 Jan 21  2015 /etc/selinux/targeted/modules/active/policy.kern
394866 7124 -rw-r--r--   1 root     root      7292689 Jan 21  2015 /etc/selinux/targeted/policy/policy.24
395770 1332 -rw-r--r--   1 root     root      1362271 Jan 28  2015 /etc/gconf/gconf.xml.defaults/%gconf-tree.xml

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

[root@bogon init.d]# find /etc/init.d/ -type f -perm -113 -ls
394214    0 -rwxr-xrwx   1 root     root            0 Nov 28 22:17 /etc/init.d/test.txt
396004    0 -rwxr-x-wx   1 root     root            0 Nov 28 22:17 /etc/init.d/test2.txt

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

[root@bogon ~]# find /usr/ -type f -not \( -user root -o -user bin -o -user hadoop \) -ls
1450330    0 -rw-r--r--   1 user1    user1           0 Nov 21 12:47 /usr/test
1469800   12 -rwsr-xr-x   1 abrt     abrt         9904 Nov 23  2013 /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

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

[root@bogon ~]# find /etc/ -type f -not -perm -222 -ls | head -10
393969    4 -rwxr-xr-x   1 root     root          233 Mar 18  2015 /etc/rc.d/rc.local
393962    8 -rwxr-xr-x   1 root     root         5866 Oct 10  2013 /etc/rc.d/init.d/halt
393865    4 -rwxr-xr-x   1 root     root         1698 Nov 23  2013 /etc/rc.d/init.d/sandbox
394410    8 -rwxr-xr-x   1 root     root         4621 Nov 13  2014 /etc/rc.d/init.d/sshd
395010    4 -rwxr-xr-x   1 root     root         2276 Apr  2  2013 /etc/rc.d/init.d/svnserve
393878   12 -rwxr-xr-x   1 root     root        10688 Nov 23  2013 /etc/rc.d/init.d/iptables
394529    4 -rwxr-xr-x   1 root     root         4043 Nov 23  2013 /etc/rc.d/init.d/autofs
394583    4 -rwxr-xr-x   1 root     root         3245 Jul  9  2013 /etc/rc.d/init.d/firstboot
394165    4 -rwxr-xr-x   1 root     root         2305 Nov 22  2013 /etc/rc.d/init.d/rpcidmapd
393916    4 -rwxr-xr-x   1 root     root         1513 Sep 17  2013 /etc/rc.d/init.d/rdisc

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

[root@bogon ~]# chown user1:user1 /etc/test.txt 
[root@bogon ~]# 
[root@bogon ~]# find /etc/ -type f -mtime -7 -not \( -user root -o -user hadoop \) -ls
396003    4 -rw-rw-rw-   1 user1    user1           7 Nov 28 06:39 /etc/test.txt


原創文章,作者:凸b男波萬,如若轉載,請注明出處:http://www.www58058.com/45317

(0)
凸b男波萬凸b男波萬
上一篇 2016-09-15
下一篇 2016-09-15

相關推薦

  • linux中如何使用幫助

     在linux學習過程中,會遇到許多困難,尤其是一些命令掌握不牢固,不知道具體用法;或者是想要實現一些功能而不知道使用何種命令。這時求人不如求己,上網求助不如自己學會使用幫助,下面介紹幾種linux幫助的用法。 1.what is +命令    執行這條命令可以顯示命令的簡短描述,讓大家了解命令的基本功能。同時可以看到命令相關章…

    2017-07-23
  • Hello World

    隨筆

    Linux干貨 2018-03-26
  • linux開篇六式

    第一式. Linux上的文件管理類命令,其常用的使用方法及其相關示例。       mkdir, 創建目錄       rmdir,刪除目錄       tree, 顯示目錄層級       cat和tac均用于查看文件,cat是從文件首向…

    Linux干貨 2016-10-13
  • Linux平臺的4個最佳開源代碼編輯器

    原文出處: Abhishek   譯文出處:Linux中國 su-kaiyao   正在尋找Linux平臺最棒的代碼編輯器?如果你詢問那些很早就玩Linux的人,他們會回答是Vi, Vim, Emacs, Nano等。但是,我今天不討論那些。我將談論一些新時代尖端、漂亮、時髦而且十分強大, 功能豐富…

    Linux干貨 2015-03-02
  • vim編輯以及腳本編程練習

    vim編輯器的使用總結: vim在工作過程當中有三種模式:編輯模式、輸入模式、末行模式。 1、編輯模式:即命令模式,鍵盤操作常被理解為編輯命令; 2、輸入模式:在文本文件當中進行輸入內容; 3、末行模式:vim內置的命令行接口,執行vim的內置命令。   vim的使用 打開文件 #vim[option]…[FILE] +#:打開文件后,直接讓光標處…

    Linux干貨 2017-10-29
  • bash腳本之練習

    1、編寫服務腳本/root/bin/testsrv.sh,完成如下要求  (1) 腳本可接受參數:start, stop, restart, status  (2) 如果參數非此四者之一,提示使用格式后報錯退出 (3) 如是start:則創建/var/lock/subsys/SCRIPTNAME, 并顯示“啟動成功” 考慮:如果事先已經啟…

    Linux干貨 2016-08-24
欧美性久久久久