天天看点

Linux学习 03

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

          cp /etc/profile /tmp

          vim /tmp/profile

Linux学习 03

2、  cd; vim  .vimrc

         set tb=4

       source .vimrc

3、编写脚本 createuser.sh,实现如下功能:使用一个用户名做为参数,如果 指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等信息

       #!/bin/bash

         grep '$1' /etc/passwd > /dev/null

         if [ $? -eq 0 ];then

               echo "user exsit"

         else

               useradd $1

               echo `id $1`

         fi

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

 #!/bin/bash

echo "**********Systeminfo***********"

echo "hostname: `hostname`"

echo "OS Version: `cat /etc/redhat-release`"

echo "Kernel Version: `uname -r`"

echo "CPU name: `lscpu | grep '^Model name' | tr -s ' ' | cut -d: -f2`"

echo "Memory: `free -h | grep 'Mem' | tr -s ' ' | cut -d: -f2` "

echo "Disk: `lsblk | grep '^sda\>' | tr -s ' ' '%' | cut -d% -f4`"