当前位置:网站首页>Common UNIX Operation and maintenance commands of shell
Common UNIX Operation and maintenance commands of shell
2022-07-01 04:38:00 【Moshow Zhengkai】
1、 Find all in the directory to .zip The last file is moved to the specified directory .
find . -name “*.zip” -exec mv {} ./backup/ ;
2、 Find the current directory 30 Days ago, it was greater than 100M Of log File and delete .
find . -name “*.log” –mtime +30 –typef –size +100M | xargs rm –rf {};
3、 Batch decompress the current directory to .zip At the end of all the files to the specified directory .
for i in
find . –name "*.zip" –type f
do
unzip –d $i /data/www/
done
annotation :for i in (command);do … done by for A common format for loops , among i As a variable , You can specify that .
4、 Write a script to find the last creation time is 3 Days ago, , Suffix is *.log And delete .
find . -mtime +3 -name “*.log” | xargs rm -rf {};
5、 Write a script to make a directory larger than 100k Move your file to /tmp Next
find . -size +100k -exec mv {} /tmp;
6、 How to determine whether a directory exists , If it doesn't exist, create a new one , Print information if it exists .
if [ ! –d /data/backup/ ];then
mkdir –p /data/backup/
else
echo “ directory already exists ”
fi
-d Representative directory
7、 Replace the directory in the file
sed ‘s:/usr/local:/tmp:g’ test.txt
perhaps
sed -i ‘s//usr/local//tmp/g’ test.txt
8、sed Common commands
How to get rid of the beginning . character :
sed -i ‘s/^.//g’ test.txt
Add a... At the beginning of the line a character :
sed ‘s/^/a/g’ test.txt
Add a... At the end of the line a character :
sed ‘s/$/a/’ tets.txt
Add a... After a specific line z character :
sed ‘/rumen/az’ test.txt
Add a c character :
sed ‘/rumenz/ic’ test.txt
9、sed Another usage is to find the current line , Then modify the parameters after the line
sed -i ‘/SELINUX/s/enforcing/disabled/’ /etc/selinux/config
sed Colon mode , It means that /tmp Change to /tmp/abc/.
sed -i ‘s:/tmp:/tmp/abc/:g’ test.txt
10、 Statistics Nginx Access log Top of the list of visits 20 Of ip Address
cat access.log |awk ‘{print $1}’|sort|uniq -c |sort -nr |head -20
annotation :sort Sort 、uniq( Check and delete the repeated rows and columns in the text file )
11、 Modify the text to ab Replace the ending with cd:
sed -e ‘s/ab$/cd/g’ b.txt
12、 Network packet capture :tcpdump
# Grab 56.7 adopt 80 Packets requested by the port .
tcpdump -nn host 192.168.56.7 and port 80
# exclude 0.22 80 port
tcpdump -nn host 192.168.56.7 or ! host 192.168.0.22 and port 80
13、 Statistics bash_history Most commonly used 20 Bar command
history | awk ‘{print $2}’ | sort | uniq -c | sort -k1,1nr | head -10
14、 Configure firewall scripts , Only remote hosts are allowed to access local 80 port
iptables -F
iptables -X
iptables -A INPUT -p tcp --dport 80 -j accept
iptables -A INPUT -p tcp -j REJECT
perhaps
iptables -A INPUT -m state --state NEW-m tcp -p tcp --dport 80 -j ACCEPT
边栏推荐
- [today in history] June 30: von Neumann published the first draft; The semiconductor war in the late 1990s; CBS acquires CNET
- 嵌入式系统开发笔记79:为什么要获取本机网卡IP地址
- C language games (I) -- guessing games
- [untitled]
- Account sharing technology enables the farmers' market and reshapes the efficiency of transaction management services
- Extension fragment
- 尺取法:有效三角形的个数
- 什么是uid?什么是Auth?什么是验证器?
- OdeInt與GPU
- 扩展-Fragment
猜你喜欢

2022年上海市安全员C证考试题模拟考试题库及答案
![[send email with error] 535 error:authentication failed](/img/58/8cd22fed1557077994cd78fd29f596.png)
[send email with error] 535 error:authentication failed

How to do the performance pressure test of "Health Code"

Concurrent mode of different performance testing tools

How to use maixll dock

206. reverse linked list

Programs and processes, process management, foreground and background processes

js 图片路径转换base64格式

2022 t elevator repair new version test questions and t elevator repair simulation test question bank

Dual Contrastive Learning: Text Classification via Label-Aware Data Augmentation 阅读笔记
随机推荐
js 图片路径转换base64格式
How to choose the right server for website data collection?
Coinbase in a bear market: losses, layoffs, stock price plunges
Unity's 3D multi-point arrow navigation
2022年聚合工艺考试题及模拟考试
Tcp/ip explanation (version 2) notes / 3 link layer / 3.4 bridge and switch / 3.4.2 multiple registration protocol (MRP)
[difficult] sqlserver2008r2, can you recover only some files when recovering the database?
Shell之分析服务器日志命令集锦
One job hopping up 8K, three times in five years
2022年煤气考试题库及在线模拟考试
How to view the changes and opportunities in the construction of smart cities?
LM small programmable controller software (based on CoDeSys) note 20: PLC controls stepping motor through driver
Internet winter, how to spend three months to make a comeback
Embedded System Development Notes 79: why should I get the IP address of the local network card
[leetcode skimming] February summary (updating)
2022 polymerization process test questions and simulation test
为什么香港服务器最适合海外建站使用
TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.4 桥接器与交换机 / 3.4.2 多属性注册协议(Multiple Registration Protocol (MRP))
What is uid? What is auth? What is a verifier?
Introduction of Spock unit test framework and its practice in meituan optimization___ Chapter I