1. 程式人生 > 其它 >linux學習(3)

linux學習(3)

------------恢復內容開始------------

Q1:統計出/etc/passwd檔案中其預設shell為非/sbin/nologin的使用者個數,並將使用者都顯示出來

A1:[root@Centos7 ~]# cat /etc/passwd | grep -v /sbin/nologin | wc -l

  10

  [root@Centos7 ~]# cat /etc/passwd | grep -v /sbin/nologin | cut -d: -f1

  root

  sync

  shutdown

  halt

  ...(使用者名稱省略)

  mageia

  slackware

  user1

  user2

  user3

Q2:查出使用者UID最大值的使用者名稱、UID及shell型別

A2:[root@Centos7 ~]# cat /etc/passwd | cut -d: f1,3,7 | sort -t: -k2 -n | tail -nl

  nfsnobody:65534:/sbin/nologin

Q3:統計當前連線本機的每個遠端主機IP的連線數,並按從大到小排序

A3:[root@Centos7 ~]# w -h | tr -s "" |cut -d" " -f 3 | uniq -c | sort -nr

  1

Q4:編寫指令碼disk.sh,顯示當前硬碟分割槽中空間利用率最大的值

A4:#!/bin/bash

  df -h |grep "^/dev"|tr -s " " %|cut -d % -f5|sort -nr|head -1

Q5:編寫指令碼 systeminfo.sh,顯示當前主機系統資訊,包括:主機名,IPv4地址,作業系統版本,核心版本,CPU型號,記憶體大小,硬碟大小

A5:#!/bin/bash

  RANDOM_COLOR="echo -e \e[$[RANDOM%7+31]m"
  GREEN="echo -e \e[32m"
  END="\e[0m"
  $GREEN************************ Host systeminfo ********************$END
  $RANDOM_COLOR"HOSTNAME: `hostname`"$END
  $RANDOM_COLOR"IPADDR: `ifconfig eth0|grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}'|head -n1`"$END
  $RANDOM_COLOR"OS: `cat /etc/redhat-release`"$END
  $RANDOM_COLOR"KERNEL: `uname -r`"$END
  $RANDOM_COLOR"CPU: `lscpu|grep 'Model name'|tr -s ' '|cut -d : -f2`"$END
  $RANDOM_COLOR"MEMORY: `free -h|grep 'Mem'|tr -s ' ' :|cut -d : -f2`"$END
  $RANDOM_COLOR"DISK: `lsblk|grep '^sd'|tr -s ' '|cut -d ' ' -f4`"$END
  $GREEN*************************************************************$END

Q6:20分鐘內通關vimtutor

A6:無(上班時間太忙,以後補回)

------------恢復內容結束------------