阅读 168

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"

原文:https://www.cnblogs.com/yangxiuhong/p/14942378.html

文章分类
代码人生
文章标签
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