当前位置:网站首页>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
边栏推荐
- 【LeetCode】100. Same tree
- Concurrent mode of different performance testing tools
- 2022年上海市安全员C证考试题模拟考试题库及答案
- [leetcode skimming] February summary (updating)
- mysql 函数 变量 存储过程
- LM small programmable controller software (based on CoDeSys) note 20: PLC controls stepping motor through driver
- Question bank and answers for chemical automation control instrument operation certificate examination in 2022
- LM小型可编程控制器软件(基于CoDeSys)笔记二十:plc通过驱动器控制步进电机
- 206. reverse linked list
- TASK04|数理统计
猜你喜欢

Ten wastes of software research and development: the other side of research and development efficiency

"Target detection" + "visual understanding" realizes the understanding of the input image

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

Internet winter, how to spend three months to make a comeback

VR线上展览所具备应用及特色

Rule method: number of effective triangles

2022年G1工业锅炉司炉特种作业证考试题库及在线模拟考试
![[recommended algorithm] C interview question of a small factory](/img/ae/9c83efe86c03763710ba5e4a2eea33.jpg)
[recommended algorithm] C interview question of a small factory

2022年上海市安全员C证考试题模拟考试题库及答案

Coinbase in a bear market: losses, layoffs, stock price plunges
随机推荐
Unity's 3D multi-point arrow navigation
What is uid? What is auth? What is a verifier?
Hololens2 development environment building and deploying apps
[Master / slave] router election in DD message
MallBook:后疫情时代下,酒店企业如何破局?
js 图片路径转换base64格式
Do280 management application deployment --rc
TASK04|数理统计
Daily question - line 10
Applications and features of VR online exhibition
Procurement intelligence is about to break out, and Alipay'3+2'system helps enterprises build core competitive advantages
2022年T电梯修理题库及模拟考试
Browser top loading (from Zhihu)
Recommend the best product development process in the Internet industry!
Strategic suggestions and future development trend of global and Chinese vibration isolator market investment report 2022 Edition
如何看待智慧城市建设中的改变和机遇?
Why is Hong Kong server most suitable for overseas website construction
Execution failed for task ‘:app:processDebugResources‘. > A failure occurred while executing com. and
2022 question bank and answers for safety production management personnel of hazardous chemical production units
TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.4 桥接器与交换机 / 3.4.2 多属性注册协议(Multiple Registration Protocol (MRP))