当前位置:网站首页>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
边栏推荐
- Introduction and application of heap memory (including examples)
- 机器学习 | MATLAB实现支持向量机回归RegressionSVM参数设定
- 【cartographer ros】10: Delay and error analysis
- redis
- AI篮球裁判火了,走步算得特别准,就问哈登慌不慌
- MacOS下postgresql(pgsql)数据库密码为什么不需要填写或可以乱填写
- [Software Architecture Mode] The difference between MVVM mode and MVC mode
- Custom Types - Enums, Unions
- 招聘随想2022
- Google Earth Engine APP——15行代码搞定一个inspector高程监测APP
猜你喜欢

WTM:ASP.NET Core快速开发利器!

基于CAP组件实现补偿事务与消息幂等性

Mysql index related knowledge review one

redis

C语言小游戏——扫雷

Visualization - Superset installation and deployment

mysql在cmd的登录及数据库与表的基本操作

VS“无法查找或打开PDB文件”是怎么回事?如何解决

Google Earth Engine APP——15行代码搞定一个inspector高程监测APP

Enterprise WeChat group: robot timing reminder function database configuration
随机推荐
Drawing arrows of WPF screenshot control (5) "Imitation WeChat"
[Cloud Residency Co-Creation] Huawei Cloud Global Scheduling Technology and Practice of Distributed Technology
Small application project works WeChat gourmet recipes applet graduation design of finished product (1) the development profile
rpm and yum
Mini Program Graduation Works WeChat Food Recipes Mini Program Graduation Design Finished Products (2) Mini Program Functions
notes....
开天aPaaS之移动手机号码空号检测【开天aPaaS大作战】
STM32 Personal Notes - Embedded C Language Optimization
机器学习 | MATLAB实现支持向量机回归RegressionSVM参数设定
SAP ABAP OData 服务如何支持 $orderby (排序)操作试读版
分类预测 | MATLAB实现1-DCNN一维卷积神经网络分类预测
2022年7月31日--使用C#迈出第一步--使用 C# 创建具有约定、空格和注释的易读代码
C语言小游戏——扫雷
How to Steal $100 Million from the Perfect Smart Contract
Introduction and application of pointers
阿里腾讯面试一二
广域铭岛入选2022年重庆市数字经济产业发展试点示范项目名单
Taobao commodity details and details on taobao, senior upgrade version of the API
CTFshow,命令执行:web33
浏览器快捷键大全