Linux第三周
Posted JINX穆空
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux第三周相关的知识,希望对你有一定的参考价值。
1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来
[root@localhost ~]# grep -v /sbin/nologin /etc/passwd | cut -d: -f1 &&\\
> grep -v /sbin/nologin /etc/passwd | wc -l
root
sync
shutdown
halt
mageia
slackware
user1
user2
user3
9
2、查出用户UID最大值的用户名、UID及shell类型
[root@localhost ~]# cat /etc/passwd | sort -t: -k3 -n | tail -1 | cut -d: -f1,3,7
nobody:65534:/sbin/nologin
3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
[root@localhost ~]# netstat -t | grep :ssh|tr -s |cut -d -f5|cut -d: -f1 | uniq -c|sort -rn
2 192.168.17.1
4、编写脚本disk.sh,显示当前硬盘分区中空间利用率最大的值
[root@localhost ~]# touch disk.sh
[root@localhost ~]# vim disk.sh
df | tr -s " " | cut -d" " -f5 | grep -o [0-9]* | sort -rn|head -1
[root@localhost ~]# sh disk.sh
28
5、编写脚本 systeminfo.sh,显示当前主机系统信息,包括:主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小
[root@localhost ~]# vim systeminfo.sh
echo "This is your sysinfo"
echo "hostname:`hostname`"
echo "ip:`ifconfig | head -n2 |grep -o -E [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}|head -n1`"
echo "OS version:`cat /etc/redhat-release`"
echo "kernel-release:`uname -r`"
echo "`lscpu | sed -n 14p|tr -s `"
echo "`cat /proc/meminfo |sed -n 1p|tr -s `"
echo "desk space:`lsblk |grep "^sda" |tr -s |cut -d -f4`"
[root@localhost ~]# sh systeminfo.sh
This is your sysinfo
hostname:localhost.localdomain
ip:192.168.17.128
OS version:CentOS Linux release 8.5.2111
kernel-release:4.18.0-348.2.1.el8_5.x86_64
型号名称: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
MemTotal: 7927628 kB
desk space:200G
6、20分钟内通关vimtutor(可参考https://yyqing.me/post/2017/2017-02-22-vimtutor-chinese-summary)
以上是关于Linux第三周的主要内容,如果未能解决你的问题,请参考以下文章