• shell面试题


    面试题

    • 使用Linux命令查询file1中空行所在的行号

      [root@slave2 testshell]# awk '/^$/{print NR}' sed.txt 
      5
      [root@slave2 testshell]# cat sed.txt 
      dong shen
      guan zhen
      wo  wo
      lai  lai
      
      le  le
    • 有个文件chengji.txt内容如下:使用Linux命令计算第二列的和并输出
      张三 40
      李四 50
      王五 60

      [root@slave2 testshell]# cat chengji.txt | awk -F " " '{sum+=$2} END{print sum}'
      150
    • shell脚本里面如何检查一个文件是否存在?如果不存在该如何处理?
      [root@slave2 testshell]# if [ -e sed.txt ]
      > then
      > echo "文件存在"
      > else
      > echo "文件不存在"
      > fi
      文件存在
      [root@slave2 testshell]# if [ -e file.txt ]; then echo "文件存在"; else echo "文件不存在"; fi   
      文件不存在
    • 用shell写一个脚本,对文本中无序的一列数字排序
      [root@slave2 testshell]# vim test.txt 
      9
      8
      7
      6
      5
      4
      3
      2
      10
      1
      ~         
      "test.txt" 10L, 21C written                                                                                          
      [root@slave2 testshell]# sort -n test.txt
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      [root@slave2 testshell]# sort -n test.txt | awk '{sum+=$1} END {print "sum="sum}'
      sum=55
    • 请用shell脚本写出查找当前文件夹(/home)下所有的文本文件内容中包含有字符“shen”的文件名称
      [root@slave2 testshell]# grep -r "shen" /root/testshell
      /root/testshell/cut.txt:dong shen si
      /root/testshell/sed.txt:dong shen
      [root@slave2 testshell]# grep -r "shen" /root/testshell | cut -d : -f 1
      /root/testshell/cut.txt
      /root/testshell/sed.txt
  • 相关阅读:
    pip常用命令
    Conda环境管理
    关于自动化去掉验证码(收录)
    下载安装Eclipse---来自廖雪峰老师
    linux之top命令
    python——os模块
    Crypto
    Java_局部内部类
    Java_内部类
    Java_权限修饰符
  • 原文地址:https://www.cnblogs.com/zxbdboke/p/10421709.html
Copyright © 2020-2023  润新知