1. 查看static這個連接文件是否自動連接的命令是____________________________________;
2. 查看default這個連接文件是否自動連接的命令是_____________________________________;
3. 查看con0這個連接文件是否自動連接的命令是___________________________________;
4. 對于grep和sed來講,在不開E的情況下就能生效的符號是. * ^ [ ] 以及__,而在開E的情況下才能生效的三個符號是 ( ) 以及____;
5. 對于grep和sed來講,在不開E的情況下就能生效的符號是__ * ^ [ ] $,而在開E的情況下才能生效的三個符號是 ( __ |;
6. 對于grep和sed來講,在不開E的情況下就能生效的符號是. * __ [ ] $,而在開E的情況下才能生效的三個符號是 __ ) |;
7. 將/etc/selinux/config文件中的"SELINUX=permissive"修改為"SELINUX=enforcing"的方法是__________________________________________;
8. 將/etc/selinux/config文件中的"SELINUX=enforcing"試探性地修改為"SELINUX=permissive"的方法是__________________________________________;
9. 對ps aux命令的結果(被保存到了文件nowcoder.txt當中)做統計,統計VSZ,RSS各自的總和(以M兆為單位統計),輸出格式如下
MEM TOTAL
VSZ_SUM:3250.8M,RSS_SUM:179.777M
方法是_______________________________;
(ps aux命令的前10行結果為:
USER ? ? ? ? PID %CPU %MEM ? ?VSZ ? RSS TTY ? ? ?STAT START ? TIME COMMAND
root ? ? ? ? ? 1 ?0.1 ?0.4 107392 16268 ? ? ? ? ?Ss ? 19:23 ? 0:02 /usr/lib/systemd/systemd rhgb --switched-root --system --deserialize 31
root ? ? ? ? ? 2 ?0.0 ?0.0 ? ? ?0 ? ? 0 ? ? ? ? ?S ? ?19:23 ? 0:00 [kthreadd]
root ? ? ? ? ? 3 ?0.0 ?0.0 ? ? ?0 ? ? 0 ? ? ? ? ?I< ? 19:23 ? 0:00 [rcu_gp]
root ? ? ? ? ? 4 ?0.0 ?0.0 ? ? ?0 ? ? 0 ? ? ? ? ?I< ? 19:23 ? 0:00 [rcu_par_gp]
root ? ? ? ? ? 5 ?0.0 ?0.0 ? ? ?0 ? ? 0 ? ? ? ? ?I ? ?19:23 ? 0:01 [kworker/0:0-events]
root ? ? ? ? ? 6 ?0.0 ?0.0 ? ? ?0 ? ? 0 ? ? ? ? ?I< ? 19:23 ? 0:00 [kworker/0:0H-events_highpri]
root ? ? ? ? ? 9 ?0.0 ?0.0 ? ? ?0 ? ? 0 ? ? ? ? ?I< ? 19:23 ? 0:00 [mm_percpu_wq]
root ? ? ? ? ?10 ?0.0 ?0.0 ? ? ?0 ? ? 0 ? ? ? ? ?S ? ?19:23 ? 0:00 [rcu_tasks_kthre]
root ? ? ? ? ?11 ?0.0 ?0.0 ? ? ?0 ? ? 0 ? ? ? ? ?S ? ?19:23 ? 0:00 [rcu_tasks_rude_]
)
10. 從下列文本中,選出這樣的值:
serverVersion:Apache Tomcat/8.5.15
serverName:8.5.15.0
osName:Windows
osVersion:10
文本為:
12-May-2017 10:02:22.789 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:Apache Tomcat/8.5.15
12-May-2017 10:02:22.813 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:May 5 2017 11:03:04 UTC
12-May-2017 10:02:22.813 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:8.5.15.0
12-May-2017 10:02:22.814 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:Windows, OS Version:10
12-May-2017 10:02:22.814 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:x86_64
其被保存在nowcoder.txt當中
11. nowcoder.txt的內容為:
Proto Recv-Q Send-Q Local Address ? ? ? ? ? Foreign Address ? ? ? ? State
tcp ? ? ? ?0 ? ? ?0 0.0.0.0:6160 ? ? ? ? ? ?0.0.0.0:* ? ? ? ? ? ? ? LISTEN
tcp ? ? ? ?0 ? ? ?0 127.0.0.53:53 ? ? ? ? ? 0.0.0.0:* ? ? ? ? ? ? ? LISTEN
tcp ? ? ? ?0 ? ? ?0 0.0.0.0:22 ? ? ? ? ? ? ?0.0.0.0:* ? ? ? ? ? ? ? LISTEN
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:41856 ? ? 172.16.34.144:3306 ? ? ?ESTABLISHED
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:49822 ? ? 172.16.0.24:3306 ? ? ? ?ESTABLISHED
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:49674 ? ? 172.16.0.24:3306 ? ? ? ?ESTABLISHED
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:42316 ? ? 172.16.34.144:3306 ? ? ?ESTABLISHED
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:44076 ? ? 172.16.240.74:6379 ? ? ?ESTABLISHED
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:49656 ? ? 172.16.0.24:3306 ? ? ? ?ESTABLISHED
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:58248 ? ? 100.100.142.4:80 ? ? ? ?TIME_WAIT
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:50108 ? ? 172.16.0.24:3306 ? ? ? ?ESTABLISHED
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:41944 ? ? 172.16.34.144:3306 ? ? ?ESTABLISHED
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:35548 ? ? 100.100.32.118:80 ? ? ? TIME_WAIT
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:39024 ? ? 100.100.45.106:443 ? ? ?TIME_WAIT
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:41788 ? ? 172.16.34.144:3306 ? ? ?ESTABLISHED
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:58260 ? ? 100.100.142.4:80 ? ? ? ?TIME_WAIT
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:41812 ? ? 172.16.34.144:3306 ? ? ?ESTABLISHED
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:41854 ? ? 172.16.34.144:3306 ? ? ?ESTABLISHED
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:58252 ? ? 100.100.142.4:80 ? ? ? ?TIME_WAIT
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:49586 ? ? 172.16.0.24:3306 ? ? ? ?ESTABLISHED
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:41754 ? ? 172.16.34.144:3306 ? ? ?ESTABLISHED
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:50466 ? ? 120.55.222.235:80 ? ? ? TIME_WAIT
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:38514 ? ? 100.100.142.5:80 ? ? ? ?TIME_WAIT
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:49832 ? ? 172.16.0.24:3306 ? ? ? ?ESTABLISHED
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:52162 ? ? 100.100.30.25:80 ? ? ? ?ESTABLISHED
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:50372 ? ? 172.16.0.24:3306 ? ? ? ?ESTABLISHED
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:50306 ? ? 172.16.0.24:3306 ? ? ? ?ESTABLISHED
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:49600 ? ? 172.16.0.24:3306 ? ? ? ?ESTABLISHED
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:41908 ? ? 172.16.34.144:3306 ? ? ?ESTABLISHED
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:60292 ? ? 100.100.142.1:80 ? ? ? ?TIME_WAIT
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:37650 ? ? 100.100.54.133:80 ? ? ? TIME_WAIT
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:41938 ? ? 172.16.34.144:3306 ? ? ?ESTABLISHED
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:49736 ? ? 172.16.0.24:3306 ? ? ? ?ESTABLISHED
tcp ? ? ? ?0 ? ? ?0 172.16.56.200:41890 ? ? 172.16.34.144:3306 ? ? ?ESTABLISHED
udp ? ? ? ?0 ? ? ?0 127.0.0.1:323 ? ? ? ? ? 0.0.0.0:*
udp ? ? ? ?0 ? ? ?0 0.0.0.0:45881 ? ? ? ? ? 0.0.0.0:*
udp ? ? ? ?0 ? ? ?0 127.0.0.53:53 ? ? ? ? ? 0.0.0.0:*
udp ? ? ? ?0 ? ? ?0 172.16.56.200:68 ? ? ? ?0.0.0.0:*
udp6 ? ? ? 0 ? ? ?0 ::1:323 ? ? ? ? ? ? ? ? :::*
raw6 ? ? ? 0 ? ? ?0 :::58 ? ? ? ? ? ? ? ? ? :::* ? ? ? ? ? ? ? ? ? ?7
編寫shell腳本查看系統tcp連接中各個狀態的連接數,并且按照連接數降序輸出。你的腳本應該輸出如下:
ESTABLISHED 22
TIME_WAIT 9
LISTEN 3
12. 接著第11題,查看和本機3306端口建立連接并且狀態是established的所有IP,按照連接數降序排序。你的腳本應該輸出
10 172.16.0.24
9 172.16.34.144
1 172.16.34.143
13. 接著第11題,輸出每個IP的連接數,按照連接數降序排序。你的腳本應該輸出
172.16.0.24 10
172.16.34.144 9
100.100.142.4 3
0.0.0.0 3
172.16.34.143 1
172.16.240.74 1
120.55.222.235 1
100.100.54.133 1
100.100.45.106 1
100.100.32.118 1
100.100.30.25 1
100.100.142.5 1
100.100.142.1 1
14. 接著第11題,輸出和本機3306端口建立連接的各個狀態的數目,按照以下格式輸出
TOTAL_IP表示建立連接的ip數目
TOTAL_LINK表示建立連接的總數目
TOTAL_IP 3
ESTABLISHED 20
TOTAL_LINK 20
15. 假設 Nginx 的日志存儲在 nowcoder.txt 里,內容如下:
192.168.1.20 - - [21/Apr/2020:14:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.21 - - [21/Apr/2020:15:27:49 +0800] "GET /2/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.22 - - [21/Apr/2020:21:27:49 +0800] "GET /3/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.23 - - [21/Apr/2020:22:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.24 - - [22/Apr/2020:15:27:49 +0800] "GET /2/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.25 - - [22/Apr/2020:15:26:49 +0800] "GET /3/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.20 - - [23/Apr/2020:08:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.21 - - [23/Apr/2020:09:20:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.22 - - [23/Apr/2020:10:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.22 - - [23/Apr/2020:10:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.20 - - [23/Apr/2020:14:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.21 - - [23/Apr/2020:15:27:49 +0800] "GET /2/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.22 - - [23/Apr/2020:15:27:49 +0800] "GET /3/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.25 - - [23/Apr/2020:16:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.24 - - [23/Apr/2020:20:27:49 +0800] "GET /2/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.25 - - [23/Apr/2020:20:27:49 +0800] "GET /3/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.20 - - [23/Apr/2020:20:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.21 - - [23/Apr/2020:20:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.22 - - [23/Apr/2020:20:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.22 - - [23/Apr/2020:15:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.21 - - [23/Apr/2020:20:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
現在需要編寫 Shell 腳本統計出 2020 年 4 月 23 號訪問 IP 的對應次數,并且按照次數降序排序。你的腳本應該輸出:
5 192.168.1.22
4 192.168.1.21
3 192.168.1.20
2 192.168.1.25
1 192.168.1.24
16. 接15題,
現在需要編寫 Shell 腳本統計 2020年04月23日20點至23點去重后的 IP 訪問量,你的腳本應該輸出:
5
輸出說明:2020年04月23日20點至23點,共有 192.168.1.24、192.168.1.25、192.168.1.20、192.168.1.21、192.168.1.22 共 5 個 IP 訪問了。
17. 接15題,
現在需要編寫shell腳本統計訪問3次以上的IP,你的腳本應該輸出:
6 192.168.1.22
5 192.168.1.21
4 192.168.1.20
18. 接15題,
假設Nginx的日志存儲在nowcoder.txt里,內容如下:
現在需要編寫shell腳本查詢192.168.1.22的詳細訪問次數情況,按訪問頻率降序排序。你的腳本應該輸出:
4 /1/index.php
2 /3/index.php
19. 接15題,
假設nginx的日志存儲在nowcoder.txt里,內容如下:
現在需要編寫shell腳本統計百度爬蟲抓取404的次數,你的腳本應該輸出
2
20. 接15題,
假設Nginx的日志存儲在nowcoder.txt里,內容如下:
現在需要編寫Shell腳本統計每分鐘的請求數,并且按照請求數降序排序。你的腳本應該輸出:
5 20:27
4 15:00
2 22:10
2 14:12
2 10:27
1 23:59
1 21:21
1 16:15
1 15:26
1 09:20
1 08:05
21.?
有一個文本文件nowcoder.txt,假設內容格式如下:
111:13443
222:13211
111:13643
333:12341
222:12123
現在需要編寫一個shell腳本,按照以下的格式輸出:
[111]
13443
13643
[222]
13211
12123
[333]
12341
22.?
有一個文件nowcoder.txt,里面的每一行都是一個數字串,編寫一個shell腳本對文件中每一行的數字串進行格式化:每3個數字加入一個逗號(,)。
例如:數字串為“123456789”,那么需要格式化為123,456,789。
假設nowcoder.txt內容如下:
1
12
123
1234
123456
那么你的腳本輸出如下:
1
12
123
1,234
123,456
23.?
假設有一個nowcoder.txt,編寫腳本,打印只有一個數字的行。
假設nowcoder.txt內容如下:
haha
1
2ab
cd
77
那么你的腳本應該輸出
1
2ab
24.?
假設有一些域名,存儲在nowcoder.txt里,現在需要寫一個shell腳本,將域名取出并根據域名進行計數排序處理(降序)。
假設nowcoder.txt內容如下:
http://www.nowcoder.com/index.html
http://www.nowcoder.com/1.html
http://m.nowcoder.com/index.html
你的腳本應該輸出:
2 www.nowcoder.com
1 m.nowcoder.com
25.?
編寫一個shell腳本,將文件nowcoder.txt中每一行的字段逆序輸出,其中字段之間使用英文冒號:相分隔。
假設nowcoder.txt內容如下:
nobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false
root:*:0:0:System Administrator:/var/root:/bin/sh
你的腳本應當輸出
/usr/bin/false:/var/empty:Unprivileged User:-2:-2:*:nobody
/bin/sh:/var/root:System Administrator:0:0:*:root
26.?
寫一個腳本統計文件nowcoder.txt中的每一行是否是正確的IP地址。
如果是正確的IP地址輸出:yes
如果是錯誤的IP地址,且是四段號碼的話輸出:no,否則的話輸出:error
假設nowcoder.txt內容如下:
192.168.1.1
192.168.1.0
300.0.0.0
123
你的腳本應該輸出:
yes
yes
no
error
27.?
寫一個bash腳本以實現一個需求,去掉輸入中含有B和b的單詞
示例:
假設輸入如下:
big
nowcoder
Betty
basic
test
你的腳本獲取以上輸入應當輸出:
nowcoder test
說明:
你可以不用在意輸出的格式,空格和換行都行
28.?
寫一個bash腳本以實現一個需求,求輸入的一個數組的平均值
第1行為輸入的數組長度N
第2~N行為數組的元素,如以下為:
數組長度為4,數組元素為1 2 9 8
示例:
4
1
2
9
8
那么平均值為:5.000(保留小數點后面3位)
你的腳本獲取以上輸入應當輸出:
5.000
29.?
編寫一個shell腳本以實現如下功能:去掉輸入中含有this的語句,把不含this的語句輸出
示例:
假設輸入如下:
that is your bag
is this your bag?
to the degree or extent indicated.
there was a court case resulting from this incident
welcome to nowcoder
你的腳本獲取以上輸入應當輸出:
that is your bag
to the degree or extent indicated.
welcome to nowcoder
說明:
你可以不用在意輸出的格式,包括空格和換行
30.?
寫一個bash腳本,統計一個文本文件nowcoder.txt中每一行出現的1~5數字的個數,并且計算一下整個文檔中一共出現了幾個1~5數字的總數。
示例:
假設 nowcoder.txt 內容如下:
a12b8
10ccc
2521abc
9asf
你的腳本應當輸出:
line1 number: 2
line2 number: 1
line3 number: 4
line4 number: 0
sum is 7
說明:
不要擔心你輸出的空格以及換行的問題
31.?
寫一個bash腳本來轉置文本文件nowcoder.txt中的文件內容。
文件中每行列數相同,并且每個字段由空格分隔
示例:
假設 nowcoder.txt 內容如下:
job salary
c++ 13
java 14
php 12
你的腳本應當輸出(以詞頻升序排列):
job c++ java php
salary 13 14 12
32.?
給定一個nowcoder.txt文件,其中有3列信息,如下:
20201001 python 99
20201002 go 80
20201002 c++ 88
20201003 php 77
20201001 go 88
20201005 shell 89
20201006 java 70
20201008 c 100
20201007 java 88
20201006 go 97
編寫一個shell腳本來檢查文件第二列是否有重復,且有幾個重復,并提取出重復的行的第二列信息(先按次數排序,如果次數相同,按照單詞字母順序排序),輸入如下:
2 java
3 go
33.?
寫一個bash腳本以統計一個文本文件nowcoder.txt 中每個單詞出現的個數。
為了簡單起見,你可以假設:
nowcoder.txt只包括小寫字母和空格,每個單詞只由小寫字母組成,單詞間由一個或多個空格字符分隔。
示例:
假設 nowcoder.txt 內容如下:
welcome nowcoder
welcome to nowcoder
nowcoder
你的腳本應當輸出(以詞頻升序排列):
to 1?
welcome 2?
nowcoder 3?
說明:
不要擔心個數相同的單詞的排序問題,每個單詞出現的個數都是唯一的。
34.?
假設 nowcoder.txt 內容如下:
USER ? ? ? PID %CPU %MEM ? ?VSZ ? RSS TTY ? ? ?STAT START ? TIME COMMAND
root ? ? ? ? 1 ?0.0 ?0.4 ?77744 ?8332 ? ? ? ? ?Ss ? ?2021 ? 1:15 /sbin/init noibrs splash
root ? ? ? ? 2 ?0.0 ?0.0 ? ? ?0 ? ? 0 ? ? ? ? ?S ? ? 2021 ? 0:00 [kthreadd]
root ? ? ? ? 4 ?0.0 ?0.0 ? ? ?0 ? ? 0 ? ? ? ? ?I< ? ?2021 ? 0:00 [kworker/0:0H]
daemon ? ? 486 ?0.0 ?0.1 ?28340 ?2372 ? ? ? ? ?Ss ? ?2021 ? 0:00 /usr/sbin/atd -f
root ? ? ? 586 ?0.0 ?0.3 ?72308 ?6244 ? ? ? ? ?Ss ? ?2021 ? 0:01 /usr/sbin/sshd -D
root ? ? 12847 ?0.0 ?0.0 ? 4528 ? ?68 ? ? ? ? ?S< ? Jan03 ? 0:13 /usr/sbin/atopacctd
root ? ? 16306 ?1.7 ?1.2 151964 26132 ? ? ? ? ?S<sl Apr15 512:03 /usr/local/aegis/aegis_client/aegis_11_25/AliYunDun
root ? ? 24143 ?0.0 ?0.4 ?25608 ?8652 ? ? ? ? ?S<Ls 00:00 ? 0:03 /usr/bin/atop -R -w /var/log/atop/atop_20220505 600
root ? ? 24901 ?0.0 ?0.3 107792 ?7008 ? ? ? ? ?Ss ? 15:37 ? 0:00 sshd: root@pts/0
root ? ? 24903 ?0.0 ?0.3 ?76532 ?7580 ? ? ? ? ?Ss ? 15:37 ? 0:00 /lib/systemd/systemd --user
root ? ? 24904 ?0.0 ?0.1 111520 ?2392 ? ? ? ? ?S ? ?15:37 ? 0:00 (sd-pam)
以上內容是通過ps aux命令輸出到nowcoder.txt文件中的,請你寫一個腳本計算一下所有進程占用內存大小的和。
35.?
寫一個bash腳本以統計一個文本文件nowcoder.txt中字母數小于8的單詞。
示例:
假設 nowcoder.txt 內容如下:
how they are implemented and applied in computer
你的腳本應當輸出:
how
they
are
and
applied
in
說明:
不用擔心你輸出的空格以及換行的問題
36.?
編寫一個shell腳本以輸出一個文本文件nowcoder.txt中空行的行號(空行可能連續,從1開始輸出)
示例:
假設 nowcoder.txt 內容如下:
a
b
c
d
e
f
你的腳本應當輸出:
3
5
7
9
10
37.?
編寫一個bash腳本以輸出一個文本文件nowcoder.txt中第5行的內容。
示例:
假設 nowcoder.txt 內容如下:
welcome
to
nowcoder
this
is
shell
code
你的腳本應當輸出:
is
38.?
寫一個 bash腳本以輸出數字 0 到 500 中 7 的倍數(0 7 14 21...)的命令
1. nmcli con show static | grep 'connection\.autoconnect'
2. nmcli con show default | grep 'connection\.autoconnect'
3. nmcli con show con0 | grep 'connection\.autoconnect'
4. $ ? ?|
5. . ? ?)
6. ^ ? ?(
7. sed -i 's/^SELINUX=.*/SELINUX=enforcing/' /etc/selinux/config
8. sed -n 's/^SELINUX=.*/SELINUX=permissive/p' /etc/selinux/config
9.?
echo MEM TOTAL
vsz_sum=`awk 'NR>1{sum+=$5} END{print sum/1024}' nowcoder.txt`
rss_sum=`awk 'NR>1{sum+=$6} END{print sum/1024}' nowcoder.txt`
echo VSZ_SUM:"$vsz_sum"M,RSS_SUM:"$rss_sum"M
10.?
serverVersion=`grep 'Server version' nowcoder.txt | awk -F 'Server version:' '{print $2}'`
serverName=`grep 'Server number' nowcoder.txt | awk -F 'Server number:' '{print $2}'`
osName=`grep 'OS Name' nowcoder.txt | awk -F 'OS Name:' '{print $2}' | awk -F ', OS Version:' '{print $1}'`
osVersion=`grep 'OS Name' nowcoder.txt | awk -F 'OS Name:' '{print $2}' | awk -F ', OS Version:' '{print $2}'`
echo serverVersion:"$serverVersion"
echo serverName:"$serverName"
echo osName:"$osName"
echo osVersion:"$osVersion"
11.?
ESTABLISHED=`awk '$1=="tcp" && $6=="ESTABLISHED"{count++} END{print count}' nowcoder.txt`
TIME_WAIT=`awk '$1=="tcp" && $6=="TIME_WAIT"{count++} END{print count}' nowcoder.txt`
LISTEN=`awk '$1=="tcp" && $6=="LISTEN"{count++} END{print count}' nowcoder.txt`
echo -e ESTABLISHED "$ESTABLISHED""\n"TIME_WAIT "$TIME_WAIT""\n"LISTEN "$LISTEN""\n" | sort -k2 -nr
12.?
awk '{print $5}' nowcoder.txt | awk -F':' '{if($2=="3306"){array[$1]+=1}} END{for(item in array){print array[item], item}}' | sort -k1 -nr
13.?
awk '$1=="tcp"{print $5}' nowcoder.txt | awk -F':' '{array[$1]+=1} END{for(item in array) {print item, array[item]}}' | sort -k2 -nr
14.?
awk '{print $5}' nowcoder.txt | awk -F':' '{if($2=="3306"){array[$1]+=1}} END{for(item in array){count++} print "TOTAL_IP", count}'
awk '$6=="ESTABLISHED"&&$5~/3306/{count++} END{print "ESTABLISHED", count}' nowcoder.txt
awk '$6=="ESTABLISHED"&&$5~/3306/{count++} END{print "TOTAL_LINK", count}' nowcoder.txt
或者
echo TOTAL_IP `awk '{print $5}' nowcoder.txt | awk -F':' '$2=="3306"{print $1}' | sort | uniq | wc -l`
awk '$6=="ESTABLISHED"&&$5~/3306/{count++} END{print "ESTABLISHED", count}' nowcoder.txt
awk '$6=="ESTABLISHED"&&$5~/3306/{count++} END{print "TOTAL_LINK", count}' nowcoder.txt
15.?
grep '23/Apr/2020' nowcoder.txt | awk '{array[$1]+=1} END{for(item in array) {print array[item], item}}' | sort -k1 -rn
16.?
grep '23/Apr/2020' nowcoder.txt | awk -F':' '$2>=20&&$2<=23{print $1}' | awk '{print $1}' | sort | uniq | wc -l
17.?
awk '{array[$1]+=1} END{for(item in array) {if(array[item]>3) {print array[item], item}}}' | sort -k1 -rn
18.?
grep '192\.168\.1\.22' nowcoder.txt | awk -F'GET ' '{print $2}' | awk '{array[$1]+=1} END{for(item in array) {print array[item], item}}' | sort -k1 -rn
19.?
grep 'Baiduspider' nowcoder.txt | awk -F'"' '{print $2}' | sort | uniq | wc -l
20.?
awk -F':' '{array[$2":"$3]+=1} END{for(item in array) {print array[item], item}}' nowcoder.txt | sort -k1 -rn
21.?
awk -F':' '{array[$1]=array[$1]"\n"$2} END{for(item in array) {print "["item"]"array[item]}}'
22.?
awk 'BEGIN{FS=""}{
? ? for(i=1;i<=NF;i++){
? ? ? ? if((NF-i)%3==0 && NF-i!=0){
? ? ? ? ? ? printf("%s,", i);
? ? ? ? }
? ? ? ? else{
? ? ? ? ? ? printf("%s", i);
? ? ? ? }
? ? }
? ? printf("\n")
}' nowcoder.txt
23.?
awk -F'[[:digit:]]' '{if(NF==2) print $0}' nowcoder.txt
24.?
awk -F'/' '{array[$3]+=1} END{for(item in array) {print array[item], item}}' nowcoder.txt | sort -rn -k1
25.?
awk -F':' '{for(i=NF; i>1; i--) {printf("%s:", $i)} printf("%s\n", $1)}' nowcoder.txt
或者
awk -F':' '{str=$NF; for(i=NF-1;i>=1;i--) {str=str":"$i} print str}' nowcoder.txt
26.?
awk -F'.' '{
? ? if(NF!=4) print "error"
? ? else{
? ? ? ? for(i=1; i<=4;i++){
? ? ? ? ? ? if($i>255 || $i<0){
? ? ? ? ? ? ? ? print "no"
? ? ? ? ? ? ? ? break
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? if(i==5) print "yes"
? ? }
}' nowcoder.txt
27.?
grep -v 'B\|b' nowcoder.txt
28.?
read N
for i in `seq $((N))`
do
? ? read temp
? ? sum=$((sum+temp))
done
echo "scale=3; $sum/$N" | bc
29.?
grep -v 'this' nowcoder.txt
30.?
awk 'BEGIN{FS=""} {
? ? array[NR]=0
? ? for(i=1;i<=NF;i++){
? ? ? ? if($i>=1 && $i<=5){
? ? ? ? ? ? array[NR]+=1
? ? ? ? }
? ? }
}
END{
? ? for(item in array) {print "line"item" number: "array[item]}
? ? for(item in array) {sum+=array[item]}
? ? print "sum is "sum
}' nowcoder.txt
31.?
awk '{
? ? for(i=1;i<=NF;i++) {
? ? ? ? array[i]=array[i]" "$i
? ? }
}
END{
? ? for(i=1;i<=NF;i++) print array[i]
}' nowcoder.txt | sort
32.?
awk '{array[$2]+=1} END{
? ? for(item in array){
? ? ? ? if(array[item]!=1) print array[item], item
? ? }
}' nowcoder.txt | sort -k1 -n
33.?
awk '{for(i=1;i<=NF;i++) array[$i]+=1} END{
? ? for(item in array) {
? ? ? ? print item, array[item]
? ? }
}' nowcoder.txt | sort -k2 -n
34.?
awk '{sum+=$4} END{print sum}' nowcoder.txt
35.?
awk '{for(i=1;i<=NF;i++){
?? ?if(length($i)<8) print $i
}}' nowcoder.txt
36.?
awk '/^$/{print NR}' nowcoder.txt
37.?
awk '{if(NR==5)print $0}' nowcoder.txt
38.?
for i in `seq 0 500`
do
?? ?[ $((i%7)) -eq 0 ] && echo $i
done
exit 0