第五周博客作業

  感覺進入了年底,明顯的時間不夠,不管怎么說,還是要努力跟上學習的進度,不能給自己松懈找借口!
  1、顯示/boot/grub/grub.conf中以至少一個空白字符開頭的行;

[root@localhost ~]# grep "^[[:space:]]\+" /boot/grub/grub.conf
     root (hd0,0)     
     kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet     
     initrd /initramfs-2.6.32-431.el6.x86_64.img

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

[root@localhost ~]# grep "^#[[:space:]]\+[^[:space:]]\+" /etc/rc.d/rc.sysinit 
# /etc/rc.d/rc.sysinit - run once at boot time
# Taken in part from Miquel van Smoorenburg's bcheckrc.
# Check SELinux status
# Print a text banner.
# Only read this once.
# Initialize hardware
# Set default affinity
...

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

[root@localhost ~]# netstat -tan | grep "LISTEN[[:space:]]*$"
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:35227               0.0.0.0:*                   LISTEN      
tcp        0      0 :::111                      :::*                        LISTEN      
tcp        0      0 :::22                       :::*                        LISTEN      
tcp        0      0 ::1:631                     :::*                        LISTEN      
tcp        0      0 ::1:25                      :::*                        LISTEN      
tcp        0      0 :::46560                    :::*                        LISTEN

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

[root@localhost ~]# useradd bash
[root@localhost ~]# useradd testbash
[root@localhost ~]# useradd basher
[root@localhost ~]# useradd -s /sbin/nologin nologin
[root@localhost ~]# grep "^\([^:]\+\>\).*\1$" /etc/passwd
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
bash:x:500:500::/home/bash:/bin/bash
nologin:x:503:503::/home/nologin:/sbin/nologin

  5、顯示當前系統上root、fedora或user1用戶的默認shell;
  因為當前系統沒有fedora和user1用戶,所以先創建。

[root@localhost ~]# useradd fedora
[root@localhost ~]# useradd user1
[root@localhost ~]# grep "^\(root\|fedora\|user1\)" /etc/passwd
root:x:0:0:root:/root:/bin/bash
fedora:x:504:504::/home/fedora:/bin/bash
user1:x:505:505::/home/user1:/bin/bash
[root@localhost ~]# grep "^\(root\|fedora\|user1\)" /etc/passwd | cut -d: -f7
/bin/bash
/bin/bash
/bin/bash
···

  6、找出/etc/rc.d/init.d/functions文件中某單詞后面跟一組小括號的行,形如:hello();
  根據對題目的理解,應該是要小括號內為空的內容,也就是一對括號,而不是括號內可以有內容的行。

