N22+張zhangzhang+第5周練習作業

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

[root@zxn ~]# cat /etc/passwd | grep -E "^root\>" | cut -d: -f7
/bin/bash

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

cat /etc/rc.d/init.d/functions | grep -E "\<[[:alpha:]]+\>\(\)"
checkpid() {daemon() {killproc() {pidfileofproc() {pidofproc() {status() {success() {failure() {passed() {warning() {action() {strstr() {

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

取基名

[root@zxn ~]# echo /etc/rc.d/init.d/functions | grep -E -o  "[^/]+/?$"
functions

取路徑名:

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

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

[root@zxn ~]# ifconfig | grep  -E  --color  "\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>"
        inet 192.168.1.15  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::20c:29ff:fec1:ddb3  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:c1:dd:b3  txqueuelen 1000  (Ethernet)
        RX packets 30268  bytes 4171288 (3.9 MiB)
        TX packets 4401  bytes 1321341 (1.2 MiB)
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        RX packets 41  bytes 3960 (3.8 KiB)
        TX packets 41  bytes 3960 (3.8 KiB)

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

[root@zxn ~]#  ifconfig |grep -E --color "[1-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[1-9]{0,1}[0-9]{1,3}"
        inet 192.168.1.15  netmask 255.255.255.0  broadcast 192.168.1.255
        inet 127.0.0.1  netmask 255.0.0.0

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

[root@zxn ~]# echo "zxn@ncist.edu.cn" | grep -E -o ".*@[[:alnum:]]+.(com|cn|edu.cn)$"
zxn@ncist.edu.cn

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

[root@zxn ~]# find /var/* -user root -group mail
/var/spool/mail
/var/spool/mail/root
[root@zxn ~]# ls -ld /var/spool/mail/root
-rw-------. 1 root mail 623 9月  10 18:40 /var/spool/mail/root

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

[root@zxn ~]# find  /  \( -nogroup -o -nouser \) -ls
102325563    0 -rw-rw----   1 1002     mail            0 8月 23 23:46 /var/spool/mail/user2102325565    0 -rw-rw----   1 1003     mail            0 8月 23 23:46 /var/spool/mail/user33050125    4 drwx------   5 hadoop   1001         4096 8月 24 00:54 /home/user139252847    0 drwxr-xr-x   4 hadoop   1001           37 8月 14 09:19 /home/user1/.mozilla
[root@zxn ~]# find / \( -nogroup -o -nouser \) -atime -3

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

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

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

[root@zxn ~]# find /etc -size +1M -type f -ls
2287674 6228 -r--r--r--   1 root     root      6376691 8月 14 09:26 /etc/udev/hwdb.bin
102088141 3752 -rw-r--r--   1 root     root      3839718 3月  6  2015 /etc/selinux/targeted/policy/policy.29
101494228 1336 -rw-r--r--   1 root     root      1367395 3月  6  2015 /etc/brltty/zh-tw.ctb

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

[root@zxn ~]# find /etc/init.d -perm -113 -ls
33701805    0 lrwxrwxrwx   1 root     root   11 8月 14 09:20 /etc/init.d -> rc.d/init.d

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

[root@zxn ~]# find /usr -not \( -user root -o -user bin -o -user hadoop \) -ls
921800    4 drwx------   2 polkitd  root  4096 8月 14 09:27 /usr/share/polkit-1/rules.d
34446281   12 -rwsr-sr-x   1 abrt  abrt   11232 3月 24  2015 /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

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

[root@zxn ~]# find /etc/ -not -perm -222 -type f -ls
/smartd_warning.sh
36069630    4 -rw-r--r--   1 root     root            1 10月  7  2014 /etc/at.deny
35959044    4 -rw-r--r--   1 root     root         2872 6月 10  2014 /etc/pinforc
35958973    4 -rw-r-----   1 root     root         3181 3月  6  2015 /etc/sudo-ldap.conf

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

[root@zxn ~]# find /etc -mtime -7 -not \( -user root -o -user hadoop \)

原創文章,作者:N22-北京-張zhangzhang,如若轉載,請注明出處:http://www.www58058.com/45106

(0)
N22-北京-張zhangzhangN22-北京-張zhangzhang
上一篇 2016-09-15
下一篇 2016-09-15

相關推薦

  • nmcli及網絡配置

    。

    2017-09-10
  • 第一周博客作業

    計算機的組成 CPU:運算器、控制器、寄存器、緩存 存儲器:內存 RAM(Random-Access Memory) Input:輸入指令、提供數據 Output: 輸出數據加工后的結果 功能: 輸入設備負責把用戶的信息輸入到計算機中 輸出設備負責將計算機中的信息(包括程序和數據)傳送到外部媒介,供用戶查看或保存; 存儲器負責存儲數據和程序,并根據控制命令提…

    Linux干貨 2017-01-10
  • 壓縮、解壓縮及歸檔工具

    壓縮、解壓縮及歸檔工具 縮文件的基本原理是查找文件內的重復字節,并建立一個相同字節的"詞典"文件,并用一個代碼表示,比如在文件里有幾處有一個相同的詞"中華人民共和國"用一個代碼表示并寫入"詞典"文件,這樣就可以達到縮小文件的目的。         &#8212…

    Linux干貨 2016-08-18
  • 計算機的組成、Linux主流三大版本的區別、Linux的哲學思想、Linux的使用格式及命令的使用簡略說明,以及如何查看命令幫助、FHS目錄機構

    計算機的組成極其功能? 按功能來說計算機是由運算器、控制器、I/O系統(輸入、輸出系統)、存儲器五部分組成。 運算器:即中央處理器(CPU)作為五大部分中心的主腦,對數據進行邏輯運算或算數運算。 控制器:主要是指內存設備,將讀取到的數據臨時保存在內存中這個過程被成為尋址。在cpu中也有屬于自己的控制器稱之為CPU的寄存器來進行多指令的行。 I/O系統:輸入系…

    2017-12-03
  • 2016/10/19作業:軟鏈接與硬鏈接的區別

    軟鏈接和硬鏈接的區別 linux中鏈接分為兩種,一種是硬鏈接(Hard Link),一種是符號鏈接(Symbolic Link),其中,符號鏈接又稱為軟鏈接。 硬鏈接: 在Linux文件系統中 ,磁盤中的所有文件都有一個編號,這個編號稱為索引節點(Inode)。在Linux中,多個同一索引節點可以有多個文件名,這就是硬鏈接。硬鏈…

    Linux干貨 2016-10-20
  • N22-第五周作業

    1、顯示當前系統上root、fedora或user1用戶的默認shell;  egrep "^(root|fedora|user1)" /etc/passwd|awk -F: '{printf "%-15s:%-s\n",$1,$7}' 2…

    Linux干貨 2016-09-15
欧美性久久久久