Linux文本处理和shell脚本基础
2022/1/10 7:05:14
本文主要是介绍Linux文本处理和shell脚本基础,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来
答:cut -d: --complement -f1,3-5 /etc/passwd | grep -v /sbin/nologin
2、查出用户UID最大值的用户名、UID及shell类型
答:cut -d: -f1,3,7 /etc/passwd |sort -t: -k2 -nr
3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
4、编写脚本disk.sh,显示当前硬盘分区中空间利用率最大的值
答1:df | tr -s " " | cut -d " " -f5 | sort -nr | head -n 1
答2: 1 #!/bin/bash
2
3 echo -e "Dish_Max_USED=`df | tr -s " " | cut -d" " -f5 | sort -nr | head -n 1`"
5、编写脚本 systeminfo.sh,显示当前主机系统信息,包括:主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小
答: 1 #!/bin/bash$
2 $
3 echo -e "My hostname is `hostname`"$
4 echo -e "IP address is `ifconfig ens160 |grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}'|head -n1`"$
5 echo -e "OS version is `cat /etc/os-release`"$
6 echo -e "Kernel version is `uname -r`"$
7 echo -e "CPU type is `lscpu|grep "Model name" |cut -d: -f2 |tr -s " "`"$
8 echo -e "Memtotol is `cat /proc/meminfo |head -n1 |grep -Eo '[0-9]+.*'`"$
9 echo -e "Disk space is `lsblk |grep 'sda\>'|grep -Eo '[0-9]+[[:upper:]]'`"$
6、20分钟内通关vimtutor(可参考https://yyqing.me/post/2017/2017-02-22-vimtutor-chi答答nese-summary)
这篇关于Linux文本处理和shell脚本基础的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-03-30[译]漫画SELinux概念
- 2024-03-29linux 移动文件
- 2024-03-28linux .so file
- 2024-03-28Linux 磁盘管理
- 2024-03-28Linux学习笔记(十三)磁盘管理(一):磁盘分区
- 2024-03-26linux 创建 文件
- 2024-03-25使用SecureCRT对Linux vim进行颜色设置
- 2024-03-202019-2020-12 20199317 《Linux内核原理与分析》 第十二周作业
- 2024-03-20Linux运维的第二周总结
- 2024-03-13how to count number of directories in linux