[root@localhost ~]# grep "\<[[:alnum:]]\+\>()" /etc/rc.d/init.d/functions
checkpid() {
daemon() {
killproc() {
pidfileofproc() {
pidofproc() {
status() {
success() {
failure() {
passed() {
warning() {
action() {
strstr() {
confirm() {

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

[root@localhost ~]# echo /etc/rc.d/init.d/functions | grep "\<[^/]\+$" -o
functions

[root@localhost ~]# echo /etc/rc.d/init.d/functions | grep "/.*/" -o
/etc/rc.d/init.d/

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

[root@localhost ~]# ifconfig | grep "\<[1-9]\>\|\<[1-9][0-9]\>\|\<1[0-9][0-9]\>\|2[0-4][0-9]\|25[0-5]" -o
29
172
16
209
172
16
3
255
255
...

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

[root@localhost ~]# ifconfig | grep "\(\([01]\?[0-9]\?[0-9]\?\|2\?[0-4]\?[0-9]\?\|25\?[0-5]\?\)\.\)\{3\}\([01]\?[0-9]\?[0-9]\?\|2\?[0-4]\?[0-9]\?\|25\?[0-5]\?\)" -o
172.16.0.209
172.16.3.255
255.255.252.0
127.0.0.1
255.0.0.0

  10、挑戰題:寫一個模式,能匹配出所有的郵件地址;
  不是太懂email的格式要求,但是一般字符只能用-和_所以就只允許這兩個了。

[root@localhost ~]# cat /tmp/mail.txt 
abc@abc.com
abc12@abc12.com
12abc@12abc.cn
a_bc12@12.org
bcd2@bc_2.net
ab$@cd.cn
cd#@cs.cc
ty%@.com
mc^d@cd.com
sb&@dds.csg
ss*@dds(.com

[root@localhost ~]# grep "^[0-9a-zA-Z\-\_]\+@\{1\}[0-9a-zA-Z\-\_]\+.[0-9a-zA-Z\-\_]\+$" /tmp/mail.txt
abc@abc.com
abc12@abc12.com
12abc@12abc.cn
a_bc12@12.org
bcd2@bc_2.net

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

[root@localhost ~]# find /var -user root -group mail -ls
2229008    4 drwxrwxr-x   2 root     mail         4096 Jan  3 02:06 /var/spool/mail

  12、查找當前系統上沒有屬主或屬組的文件;
  進一步:查找當前系統上沒有屬主或屬組,且最近3天內曾被訪問過的文件或目錄;
  #由于系統上沒有無屬主或屬組的文件,所以先做一些類似的文件出來。

[root@localhost ~]# chown user1:fedora /tmp/mail.txt 
[root@localhost ~]# cp /etc/issue /tmp
[root@localhost ~]# cp /etc/rc.d/init.d/functions /tmp
[root@localhost ~]# chown testbash:mail /tmp/issue 
[root@localhost ~]# chown basher:fedora /tmp/functions 
[root@localhost ~]# ll /tmp
total 28
-rw-r--r--. 1 basher   fedora 18586 Jan  3 04:27 functions
-rw-r--r--. 1 testbash mail      47 Jan  3 04:27 issue
-rw-r--r--. 1 user1    fedora   138 Jan  3 03:49 mail.txt
[root@localhost ~]# userdel basher
[root@localhost ~]# userdel testbash
[root@localhost ~]# userdel fedora
[root@localhost ~]# userdel user1
[root@localhost ~]# ll /tmp
total 28
-rw-r--r--. 1 502  504 18586 Jan  3 04:27 functions
-rw-r--r--. 1 501 mail    47 Jan  3 04:27 issue
-rw-r--r--. 1 505  504   138 Jan  3 03:49 mail.txt
[root@localhost ~]# find / \( -nouser -o -nogroup \) -ls
find: `/proc/2941/task/2941/fd/5': No such file or directory
find: `/proc/2941/task/2941/fd/5': No such file or directory
find: `/proc/2941/task/2941/fdinfo/5': No such file or directory
find: `/proc/2941/task/2941/fdinfo/5': No such file or directory
find: `/proc/2941/fd/5': No such file or directory
find: `/proc/2941/fd/5': No such file or directory
find: `/proc/2941/fdinfo/5': No such file or directory
find: `/proc/2941/fdinfo/5': No such file or directory
3932161    4 drwx------   2 504      504          4096 Jan  3 02:06 /home/fedora
3932162    4 -rw-r--r--   1 504      504            18 Jul 18  2013 /home/fedora/.bash_logout
3932164    4 -rw-r--r--   1 504      504           124 Jul 18  2013 /home/fedora/.bashrc
3932163    4 -rw-r--r--   1 504      504           176 Jul 18  2013 /home/fedora/.bash_profile
131073    4 drwx------   2 505      505          4096 Jan  3 02:06 /home/user1
131074    4 -rw-r--r--   1 505      505            18 Jul 18  2013 /home/user1/.bash_logout
131076    4 -rw-r--r--   1 505      505           124 Jul 18  2013 /home/user1/.bashrc
131075    4 -rw-r--r--   1 505      505           176 Jul 18  2013 /home/user1/.bash_profile
655361    4 drwx------   2 502      502          4096 Jan  3 01:36 /home/basher
655362    4 -rw-r--r--   1 502      502            18 Jul 18  2013 /home/basher/.bash_logout
655364    4 -rw-r--r--   1 502      502           124 Jul 18  2013 /home/basher/.bashrc
655363    4 -rw-r--r--   1 502      502           176 Jul 18  2013 /home/basher/.bash_profile
524289    4 drwx------   2 501      501          4096 Jan  3 01:36 /home/testbash
524290    4 -rw-r--r--   1 501      501            18 Jul 18  2013 /home/testbash/.bash_logout
524292    4 -rw-r--r--   1 501      501           124 Jul 18  2013 /home/testbash/.bashrc
524291    4 -rw-r--r--   1 501      501           176 Jul 18  2013 /home/testbash/.bash_profile
2230209    0 -rw-rw----   1 505      mail            0 Jan  3 02:06 /var/spool/mail/user1
2230206    0 -rw-rw----   1 502      mail            0 Jan  3 01:36 /var/spool/mail/basher
2230208    0 -rw-rw----   1 504      mail            0 Jan  3 02:06 /var/spool/mail/fedora
2230193    0 -rw-rw----   1 501      mail            0 Jan  3 01:36 /var/spool/mail/testbash
2752517   20 -rw-r--r--   1 502      504         18586 Jan  3 04:27 /tmp/functions
2752514    4 -rw-r--r--   1 501      mail           47 Jan  3 04:27 /tmp/issue
2752516    4 -rw-r--r--   1 505      504           138 Jan  3 03:49 /tmp/mail.txt


[root@localhost ~]# find / \( -nouser -o -nogroup \) -a -atime -3 -ls
find: `/proc/2927/task/2927/fd/5': No such file or directory
find: `/proc/2927/task/2927/fdinfo/5': No such file or directory
find: `/proc/2927/fd/5': No such file or directory
find: `/proc/2927/fdinfo/5': No such file or directory
3932161    4 drwx------   2 504      504          4096 Jan  3 02:06 /home/fedora
3932162    4 -rw-r--r--   1 504      504            18 Jul 18  2013 /home/fedora/.bash_logout
3932164    4 -rw-r--r--   1 504      504           124 Jul 18  2013 /home/fedora/.bashrc
3932163    4 -rw-r--r--   1 504      504           176 Jul 18  2013 /home/fedora/.bash_profile
131073    4 drwx------   2 505      505          4096 Jan  3 02:06 /home/user1
131074    4 -rw-r--r--   1 505      505            18 Jul 18  2013 /home/user1/.bash_logout
131076    4 -rw-r--r--   1 505      505           124 Jul 18  2013 /home/user1/.bashrc
131075    4 -rw-r--r--   1 505      505           176 Jul 18  2013 /home/user1/.bash_profile
655361    4 drwx------   2 502      502          4096 Jan  3 01:36 /home/basher
655362    4 -rw-r--r--   1 502      502            18 Jul 18  2013 /home/basher/.bash_logout
655364    4 -rw-r--r--   1 502      502           124 Jul 18  2013 /home/basher/.bashrc
655363    4 -rw-r--r--   1 502      502           176 Jul 18  2013 /home/basher/.bash_profile
524289    4 drwx------   2 501      501          4096 Jan  3 01:36 /home/testbash
524290    4 -rw-r--r--   1 501      501            18 Jul 18  2013 /home/testbash/.bash_logout
524292    4 -rw-r--r--   1 501      501           124 Jul 18  2013 /home/testbash/.bashrc
524291    4 -rw-r--r--   1 501      501           176 Jul 18  2013 /home/testbash/.bash_profile
2230209    0 -rw-rw----   1 505      mail            0 Jan  3 02:06 /var/spool/mail/user1
2230206    0 -rw-rw----   1 502      mail            0 Jan  3 01:36 /var/spool/mail/basher
2230208    0 -rw-rw----   1 504      mail            0 Jan  3 02:06 /var/spool/mail/fedora
2230193    0 -rw-rw----   1 501      mail            0 Jan  3 01:36 /var/spool/mail/testbash
2752517   20 -rw-r--r--   1 502      504         18586 Jan  3 04:27 /tmp/functions
2752514    4 -rw-r--r--   1 501      mail           47 Jan  3 04:27 /tmp/issue
2752516    4 -rw-r--r--   1 505      504           138 Jan  3 03:49 /tmp/mail.txt

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

[root@localhost ~]# find /etc -perm -222 -type f -ls
...

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

[root@localhost ~]# find /etc -type f -size +1M -ls
1181096 7124 -rw-r--r--   1 root     root      7292689 Dec 21 04:02 /etc/selinux/targeted/policy/policy.24
1181093 7124 -rw-r--r--   1 root     root      7292689 Dec 21 04:02 /etc/selinux/targeted/modules/active/policy.kern

  15、查找/etc/init.d/目錄下,所有用戶都有執行權限,且其它用戶有寫權限的文件;
  沒有其他用戶有寫權限的文件,所以將查詢改為讀和執行。

[root@localhost ~]# find /etc/rc.d/init.d -perm -114 -type f -ls
1179729    4 drwxr-xr-x   2 root     root         4096 Jan  3 02:12 /etc/rc.d/init.d
1180321    4 -rwxr-xr-x   1 root     root          652 Oct 10  2013 /etc/rc.d/init.d/killall
1181236    4 -rwxr-xr-x   1 root     root         1725 Aug 19  2010 /etc/rc.d/init.d/acpid
1181220    4 -rwxr-xr-x   1 root     root         2034 Jun 13  2013 /etc/rc.d/init.d/quota_nld
1180644    4 -rwxr-xr-x   1 root     root         2094 Feb 22  2013 /etc/rc.d/init.d/certmonger
1181162    4 -r-xr-xr-x   1 root     root         2134 Nov 24  2013 /etc/rc.d/init.d/lvm2-lvmetad
1179849    4 -rwxr-xr-x   1 root     root         2023 Apr  3  2012 /etc/rc.d/init.d/portreserve
1180609    4 -rwxr-xr-x   1 root     root         2011 Aug 15  2013 /etc/rc.d/init.d/rsyslog
1181122    4 -rwxr-xr-x   1 root     root         1144 Nov 23  2013 /etc/rc.d/init.d/sysstat
...

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

[root@localhost ~]# find /usr -not \( -user root -o -user bin \) -ls
1314588   12 -rwsr-xr-x   1 abrt     abrt         9904 Nov 23  2013 /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

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

[root@localhost ~]#  find /etc -perm /222 -type f -ls
1179706    4 -rw-r--r--   1 root     root          236 Nov 12  2010 /etc/sgml/docbook/xmlcatalog
1180292    4 -rw-r--r--   1 root     root           48 Dec 28 01:18 /etc/adjtime
1179780    0 -rw-r--r--   1 root     root            0 Nov 29  2012 /etc/odbc.ini
1179983    4 -rw-r--r--   1 root     root          251 Nov 23  2013 /etc/my.cnf
1180066    4 -rw-r--r--   1 root     root         2293 Apr  5  2012 /etc/libuser.conf
1179964   16 -rw-r--r--   1 root     root        13537 Dec 16  2004 /etc/java/font.properties
1179965    4 -rw-r--r--   1 root     root          684 Nov 12  2010 /etc/java/java.conf
1179966    4 -rw-r--r--   1 root     root           50 Nov 12  2010 /etc/java/jpackage-release
...

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

[root@localhost ~]# find /etc \( -not -user root -a -not -user bin \) -a -mtime -7

原創文章,作者:N25-Johnny,如若轉載,請注明出處:http://www.www58058.com/65650

(0)
N25-JohnnyN25-Johnny
上一篇 2017-01-03
下一篇 2017-01-03

相關推薦

  • Ansible Playbook Roles 和 Include 聲明-手稿

    Edit Ansible Playbook Roles 和 Include 聲明 Ansible Playbook Roles 和 Include 聲明 1. Introduction 2. Task Include Files And Encouraging Reuse 3. Roles 4. Role Default Variables 5. Role …

    Linux干貨 2016-03-28
  • 前兩周linux基礎知識總結

    linux用戶權限管理 軟鏈接與硬鏈接 輸入輸出重定向 文本處理三劍客vim sed awk 包管理rpm yum 源碼包編譯安裝

    Linux干貨 2018-03-17
  • HAProxy淺說

    HAProxy淺說:    HAProxy響應碼:        200:請求正常,響應正常,也就是正常響應碼     301:配置使用的重定向,以下都是有關于重定向的一些響應碼,不做解釋     302:    &nb…

    2017-05-18
  • 創建CA、申請證書和吊銷證書詳解

    創建CA和申請證書、吊銷證書 搭建工具:openssl 服務端:centos7 客戶端:centos6 配置實驗環境: 需要兩臺虛擬機為服務端、客戶端提供運行環境,裝載openssl工具,添加必要文件;通過查看openssl的配置文件/etc/pki/tls/openssl.cnf(圖一),對比服務端的/etc/pki/CA文件內容(圖二),如果第一次搭建服…

    2017-04-11
  • echo命令的簡單用法和實例

        在CentOS 6.8版本下,通過實例的形式,展現選項和參數的靈活運用,可以簡明的了解echo的用法。 一、語法:echo [SHORT-OPTION]… [STRING]… ;echo [選項]…[參數]       作用:將需要的內容輸出到終端或者其他文件。 二、實例和選項參數的用法: (1)文本…

    Linux干貨 2017-03-27
  • python裝飾器詳解

    python之裝飾器詳解 一、裝飾器定義 定義一個函數,可以接受一個函數作為參數,對該函數進行一些包裝,不改變函數的本身。 二、裝飾器四部曲(分解) 1、函數可賦值給變量。若賦值給變量的是調用后的函數,變量的值就是return的返回值。 切記:函數賦值給變量,只看return的值。分清楚函數是處于調用狀態還是未被調用狀態。若函數沒有寫return,默認ret…

    2017-02-08

評論列表(1條)

  • 馬哥教育
    馬哥教育 2017-02-17 10:57

    寫的很好,排版也很漂亮,提問一個問題,255.255.255.255是一個合理的ip地址嗎?

欧美性久久久久