天天看點

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`"