linux基础-vim、grep、shell基础
1、复制/etc/profile至/tmp/目录,用查找替换命令删除/tmp/profile文件中的行首的空白字符
cp /etc/profile /tmp/
sed -ri.bak 's/^[ ]+(.)/\1/' /etc/profile && cat /etc/profile
2.在vim中设置tab缩进为4个字符
set tabstop=# 指定#个空格代替Tab
3.vimtutor;进入vim指导教程
4、编写脚本 createuser.sh,实现如下功能:使用一个用户名做为参数,如果 指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等信息
#!/bin/bash
[ $# -eq 0 ] && { echo 'creatuser must need one username at the least!';exit 1; }
for usr_in in $@;do
id $usr_in &> /dev/null
usr_ex=$?
[ $usr_ex -eq 0 ] && id $usr_in || { useradd $usr_in;echo "$usr_in is created"; }
done
5、编写脚本 systeminfo.sh,显示当前主机系统信息,包括:主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小
6、编写脚本disk.sh,显示当前硬盘分区中空间利用率最大的值
#!/bin/bash
df|grep ^\/dev\/ |awk -F ' +|%' '{print $5,$1}'|sort -rn|head -1|while read use dev;do
echo "$dev has the bigges usage, is $use"
done

浙公网安备 33010602011771号