• shell 练习


    1. 求两个数的和

    #! /bin/bash
    
    read t1
    read t2
    
    echo $((t1+t2))

    2. 求1~100的和

     #!/bin/bash
       
     ans=0    
     count=100
     while [ $count -gt 0 ]; do     
      ans=$((count+ans))
      count=$(( count-1 ))
     done     
               
     echo $ans                                                                   

    3. 将一目录下所有的文件的扩展名改为bak

    #!/bin/bash
           
    POS=/home/huangqingxiang/q/
           
    for i in $(ls $POS); do
        echo $i
        mv $i $i.bak
      done          
    // 上面这个的工作目录必须和指定目录相等

     #!/bin/bash

     POS=/home/huangqingxiang/q/

     cd $POS
     for i in $(ls $POS);
     do
      echo $i
     mv $i $i.bak
     done

    // 下面这个的工作目录可以和指定目录不相等

    4.  编译当前目录下的所有.c文件   编译后 .c 后缀将去掉

     #!i/bin/bash                         
                                           
      for NAME in $(ls *.c) ;              
      do                                   
          echo $NAME                       
          gcc $NAME -o -pthread  ${NAME%.c}                                                                                                                                                                  
       done                                 

    5. 打印root可以使用可执行文件数,处理结果: root's bins: 2306

    echo "root's bins: $(find ./ -type f | xargs ls -l | sed '/-..x/p' | wc -l)"

    p是打印的功能,之所以没有打印是因为管道的原因?是的

    6.打印当前sshd的端口和进程id,处理结果: sshd Port&&pid: 22 5412

  • 相关阅读:
    git 常用命令
    centos 7 mini 安装
    python打印杨辉三角
    python 求100内的素数/质数
    字符串与bytes
    format
    Python字符串格式化
    数据结构
    ARM工作模式
    C语言实现字符串逆序输出
  • 原文地址:https://www.cnblogs.com/letlifestop/p/11381201.html
Copyright © 2020-2023  润新知