当前位置:网站首页>Shell之Unix运维常用命令
Shell之Unix运维常用命令
2022-07-01 04:33:00 【Moshow郑锴】
1、查找目录下所有以 .zip 结尾的文件移动到指定目录。
find . -name “*.zip” -exec mv {} ./backup/ ;
2、查找当前目录 30 天以前大于 100M 的 log 文件并删除。
find . -name “*.log” –mtime +30 –typef –size +100M | xargs rm –rf {};
3、批量解压当前目录下以 .zip 结尾的所有文件到指定目录。
for i in
find . –name "*.zip" –type f
do
unzip –d $i /data/www/
done
注解:for i in (command);do … done 为 for 循环的一个常用格式,其中i为变量,可以自己指定。
4、写一个脚本查找最后创建时间是 3 天前,后缀是 *.log 的文件并删除。
find . -mtime +3 -name “*.log” | xargs rm -rf {};
5、写一个脚本将某目录下大于 100k 的文件移动至 /tmp 下
find . -size +100k -exec mv {} /tmp;
6、如何判断某个目录是否存在,不存在则新建,存在则打印信息。
if [ ! –d /data/backup/ ];then
mkdir –p /data/backup/
else
echo “目录已存在”
fi
-d 代表目录
7、替换文件中的目录
sed ‘s:/usr/local:/tmp:g’ test.txt
或者
sed -i ‘s//usr/local//tmp/g’ test.txt
8、sed 常用命令
如何去掉行首的.字符:
sed -i ‘s/^.//g’ test.txt
在行首添加一个a字符:
sed ‘s/^/a/g’ test.txt
在行尾添加一个a字符:
sed ‘s/$/a/’ tets.txt
在特定行后添加一个z字符:
sed ‘/rumen/az’ test.txt
在行前加入一个c字符:
sed ‘/rumenz/ic’ test.txt
9、sed 另外一个用法找到当前行,然后在修改该行后面的参数
sed -i ‘/SELINUX/s/enforcing/disabled/’ /etc/selinux/config
sed 冒号方式,意思是将/tmp改成/tmp/abc/。
sed -i ‘s:/tmp:/tmp/abc/:g’ test.txt
10、统计 Nginx 访问日志 访问量排在前20的ip地址
cat access.log |awk ‘{print $1}’|sort|uniq -c |sort -nr |head -20
注解:sort 排序、uniq(检查及删除文本文件中重复出现的行列 )
11、修改文本中以ab 结尾的替换成 cd:
sed -e ‘s/ab$/cd/g’ b.txt
12、网络抓包:tcpdump
#抓取 56.7 通过80端口请求的数据包。
tcpdump -nn host 192.168.56.7 and port 80
#排除0.22 80端口
tcpdump -nn host 192.168.56.7 or ! host 192.168.0.22 and port 80
13、统计 bash_history 最常用的 20 条命令
history | awk ‘{print $2}’ | sort | uniq -c | sort -k1,1nr | head -10
14、配置防火墙脚本,只允许远程主机访问本机的 80 端口
iptables -F
iptables -X
iptables -A INPUT -p tcp --dport 80 -j accept
iptables -A INPUT -p tcp -j REJECT
或者
iptables -A INPUT -m state --state NEW-m tcp -p tcp --dport 80 -j ACCEPT
边栏推荐
- NFT: start NFT royalty journey with eip-2981
- Applications and features of VR online exhibition
- Redis (VII) optimization suggestions
- Seven crimes of counting software R & D Efficiency
- ThreeJS开篇
- Do280 management application deployment --rc
- Software testing needs more and more talents. Why do you still not want to take this path?
- After many job hopping, the monthly salary is equal to the annual salary of old colleagues
- 扩展-Fragment
- 细数软件研发效能的七宗罪
猜你喜欢

2022.2.7-2.13 AI industry weekly (issue 84): family responsibilities

Task04 | statistiques mathématiques

Offline installation of Wireshark 2.6.10

Rule method: number of effective triangles
![[send email with error] 535 error:authentication failed](/img/58/8cd22fed1557077994cd78fd29f596.png)
[send email with error] 535 error:authentication failed

Embedded System Development Notes 79: why should I get the IP address of the local network card

2022年G1工业锅炉司炉特种作业证考试题库及在线模拟考试

Software testing needs more and more talents. Why do you still not want to take this path?

TASK04|數理統計

In the innovation community, the "100 cities Tour" of the gold warehouse of the National People's Congress of 2022 was launched
随机推荐
PgSQL failed to start after installation
LM small programmable controller software (based on CoDeSys) note 20: PLC controls stepping motor through driver
Learn Chapter 20 of vue3 (keep alive cache component)
Haskell lightweight threads overhead and use on multicores
Daily algorithm & interview questions, 28 days of special training in large factories - the 13th day (array)
CF1638E colorful operations
Embedded System Development Notes 80: using QT designer to design the main interface
How to ensure the idempotency of the high concurrency interface?
多次跳槽后,月薪等于老同事的年薪
Obtain detailed ideas for ABCDEF questions of 2022 American Games
slf4j 简单实现
Task04 | statistiques mathématiques
Redis (VII) optimization suggestions
Seven crimes of counting software R & D Efficiency
Applications and features of VR online exhibition
Strategic suggestions and future development trend of global and Chinese vibration isolator market investment report 2022 Edition
2022 tea master (intermediate) examination question bank and tea master (intermediate) examination questions and analysis
Offline installation of Wireshark 2.6.10
2022 question bank and answers for safety production management personnel of hazardous chemical production units
【发送邮件报错】535 Error:authentication failed