当前位置:网站首页>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
边栏推荐
- C#/VB.NET 将PPT或PPTX转换为图像
- 2022年中盘点 | 产品打底,科技背书,广汽集团阔步向前
- 【软件架构模式】MVVM模式和MVC模式区别
- 我是如何保护 70000 ETH 并赢得 600 万漏洞赏金的
- WPF 截图控件之绘制箭头(五)「仿微信」
- CTFshow,命令执行:web31
- Naive Bayes--Study Notes--Basic Principles and Code Implementation
- gc的意义和触发条件
- For small applications, which database is better to use?
- STM32 Personal Notes - Watchdog
猜你喜欢
随机推荐
notes....
从零开始Blazor Server(4)--登录系统
基于CAP组件实现补偿事务与消息幂等性
ClickHouse多种安装方式
xss-labs靶场挑战
Browser shortcut keys
The first experience of Shengsi large model experience platform——Take the small model LeNet as an example
线上问题排查常用命令,总结太全了,建议收藏!!
Google Earth Engine APP——15行代码搞定一个inspector高程监测APP
notes....
July 31, 2022 -- Take your first steps with C# -- Use C# to create readable code with conventions, spaces, and comments
Dataset之mpg:mpg数据集的简介、下载、使用方法之详细攻略
DBPack SQL Tracing 功能及数据加密功能详解
rpm and yum
C language game - minesweeper
Mysql索引相关的知识复盘一
Android Security and Protection Policy
Mysql index related knowledge review one
How to find out hidden computer software (how to clean up the computer software hidden)
Introduction to data warehouse layering (real-time data warehouse architecture)









