当前位置:网站首页>Shell enterprise interview exercise
Shell enterprise interview exercise
2022-07-27 07:40:00 【Empty and white】
problem 1: Use Linux Command query file1 Line number of the blank line
#!/bin/bash
awk '/^$/ {print NR}' file1
problem 2: Documents chengji.txt The contents are as follows ’’
Zhang San 40
Li Si 50
Wang Wu 60
Use Linux Command to calculate the sum of the second column and output .
#!/bin/bash
awk '{sum+=$2} END {print sum}' chengji.txt
problem 3:Shell How to check whether a file exists in the script ? What to do if it doesn't exist ?
#!/bin/bash
if [ -f file1 ];then
echo exist
else
echo not exist
fi
problem 4: use shell Write a script , Sort an unordered column of numbers in a text
#!/bin/bash
sort -k 2 -nr chengji.txt
problem 5: Please use shell Script out find current folder (/home) All text files below contain characters ”shen” File name for
#1/bin/bash
ls -l /home |grep -r "shen"| awk -F: '{print $1}'
problem 6:
A text file info.txt Is as follows :
aa,201
zz,502
bb,1
ee,42
Each line is separated by commas , The second column is all numbers , Please arrange the file in the second column from the largest to the smallest .
#!/bin/bash
sort -t',' -k 2 -nr info.txt
problem 7: Write scripts to achieve the following functions ;
Every day in the morning 5 Start backup at
What to back up is /var/mylog All files and directories in the can be compressed for backup
Backup can be saved to another device 192.168.1.2 FTP Account number aaa password bbb
Daily backup files are required to be marked with the date of the day
#!/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
problem 8: Please use shell The script creates a group class、 A group of users , The user is called stdX,X from 01-30, And attribution class Group
#!/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
problem 9:## Process the following documents , Take out the domain name and count it , Such as handling :
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
problem 10、 Write a script to find the last creation time is 3 Days ago, , Suffix is *.log And delete .**
#!/bin/bash
find / -name "*.log" -ctime +3 | xargs rm -f
problem 11、 Write a script to make a directory larger than 100k Move your file to /tmp Next .
#!/bin/bash
for i in `find /shell -type f -size +100k`
do
cd /shell && mv $i /tmp
done
problem 12、 Write a script for nginx Log statistics , Get access to ip Most of the former 10 individual (nginx Log path
path :/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
problem 13、 Write a script to put... In the specified file /usr/local Replace it with another directory .
#!/bin/bash
sed 's#/usr/local#/usr#g' test.txt
problem 14、 Instructions :ls | grep “[ad]*.conf” The correct explanation of the command is :
Display contains a perhaps d Start with , Followed by any character , Is then followed by .conf Character file ( Or directory )
2、 find IO The redirection execution result is different from the other three :
right key : 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、 A file , Probably 1 Billion rows , Each row of a ip, Will appear the most top10 Output to a new file
sort file | uniq -c | sort -nr | head -n 10 >> file2
边栏推荐
- UUID and secrets module
- A priority SQL problem
- Actual combat of flutter - Request encapsulation (I)
- Single arm routing (explanation + experiment)
- flink1.14 sql基础语法(一) flink sql表查询详解
- Synchronized lock
- What is the real HTAP? (2) Challenge article
- C common function integration-2
- Closed hash and open hash resolve hash conflicts
- SQL statement batch update time minus 1 day
猜你喜欢

What is the real HTAP? (2) Challenge article

Plato farm is expected to further expand its ecosystem through elephant swap

什么是真正的HTAP?(一)背景篇

drawImage方法第一次调用不显示图片的解决方式

闭散列和开散列解决哈希冲突

Tcp/ip protocol analysis (tcp/ip three handshakes & four waves + OSI & TCP / IP model)

小程序支付管理-新版支付对接流程

Okaleido生态核心权益OKA,尽在聚变Mining模式

STM32_找到导致进入HardFault_Handler的函数

C语言实现猜数字小游戏项目实战(基于srand函数、rand函数,Switch语句、while循环、if条件判据等)
随机推荐
面试复盘五
shell awk相关练习
C language implementation of guessing numbers Games project practice (based on srand function, rand function, switch statement, while loop, if condition criterion, etc.)
Basic functions and collections of guava
Confluence vulnerability learning - cve-2021-26084/85, cve-2022-26134 vulnerability recurrence
Zabbix: map collected values to readable statements
(2022 Hangdian multi school III) 1011.taxi (Manhattan maximum + 2 points)
如何在电脑端登陆多个微信
Am I delayed by the code... Unfortunately, I became a programmer
「翻译」SAP变式物料的采购如何玩转?看看这篇你就明白了
模仿大佬制作的宿舍门禁系统(三)
LeetCode56. 合并区间
[wsl2] configure the USB camera connecting the USB device and using the host
Codeforces Round #810 (Div.2) A-C
Use Amazon dynamodb and Amazon S3 combined with gzip compression to maximize the storage of player data
[golang learning notes 2.0] arrays and slices in golang
VLAN trunk experiment
C# 中的转译字符'/b'
STM32_ Find the cause of entering hardfault_ Handler's function
Systematic explanation of unit testing: mockito