第十期_Shell 进阶_20190623

参考资料

管道

 ls ddd >/tmp/1 2>&1

三剑客Grep

  552  ps -ef | grep login
  553  ps -ef | grep "login -fp seveniruby"
  554  ps -ef | grep "login -fp seveniruby"
  555  ps -ef | grep "login -fp seveniruby"
  556  ps -ef | grep "login -fp seveniruby"
  557  ps -ef | grep "login -fp seveniruby"
  558  ps -ef | grep "0 .*seveniruby"
  559  ps -ef | grep "2253.*seveniruby"
  560  ps -ef | grep "2253.*seveniruby" | grep -v grep
  561  echo 1234
  562  echo 1234 | grep 2
  563  echo 1234 | grep 3
  564  echo 1234 | grep 4
  565  echo 1234 | grep -o 2
  566  echo 1234 | grep -o 3
  567  echo 1234 | grep -o 4
  568  echo 1234 | grep -o 5
  569  echo hello world
  570  ps -ef
  571  ps -ef  | grep seveniruby
  572  ps -ef  | grep seveniruby | grep "0 .*seveniruby""
  573  ps -ef  | grep seveniruby | grep "0 .*seveniruby"
  574  ps -ef  | grep seveniruby | grep "^ *0 .*seveniruby"
  575  echo hello world
  576  echo hello world | grep "hello|hi"
  577  echo hello world | grep -E "(hello)|(hi)"
  578  echo hello world | grep -E "hello|hi"
  579  echo 1234 | grep .
  580  echo 1234 | grep -o .
  581  echo 1234 | grep -o ..
  582  echo 1234 | grep -o ...
  583  echo 1234 | grep -o ...
  584  echo 1234 | grep -o '.*'
  585  echo 1234 | grep -oE '.*?'
  586  echo 1234 | grep -oE '..*?'
  587  echo 1234 | grep -oE '.*?'
  588  echo 1234 | grep -oE '.?'
  589  echo 1234 | grep -oE '.*?'
  590  echo 1234 | grep -oE '.*'
  591  echo 1234 | grep -oE '.*?'
  592  echo 1234 | grep -oE '..*?'
  593  echo 12341234
  594  echo 12341234 | grep -o '.*3'
  595  echo 12341234 | grep -oE '.*?3'
curl https://testerhome.com | grep '^ *<a title=".*".*topics' | grep -o '".*"'

awk

  612  awk 'BEGIN{print 1*10*2}'
  614  curl https://testerhome.com | awk  '/^ *<a title=".*".*topics/'
7,8,9' | awk -F, '{print $2}'
7,8,9' | awk -F, '{print $2}'
7,8,9' | awk -F, '{print $3}'
7,8,9' | awk -F, '{print $1}'
  625  ps | awk '{print $1}'
  626  ps | awk '{print $2}'
  627  ps | awk '{print $}'
  628  ps | awk '{print $3}'
  629  ps | awk '{print $4}'
  630  ps | awk "{print $4}"
  631  ps | awk "{print \\$4}"
  632  ps | awk '{print $1}'
  633  ps | awk '{print $NF}'
  634  ps | awk '{print $(NF-1)}'
  641  curl https://testerhome.com | awk  '/^ *<a title=".*".*topics/'
  643  curl https://testerhome.com | grep '^ *<a title=".*".*topics'  | awk -F '"' '{print $2}'
  644  ps | awk '{print $1}'
  645  ps | awk 'NR>1{print $1}'
7,8,9' | awk -F, '{print NF,NR,$0}'
  647  ps | awk 'NR>1{print $1}'
7,8,9' | awk -F, '{print NF,NR,$0}'
7,8,9' | awk -F, '{OFS="|"}{print NF,NR,$0}'
7,8,9' | awk -F, 'BEGIN{OFS="|"}{print NF,NR,$0}'
7,8,9' | awk -F, 'BEGIN{OFS="|"}{print NF,NR,$1,$2}'
  657  echo $PATH | awk 'BEGIN{RS=":"}{print $0}'
  658  echo $PATH | awk 'BEGIN{RS=":"}'
  659  echo $PATH | awk 'BEGIN{RS=":"}{print $0}'
  660  echo $PATH | awk 'BEGIN{RS=":"}{print $0}'  | grep -i java
  661  echo $PATH | awk 'BEGIN{RS=":"}{print $0}'
  662  echo $PATH | awk 'BEGIN{RS=":"}{print $0}'   | awk 'BEGIN{ORS=":"}{print $0}'
  663  echo $PATH | awk 'BEGIN{RS=":"}{print $0}'   | awk 'BEGIN{ORS=":"}{print $0}'
  664  echo $PATH | awk 'BEGIN{RS=":"}{print $0}'
  666  echo $PATH | awk 'BEGIN{RS=":"}'
  667  echo $PATH | awk 'BEGIN{RS=":";FS="/"}'
  668  echo $PATH | awk 'BEGIN{RS=":";FS="/"}{print $1}'
  669  echo $PATH | awk 'BEGIN{RS=":";FS="/"}{print $2}'
  677  echo $PATH | awk '{RS=":"}'
  678  echo $PATH | awk '{RS=":"}'
  679  echo $PATH | awk 'RS=":"'
  680  echo $PATH | awk 'BEGIN{RS=":"}{print $0}'
  695  echo $PATH | awk 'BEGIN{RS=":"}{print $0}'| grep -oE '/[^/]*$'
  697  echo $PATH | awk 'BEGIN{RS=":"}{print $0}'
  716  history | grep awk |less
  717  history | grep awk

sed

  672  echo 1,2,3 | sed "s#,2#,20#"
  673  echo 1,2,3 | sed "s#,#|#"
  674  echo 1,2,3 | sed "s#,#|#g"
  696  echo $PATH | awk 'BEGIN{RS=":"}{print $0}'| sed 's#/[^/]*$#xxxxxx#'
  701  echo $PATH | awk 'BEGIN{RS=":"}{print $0}'| sed -E 's#(/[^/]*$)#\\1/xxxxxx#'

Linux

Android

作业

课间作业1

把代码回复到帖子里,并注明 课间作业1

课间作业2

  • 从shell服务器上的/tmp/nginx.log中找出所有404 500的报错数据,并去除其中的url

课间作业3

  • 找出访问量最高的ip

课间作业4

  • 找出访问量最高的页面,/topics/1234 topics/4567 视为一个页面

课后作业

  • 提取 https://testing-studio.com/ 中的所有链接
  • 找出不能被访问的连接
  • 封装为函数,传入一个网站,自动检查这个网站上的链接