• shell 案例


    1、复制/etc/profile至/tmp/目录,用查找替换命令删除/tmp/profile文件中的 行首的空白字符

    cp /etc/profile  /tmp/

    :%s/^ +//g

    2、在vim中设置tab缩进为4个字符

    进入扩展模式 : :set tabstop=4

    3、20分钟内通关vimtutor(可参考https://yyqing.me/post/2017/2017-02-22-vimtutor-chinese-summary)
    4、编写脚本 createuser.sh,实现如下功能:使用一个用户名做为参数,如果 指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等信息

    #!/bin/bash
    cat /etc/passwd|cut -d: -f1|grep $1 &> /dev/null
    if [ $? -eq 0 ];then
    echo "$1 exist"
    else
    useradd $1
    fi


    5、编写脚本 systeminfo.sh,显示当前主机系统信息,包括:主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小

    #!/bin/bash
    echo '主机系统信息,包括:主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小'
    host_name=`hostname`
    IPV4=`ifconfig eth0|grep -o '([0-9]{1,3}.){3}[0-9]{1,3}'|head -n1`
    OS=`cat /etc/redhat-release`
    neihe=`uname -r`
    CPU=`cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c`
    neicun=`free -g|grep 'Mem'|tr -s ' ' ':'|cut -d: -f2`
    disk=`df -h|tr -s ' ' ':'|cut -d ':' -f 1,2`
    echo "####################################"
    echo "主机名:$host_name"
    echo "IPV4地址:$IPV4"
    echo "操作系统版本:$OS"
    echo "内核版本:$neihe"
    echo "CPU型号:$CPU"
    echo "内存大小:$neicun"
    echo "硬盘大小:$disk"
    echo "####################################"


    6、编写脚本disk.sh,显示当前硬盘分区中空间利用率最大的值

    #!/bin/bash
    disk=`df -h|grep "^/dev"|tr -s " " ':'|sort -nr -t: -k5|tail -1|cut -d: -f5`
    echo "$disk"

  • 相关阅读:
    C++---继承和派生
    【解迷糊】关于PHP的extract()函数提取出的变量的作用域问题
    PHP常用内置函数记忆(持更)
    PHP数据类型转换
    在window把自己的项目上传到github
    github Desktop上传项目
    【终于明白】PHP加入命名空间的好处--方便自动加载
    PHP中session的使用方法和生命周期问题
    php
    PHP中include和require的区别详解
  • 原文地址:https://www.cnblogs.com/yangxiuhong/p/14942378.html
Copyright © 2020-2023  润新知