shell综合习题
1.按照时间生成文件`2018-05-22.log`将每天的磁盘使用状态写入到对应日期的文件
[root@manager ~]# crontab -l
0 0 * * * df -h >(date +%F)_file
2.统计Nginx日志中每个IP的访问量有多少,日志如下:
`192.168.56.1 - - [21/May/2018:20:44:06 -0400] "GET /index.html HTTP/1.0" 404 169 "-" "ApacheBench/2.3" "-"/code/index.html`
cat /var/log/message |awk '{print $1}' |sort -nr |uniq -c
3.写一个脚本计算一下Linux系统所有进程占用内存大小的和。
[root@manager zhoumo]# cat var3.sh
#!/bin/bash
#********************************************************************
#Author: 一个shell小白
#QQ: 2226823216
#Date: 2019-11-01
#FileName: var3.sh
Num=$(ps aux |awk '{print $6}'|grep -v "RSS")
sum=0
for i in $Num
do
sum=$(( $sum + $i ))
done
echo "总的值是:$sum"
echo "以M为单位是:$(( $sum /1024 ))M "
4.在/backup下创建10个.txt的文件,找到/backup目录下所有后缀名为.txt的文件
1.批量修改txt为txt.bak
2.把所有的.bak文件打包压缩为123.tar.gz
3.批量还原文件的名字,及把增加的.bak再删除
[root@manager ~]# mkdir /backup
[root@manager ~]# cd /backup/
[root@manager backup]# touch file{1..10}.txt
[root@manager backup]# find /backup/ -type f -name "*.txt"
[root@manager zhoumo]# cat var4.sh
#!/bin/bash
#********************************************************************
#Author: 一个shell小白
#QQ: 2226823216
#Date: 2019-11-02
#FileName: var4.sh
#修改名称
dy_file=$(find /backup/ -type f -name "*.txt")
for i in $dy_file
do
mv $i ${i}.bak
sleep 2
echo "修改名称成功..."
done
#压缩
tar czf /backup/123.tar.gz $(find /backup -type f -name "*.bak")
sleep 1
echo "打包成功..."
#还原文件名,删除.bak
dy_fil=$(find /backup/ -type f -name "*.bak")
for i in $dy_fil
do
mv $i ${i%.*}.txt
done
echo "还原成功..."
5.把一个文本文档的前五行中包含字母的行删除掉,同时把6到10行中的全部字母删除掉
7.写个shell,看看你的linux系统中是否有自定义用户(普通用户),若是有,一共有几个?
1、查看、etc/passwd
2、提取uid和/bin/bash
3、判断UID大于1000且shell为/bin/bash
4、成功需要计数
[root@manager zhoumo]# cat var7.sh
#!/bin/bash
#********************************************************************
#Author: 一个shell小白
#QQ: 2226823216
#Date: 2019-11-02
#FileName: var7.sh
i=0
while read line
do
User_uid=$(echo $line |awk -F ":" '{print $3}')
User_shell=$(echo $line |awk -F ":" '{print $NF}')
if [ $User_uid -ge 1000 -a $User_shell == "/bin/bash" ];then
let i++
fi
echo $User_uid $User_shell
done </etc/passwd
echo "总共有$i 个普通用户"
8.写一个shell脚本来看看你使用最多的命令是哪些,列出你最常用的命令top10
[root@manager zhoumo]# history |awk '{print $2}' |sort |uniq -c |sort -nr |head
9.中企动力面试题
用shell处理以下内容
1、按单词出现频率降序排序!
2、按字母出现频率降序排序!
the squid project provides a number of resources toassist users design,implement and support squid installations. Please browsethe documentation and support sections for more infomation
[root@manager zhoumo]# echo "the squid project provides a number of resources toassist users design,implement and support squid installations. Please browsethe documentation and support sections for more infomation" |sed 's#[.,]# #' |xargs -n1 |sort |uniq -c |sort -nr
[root@manager zhoumo]# echo "the squid project provides a number of resources toassist users design,implement and support squid installations. Please browsethe documentation and support sections for more infomation" |sed 's#[.,]# #' |grep -o '[a-Z]' |sort |uniq -c |sort -nr
10.写一个脚本,实现判断10.0.0.0/24网络里,当前在线用户的IP有哪些
[root@manager zhoumo]# cat var10.sh
#!/bin/bash
#********************************************************************
#Author: 一个shell小白
#QQ: 2226823216
#Date: 2019-11-02
#FileName: var10.sh
>ip.txt
for i in {1..254}
do
{
ip=10.0.0.$i
ping -W1 -c1 $ip &>/dev/null
if [ $? -eq 0 ];then
echo "$ip is ok" >>ip.txt
fi
} &
done
wait && cat ip.txt
技术是没有终点的,也是学不完的,最重要的是活着、不秃。 学习看书还是看视频,都不重要,重要的是学会,欢迎关注,我们的目标---不秃。
---更多运维开发交流及软件包免费获取请加V: Linuxlaowang
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义