当前位置:网站首页>shell企业面试题练习
shell企业面试题练习
2022-07-27 06:50:00 【空丶白灬】
问题1:使用Linux命令查询file1中空行所在的行号
#!/bin/bash
awk '/^$/ {print NR}' file1
问题2:有文件chengji.txt内容如下’’
张三 40
李四 50
王五 60
使用Linux命令计算第二列的和并输出。
#!/bin/bash
awk '{sum+=$2} END {print sum}' chengji.txt
问题3:Shell脚本里如何检查一个文件是否存在?如果不存在该如何处理?
#!/bin/bash
if [ -f file1 ];then
echo exist
else
echo not exist
fi
问题4:用shell写一个脚本,对文本中无序的一列数字排序
#!/bin/bash
sort -k 2 -nr chengji.txt
问题5:请用shell脚本写出查找当前文件夹(/home)下所有的文本文件内容中包含有字符”shen”的文件名称
#1/bin/bash
ls -l /home |grep -r "shen"| awk -F: '{print $1}'
问题6:
一个文本文件info.txt的内容如下:
aa,201
zz,502
bb,1
ee,42
每行都是按照逗号分隔,其中第二列都是数字,请对该文件按照第二列数字从大到小排列。
#!/bin/bash
sort -t',' -k 2 -nr info.txt
问题7:编写脚本实现以下功能;
每天早上5点开始做备份
要备份的是/var/mylog里所有文件和目录可以压缩进行备份
备份可以保存到别一台器上192.168.1.2 FTP帐号 aaa 密码 bbb
要求每天的备份文件要带有当天的日期标记
#!/bin/bash
date=`date +%F`
tar -zvcf backup-{
$date}.bak /var/mylog/
if [ -f backup-{
$date}.bak ];then
echo success
ftp -i -n 192.168.1.2 <<- eof
user aaa bbb
put backup-{
$date}.bak
bye
eof
else
echo failed
fi
vim /etc/crontab
* 5 * * * /bin/bash /shell/d4/7.sh
问题8:请用shell脚本创建一个组class、一组用户,用户名为stdX,X从01-30,并归属class组
#!/bin/bash
groupadd class
for i in {
1..30}
do
if [ $i -le 10 ];then
useradd std0$i -g class
else
useradd std$i -g class
fi
done
问题9:## 处理以下文件内容,将域名取出并进行计数排序,如处理:
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
#!/bin/bash
awk -F/ '{print $3}' a.txt| sort | uniq -c |sort -n
问题10、写一个脚本查找最后创建时间是3天前,后缀是*.log的文件并删除。**
#!/bin/bash
find / -name "*.log" -ctime +3 | xargs rm -f
问题11、写一个脚本将某目录下大于100k的文件移动至/tmp下。
#!/bin/bash
for i in `find /shell -type f -size +100k`
do
cd /shell && mv $i /tmp
done
问题12、写一个脚本进行nginx日志统计,得到访问ip最多的前10个(nginx日志路
径:/home/logs/nginx/default/access.log
#!/bin/bash
awk '{print $1}' /home/logs/nginx/default/access.log | sort | uniq -c | sort -nr | head -n 10
问题13、写一个脚本把指定文件里的/usr/local替换为别的目录。
#!/bin/bash
sed 's#/usr/local#/usr#g' test.txt
问题14、指令:ls | grep “[ad]*.conf” 命令解释正确的是:
显示包含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输出到一个新的文件中
sort file | uniq -c | sort -nr | head -n 10 >> file2
边栏推荐
- 单臂路由(讲解+实验)
- Use shell to calculate the sum of numbers in text
- Okaleido tiger is about to log in to binance NFT in the second round, which has aroused heated discussion in the community
- 在mac中使用docker来搭建oracle数据库服务器
- 2022 0726 Gu Yujia's study notes
- Chapter 6 Shell Logic and Arithmetic
- ARP broadcasting practice cases
- The solution of using sqlplus to display Chinese as garbled code
- Tableau prep is connected to maxcompute and only writes simple SQL. Why is this error reported?
- 杂谈:最近好多朋友谈出国……
猜你喜欢

Understanding and learning of node flow and processing flow in io

flink1.14 sql基础语法(一) flink sql表查询详解

Understanding and learning of properties class and properties configuration file

Properties类和properties配置文件的理解学习

Codeforces Round #810 (Div.2) A-C

ARP broadcasting practice cases

在mac中使用docker来搭建oracle数据库服务器

Prior Attention Enhanced Convolutional Neural Network Based Automatic Segmentation of Organs at Risk

帮忙发一份招聘,base全国,有兴趣的可以过来看看

Chapter 6 Shell Logic and Arithmetic
随机推荐
MySQL backup strategy
STM32_找到导致进入HardFault_Handler的函数
用户解锁SM04 SM12
帮忙发一份招聘,base全国,有兴趣的可以过来看看
JS make a traffic light
Compiling and using log4cxx in rhel7.3
Record a pit dug by yourself~
Actual combat of flutter - Request encapsulation (I)
Systematic explanation of unit testing: mockito
when的多条件查询
flink1.14 sql基础语法(一) flink sql表查询详解
Using docker in MAC to build Oracle database server
Demonstrate the use of foreign keys with Oracle
单臂路由(讲解+实验)
Single arm routing (explanation + experiment)
杂谈:最近好多朋友谈出国……
Okaleido ecological core equity Oka, all in fusion mining mode
C程序代码的内存结构分析
Oracle composite query
在rhel7.3中编译和使用log4cxx