RedHat運維-Linux文本操作基礎-牛客AWK

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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/42385.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/42385.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/42385.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【Python】已解決:(paddleocr導包報錯)ModuleNotFoundError: No module named ‘paddle’

文章目錄 一、分析問題背景二、可能出錯的原因三、錯誤代碼示例四、正確代碼示例五、注意事項 已解決&#xff1a;&#xff08;paddleocr導包報錯&#xff09;ModuleNotFoundError: No module named ‘paddle’ 一、分析問題背景 近日&#xff0c;一些使用PaddleOCR庫進行文字…

Python數據分析案例49——基于機器學習的垃圾郵件分類系統構建(樸素貝葉斯,支持向量機)

案例背景 trec06c是非常經典的郵件分類的數據&#xff0c;還是難能可貴的中文數據集。 這個數據集從一堆txt壓縮包里面提取出來整理為excel文件還真不容不易&#xff0c;肯定要做一下文本分類。 雖然現在文本分類基本都是深度學習了&#xff0c;但是傳統的機器學習也能做。本案…

C#架構師的成長之路

成為一名C#架構師不僅需要深厚的技術功底&#xff0c;還需要廣泛的行業知識、優秀的團隊協作能力和領導力。以下是C#架構師成長之路上的關鍵步驟和技能要求&#xff1a; 1. 扎實的技術基礎 精通C#語言&#xff1a;深入理解C#的語法、特性&#xff0c;包括但不限于泛型、多線程…

Xilinx FPGA:vivado關于真雙端口的串口傳輸數據的實驗

一、實驗內容 用一個真雙端RAM&#xff0c;端口A和端口B同時向RAM里寫入數據0-99&#xff0c;A端口讀出單數并存入單端口RAM1中&#xff0c;B端口讀出雙數并存入但端口RAM2中&#xff0c;當檢測到按鍵1到來時將RAM1中的單數讀出顯示到PC端&#xff0c;當檢測到按鍵2到來時&…

Vim編輯器與Shell命令腳本

前言&#xff1a;本博客僅作記錄學習使用&#xff0c;部分圖片出自網絡&#xff0c;如有侵犯您的權益&#xff0c;請聯系刪除 目錄 一、Vim文本編輯器 二、編寫Shell腳本 三、流程控制語句 四、計劃任務服務程序 致謝 一、Vim文本編輯器 “在Linux系統中一切都是文件&am…

Rust 程序設計語言學習——函數式語言功能:迭代器和閉包

Rust 的閉包&#xff08;closures&#xff09;是可以保存在一個變量中或作為參數傳遞給其他函數的匿名函數。可以在一個地方創建閉包&#xff0c;然后在不同的上下文中執行閉包運算。不同于函數&#xff0c;閉包允許捕獲被定義時所在作用域中的值。 迭代器&#xff08;iterato…

C++ STL 隨機數用法介紹

目錄 一:C語言中的隨機數 二:C++中的隨機數 1. 生成隨機數的例子 2. 隨機數引擎 3. 隨機數引擎適配器 4. C++中預定義的隨機數引擎,引擎適配器 5. 隨機數分布 一:C語言中的隨機數 <stdlib.h>//初始化隨機種子 srand(static_cast<unsigned int>(time(nullptr)…

C#面: 依賴注入有哪幾種方式?

依賴注入&#xff08;Dependency Injection&#xff0c;簡稱DI&#xff09;是一種設計模式&#xff0c;用于解耦組件之間的依賴關系。在C#中&#xff0c;常見的依賴注入方式有以下幾種&#xff1a; 構造函數注入&#xff08;Constructor Injection&#xff09;&#xff1a;通過…

dependencyManagement的作用、nacos的學習

使用SpringCloudAlibaba注意各組件的版本適配 SpringCloudAlibaba已經包含了適配的各組件&#xff08;nacos、MQ等&#xff09;的版本號&#xff0c;也是一個版本仲裁者&#xff0c;但是可能已經有了父項目Spring-Boot-Starter-Parent這個版本仲裁者&#xff0c;又不能加多個父…

什么是獨立服務器?

獨立服務器是指一個單獨的物理服務器&#xff0c;整體的硬件設施都是獨立存在的&#xff0c;有著強大的性能&#xff0c;只需要運行用戶個人的數據信息&#xff0c;并且可以享受到獨立服務器的硬件與軟件&#xff0c;當網站有著大量的用戶進行訪問或者是需要運行大型的軟件時&a…

