考试总结 3.30

1.用什么命令显示当前目录?
echo ${pwd}

2.将当前目录下的myftp.tar.gz解压到/tmp下?

tar xvzfmyftp.tar.gz –C /tmp

关于tar每列的补充:

-C 解压到指定目录

-c 建立新的存档

-A与已有的存档合并

-d比较存档与当前文档的不同之处

-r附加到存档结尾

-f指定存档或设备

-w每个操作都要求确认

扫描二维码关注公众号,回复: 1532900 查看本文章

-W写入存档后进行校验
3.>>>print “%.2f”%3.1415926

 >>>3.14

 >>>print “%0.2f”%3.1415926

 >>>3.14

 >>>print “%8.2f”%3.1415926

 >>>   3.14(4个空格)

 >>>print “%08.2f”%3.1415926

 >>>00003.14

4.查看文件file1的第300-500行

  cat file1 | tail –n +300| head –n 200

  cat file1 | head –n 500 | tail –n +300

  sed –n ‘300,500p’file1

 tail –n +300 从第300行开始显示到最后一行

  head –n 200显示前200

5.awk ‘BEGIN {Arr[2,79]=78;________}’打印出78应补充:

  print Arr[“2\03479”]

  print Arr[2,79]

 idx=2 SUBSEP 79;print Arr[idx]

  print Arr[2, 79]

awk数组字符串为索引。SUBSEP为数组下标的分隔符,预设值为“\034”,awk中的数组只接受字符串作为下标,故将下标转换成字符串“2\03479”,之后以Arr[“2\03479”]代替Arr[2,79]

6.脚本题

 判断cpu的生产商

 #!/bin/bash

 name=`grep “^vendor_id” /proc/cpuinfo | cut –d“ ” –f 2`

 if [ ${name} = “AuthenticAMD” ];then

   echo “AMD”

elif [ ${name} = “GenuineIntel”];then

   echo “Intel”

 else

  echo “other”

fi

猜你喜欢

转载自blog.csdn.net/weixin_41661222/article/details/79817465