1、复制/etc/profile至/tmp/目录,用查找替换命令删除/tmp/profile文件中的 行首的空白字符
#cp /etc/profile /tmp
#vi /tmp/profile
:%s/^[[:space:]]\+/
2、在vim中设置tab缩进为4个字符
临时生效:用vim打开一个文件,在扩展的命令行模式里,输入:set ts=4;
永久生效:写set tabstop=4进/root/.vimrc配置文件里
3、20分钟内通关vimtutor(可参考https://yyqing.me/post/2017/2017-02-22-vimtutor-chinese-summary)
4、编写脚本 createuser.sh,实现如下功能:使用一个用户名做为参数,如果 指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等信息
[root@centos7-test data]#cat createuser.sh
#!/bin/bash
#
#**********************************************************************************************
#Author: mahui
#Date: 2021-06-18
#FileName: createuser.sh
#Copyright (C):2021 All rights reserved
#*********************************************************************************************
[ $# -lt 1 ] && echo "input username !" && exit
id $1 &> /dev/null
if [ $? -eq 1 ];then
useradd $1 ;echo -e "successful\n`id $1`"
else echo "user already exists"
fi
[root@centos7-test data]#bash createuser.sh
input username !
[root@centos7-test data]#bash createuser.sh mahui
user already exists
[root@centos7-test data]#bash createuser.sh mage
successful
uid=1002(mage) gid=1003(mage) groups=1003(mage)
5、编写脚本 systeminfo.sh,显示当前主机系统信息,包括:主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小
#!/bin/bash
#
#**********************************************************************************************
#Author: mahui
#Date: 2021-06-18
#FileName: systeminfo.sh
#Copyright (C):2021 All rights reserved
#*********************************************************************************************
echo hostname=`hostname`
echo OS=`cat /etc/redhat-release`
echo kenel=`uname -r`
echo IP=`hostname -I`
echo CPU=`lscpu|grep name|cut -d ":" -f 2`
echo Memory Size=`free -m |grep Mem |tr -s ' '|cut -d ' ' -f2`
echo Disk Size=`lsblk |sed -rn '2p'|tr -s ' '|cut -d ' ' -f4`
运行结果:
[root@centos7-test data]#./systeminfo.sh
hostname=centos7-test
OS=CentOS Linux release 7.6.1810 (Core)
kenel=3.10.0-957.el7.x86_64
IP=10.0.0.201 192.168.122.1
CPU= Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
Memory Size=1819
Disk Size=200G
6、编写脚本disk.sh,显示当前硬盘分区中空间利用率最大的值
#!/bin/bash
#
#**********************************************************************************************
#Author: mahui
#Date: 2021-06-18
#FileName: dish.sh
#Copyright (C):2021 All rights reserved
#*********************************************************************************************
DiskSpace=`df |grep /dev/sd|tr -s ' ' '%'|cut -d '%' -f5|sort -rn|head -1`
echo -e "\033[1;34mmax disk space is $DiskSpace%\033[0m"
运行结果
[root@centos7-test data]#./dish.sh
max disk space is 18%