Linux与Shell课程一知识串讲

帮助

寻找帮助的顺序

  • help
  • man
  • 官方文档

常用命令

  • df du find
  • ps top
  • netstat

三剑客

223.104.7.59 - - [05/Dec/2018:00:00:01 +0000] "GET /topics/17112 HTTP/2.0" 200 9874 "https://www.googleapis.com/auth/chrome-content-suggestions" "Mozilla/5.0 (iPhone; CPU iPhone OS 12_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/70.0.3538.75 Mobile/15E148 Safari/605.1" 0.040 0.040 .

awk自动数字段

[root@shell.ceshiren.com ~]$ less nginx.log |head -1 | awk '{for(i=1;i<=NF;i++) print "$"i" = "$i}'
$1 = 223.104.7.59
$2 = -
$3 = -
$4 = [05/Dec/2018:00:00:01
$5 = +0000]
$6 = "GET
$7 = /topics/17112
$8 = HTTP/2.0"
$9 = 200
$10 = 9874
$11 = "https://www.googleapis.com/auth/chrome-content-suggestions"
$12 = "Mozilla/5.0
$13 = (iPhone;
$14 = CPU
$15 = iPhone
$16 = OS
$17 = 12_1
$18 = like
$19 = Mac
$20 = OS
$21 = X)
$22 = AppleWebKit/605.1.15
$23 = (KHTML,
$24 = like
$25 = Gecko)
$26 = CriOS/70.0.3538.75
$27 = Mobile/15E148
$28 = Safari/605.1"
$29 = 0.040
$30 = 0.040
$31 = .

相关链接

PPT

课间作业

  • 找出nginx.log中的404 500的报错 考察严谨性

我是16期学员 :sweat_smile:
awk ‘$9~/404|500/ {print $0}’ nginx.log

awk '$9==404||$9==500 {print}' nginx.log

less nginx.log |awk ‘{print $9}’|grep -E ‘404|500’

cat nginx.log |grep 404

cat ngnix.log | awk ‘{print $9}’ | grep -E ‘404|500’

cat nginx.log | awk '{print $9}' | grep -E '404|500'

cat nginx.log | grep “500 /|400”

cat nginx.log|awk '$9 ~/404|500/ {print $0}'
cat nginx.log|grep -E " HTTP/.* 404 | HTTP/.* 500 "|less
2 Likes
cat nginx.log | awk '$9~/404|500/'
1 Like
awk '$9~/404|500/' nginx.log
1 Like
awk '$9~/404|500/' nginx.log

less nginx.log | awk ‘{print $9}’ | grep -E ‘404|500’ | wc -l

cat nginx.log | awk ‘$9~/404|500/’

‘’’
less nginx.log | grep -E “404|500” | awk ‘{print $9}’ | wc -l
‘’’

less nginx.log | awk ‘$9’|grep -E ‘404|500’

awk ‘{print$ 9}’ nginx.log |grep -E ‘404|500’ |wc -l

awk ‘$9~/404|500/{print $9}’ nginx.log |wc -l

awk ‘$9~/404|500/{t+=1}END{print t}’ nginx.log

awk ‘{if($9~/500$/ || $9~/404$/){print $0}}’ ./nginx.log

cat nginx.log | awk '$9 == 404 || $9 == 500'