leetcode熱題100.零錢兌換(動態規劃)

今天給大家分享一道動態規劃的常考題&#xff0c;零錢兌換&#xff0c;很有趣的動態規劃題目&#xff0c;希望可以對大家找工作過程中起到幫助&#xff0c;幫助大家拓展下思維 給你一個整數數組 coins &#xff0c;表示不同面額的硬幣&#xff1b;以及一個整數 amount &#xf…

6、Redis系統-數據結構-06-跳表

六、跳表&#xff08;Skiplist&#xff09; 跳表是一種高效的動態數據結構&#xff0c;可以用于實現有序集合&#xff08;Sorted Set&#xff0c;Zset&#xff09;。與平衡樹相比&#xff0c;跳表具有實現簡單、效率高的優點&#xff0c;因此被 Redis 選用作為有序集合的底層數…

階段三:項目開發---搭建項目前后端系統基礎架構:任務13:實現基本的登錄功能

任務描述 任務名稱&#xff1a; 實現基本的登錄功能 知識點&#xff1a; 了解前端Vue項目的基本執行過程 重 點&#xff1a; 構建項目的基本登陸功能 內 容&#xff1a; 通過實現項目的基本登錄功能&#xff0c;來了解前端Vue項目的基本執行過程&#xff0c;并完成基…

如何讓代碼兼容 Python 2 和 Python 3?Future 庫助你一臂之力

目錄 01Future 是什么? 為什么選擇 Future? 安裝與配置 02Future 的基本用法 1、兼容 print 函數 2、兼容整數除法 3、兼容 Unicode 字符串 03Future 的高級功能 1. 處理字符串與字節 2. 統一異常處理…

linux kthread任務管理

目錄 一、linux 創建內核線程1.1 kthread_create1.2 kthread_create_worker kthread_queue_work 二、設置線程優先級和調度策略2.1 sched_setscheduler2.2 調度策略 一、linux 創建內核線程 1.1 kthread_create 在 linux 中&#xff0c;可以使用 kthread_create 接口創建內核…

移動校園(7)ii:uniapp路由響應攔截器處理token,以及微信小程序報錯當前頁面正在處于跳轉狀態,請稍后再進行跳轉....

依據昨天的寫完&#xff0c;在token過期之后&#xff0c;再次調用接口&#xff0c;會觸發后端攔截&#xff0c;扔進全局錯誤處理中間件 前端說明提示都沒有&#xff0c;只有一個這個&#xff0c;現在優化一下&#xff0c;再寫一個類似全局后置守衛&#xff0c;當狀態碼是401的時…

MySQL——數據連接池

數據庫連接 --- 執行完畢 --- 釋放&#xff08;連接到釋放的過程十分浪費系統資源&#xff09; 池化技術&#xff1a;準備一些預先的資源&#xff0c;過來就連接預先準備好的 編寫連接池&#xff0c;實現一個接口 DataSource 開源數據源實現&#xff08;拿來即用&#xff09;…

增強安全防護,解讀智慧校園系統的登錄日志功能

在構建智慧校園系統時&#xff0c;登錄日志功能扮演著不可或缺的角色&#xff0c;它不僅是系統安全的守護者&#xff0c;也是提升管理效率和確保合規性的有力工具。這一機制詳細記錄每次登錄嘗試的方方面面&#xff0c;涵蓋了時間戳、用戶身份、登錄來源的IP地址乃至使用的設備…

phpcms 升級php8.3.8

windows 2008 server 不支持php8.3.8,需升級為windows 2012 1.下載php8.3.8 PHP8.3.9 For Windows: Binaries and sources Releases 2.配置php.ini (1.)在php目錄下找到php.ini-development文件&#xff0c;把它復制一份&#xff0c;改名為php.ini (2.)修改php安裝目錄 根…

《昇思 25 天學習打卡營第 10 天 | ResNet50 遷移學習 》

《昇思 25 天學習打卡營第 10 天 | ResNet50 遷移學習 》 活動地址&#xff1a;https://xihe.mindspore.cn/events/mindspore-training-camp 簽名&#xff1a;Sam9029 使用遷移學習進行狼狗圖像分類 簡介 在機器學習和深度學習中&#xff0c;我們經常面臨數據不足的問題。 遷…