当前位置:网站首页>shell--面试题
shell--面试题
2022-08-01 10:14:00 【weixin_51808099】
12.1 京东
问题1:使用Linux命令查询file1中空行所在的行号。
[[email protected] zuoye]# awk '/^$/ {print NR}' file
问题2:有文件chengji.txt内容如下’’
张三 40
李四 50
王五 60
使用Linux命令计算第二列的和并输出
[[email protected] zuoye]# awk '{num+=$2} END{print num}' chengji.txt
12.2 搜狐&和讯网
问题1:Shell脚本里如何检查一个文件是否存在?如果不存在该如何处理?
[[email protected] zuoye]# vim 12.2.sh
#!/bin/bash
read -p "plase input you want find file path: " path
find $path &>/dev/null
if [ $? -eq 0 ];then
echo "this file extis"
else
echo "this file not extis "
fi
12.3 新浪
问题1:用shell写一个脚本,对文本中无序的一列数字排序
[[email protected] zuoye]# vim 12.3.sh
#!/bin/bash
sort -n 12.3.txt
12.4 金和网络
问题1:请用shell脚本写出查找当前文件夹(/home)下所有的文本文件内容中包含有字符”shen”的文件
名称
[[email protected] zuoye]# grep sh -R /home |awk -F: '{print $1}'|uniq
12.5 小米
问题1:
一个文本文件info.txt的内容如下:
aa,201
zz,502
bb,1
ee,42
每行都是按照逗号分隔,其中第二列都是数字,请对该文件按照第二列数字从大到小排列。
[[email protected] zuoye]# awk -F, '{print $2}' info.txt |sort -nr
12.6 美团
问题1:编写脚本实现以下功能;
每天早上5点开始做备份
要备份的是/var/mylog里所有文件和目录可以压缩进行备份
备份可以保存到别一台器上192.168.1.2 FTP帐号 aaa 密码 bbb
要求每天的备份文件要带有当天的日期标记
问题2:请用shell脚本创建一个组class、一组用户,用户名为stdX,X从01-30,并归属class组
[[email protected] zuoye]# vim 12.6.2.sh
#!/bin/bash
groupadd class
for i in `seq 11`
do
if [ $i -lt 10 ];then
useradd std0$i -g class &>/dev/null
else
useradd std$i -g class
fi
done
12.7 百度
处理以下文件内容,将域名取出并进行计数排序,如处理:
http://www.baidu.com/more/
http://www.baidu.com/guding/more.html
http://www.baidu.com/events/20060105/photomore.html
http://hi.baidu.com/browse/
http://www.sina.com.cn/head/www20021123am.shtml
http://www.sina.com.cn/head/www20041223am.shtml
[[email protected] zuoye]# awk -F/ '{print $3}' www.txt |uniq -c
12.8 奇虎360
1、写一个脚本查找最后创建时间是3天前,后缀是*.log的文件并删除。
[[email protected] zuoye]# vim 12.8.sh
#!/bin/bash
for i in ` find / -mtime +3 -name *.log`
do
rm -f $i
done
~
2、写一个脚本将某目录下大于100k的文件移动至/tmp下。
[[email protected] zuoye]# find /root/zuoye/ -size +10k -exec cp -a {
} /tmp/ \;
3、写一个脚本进行nginx日志统计,得到访问ip最多的前10个(nginx日志路径:/home/logs/nginx/default/access.log
4、写一个脚本把指定文件里的/usr/local替换为别的目录。
[[email protected] zuoye]# sed -i 's#/usr/local#/sy#g' www.txt
12.9 滴滴出行
1、指令:ls | grep “[ad]*.conf” 命令解释正确的是:
正确答案: A
A 显示包含a 或者d 为开头,后接任何字符,再后面是.conf字符的文件(或目录)
B 显示包含a 或者d 出现0 次或无数次,后面是.conf字符的文件(或目录)
C 显示包含字母a 或者d出现0次或1次,后面是.conf字符的文件(或目录)
D 显示从字母a 到d ,后接任何字符,再后面是.conf字符的文件(或目录)
2、找出IO重定向执行结果与其他三个不同的:
正确答案: C
A ./run.sh >run.log 2>&1;
B ./run.sh 2>&1 >run.log;
C ./run.sh &>run.log;
D ./run.sh 2>run.log >&2
3、一个文件,大概1亿行,每行一个ip,将出现次数最多的top10输出到一个新的文件中
[[email protected] zuoye]# sort host_down.txt |uniq -c|sort -r |head -10
边栏推荐
- Google Earth Engine——给影像添加一个属性对于单景的时间序列并返回影像
- July 31, 2022 -- Take your first steps with C# -- Use arrays and foreach statements in C# to store and iterate through sequences of data
- 2022年7月31日--使用C#迈出第一步--使用 C# 创建具有约定、空格和注释的易读代码
- Mysql索引相关的知识复盘一
- Qt 支持HEIC/HEIF格式图片
- notes....
- MFC实现交通图导航系统
- slice、splice、split傻傻分不清
- C语言小游戏——扫雷
- 回归预测 | MATLAB实现TPA-LSTM(时间注意力注意力机制长短期记忆神经网络)多输入单输出
猜你喜欢
随机推荐
跨域网络资源文件下载
Dataset之mpg:mpg数据集的简介、下载、使用方法之详细攻略
Basic configuration commands of cisco switches (what is the save command of Huawei switches)
2022年7月31日--使用C#迈出第一步--使用C#中的数组和foreach语句来存储和循环访问数据序列
Mini Program Graduation Works WeChat Food Recipes Mini Program Graduation Design Finished Products (4) Opening Report
Golang内存分析工具gctrace和pprof实战
retired paddling
mysql在cmd的登录及数据库与表的基本操作
July 31, 2022 -- Take your first steps with C# -- Use arrays and foreach statements in C# to store and iterate through sequences of data
CTFshow,命令执行:web34、35、36
Mysql index related knowledge review one
Shell: Conditional test action
C#/VB.NET 将PPT或PPTX转换为图像
SQL Server database schema and objects related knowledge notes
Qt supports HEIC/HEIF format images
The meaning and trigger conditions of gc
[Cloud Residency Co-Creation] Huawei Cloud Global Scheduling Technology and Practice of Distributed Technology
Android Security and Protection Policy
回归预测 | MATLAB实现TPA-LSTM(时间注意力注意力机制长短期记忆神经网络)多输入单输出
C#/VB.NET 将PPT或PPTX转换为图像









