当前位置:网站首页>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
边栏推荐
- 2022 tea master (intermediate) examination question bank and tea master (intermediate) examination questions and analysis
- 1. Mobile terminal touch screen event
- 尺取法:有效三角形的个数
- 什么是uid?什么是Auth?什么是验证器?
- Daily question - line 10
- Some small knowledge points
- 为什么香港服务器最适合海外建站使用
- 283. move zero
- 离线安装wireshark2.6.10
- Browser top loading (from Zhihu)
猜你喜欢

Offline installation of Wireshark 2.6.10

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

Recommend the best product development process in the Internet industry!

Obtain detailed ideas for ABCDEF questions of 2022 American Games

25.k sets of flipped linked lists

Daily question - line 10

Dual contractual learning: text classification via label aware data augmentation reading notes

嵌入式系统开发笔记79:为什么要获取本机网卡IP地址

多次跳槽后,月薪等于老同事的年薪

Rule method: number of effective triangles
随机推荐
嵌入式系统开发笔记80:应用Qt Designer进行主界面设计
OdeInt与GPU
Custom components in applets
2022年煤气考试题库及在线模拟考试
做网站数据采集,怎么选择合适的服务器呢?
Hololens2 development environment building and deploying apps
LM小型可编程控制器软件(基于CoDeSys)笔记二十:plc通过驱动器控制步进电机
嵌入式系统开发笔记79:为什么要获取本机网卡IP地址
PgSQL failed to start after installation
[untitled]
How to view the changes and opportunities in the construction of smart cities?
Tencent has five years of testing experience. It came to the interview to ask for 30K, and saw the so-called software testing ceiling
Obtain detailed ideas for ABCDEF questions of 2022 American Games
Jenkins automatically cleans up construction history
使用scroll-view实现滑块视图可能遇到的问题及其解决方法
Leetcode learning - day 36
mysql 函数 变量 存储过程
C language games (I) -- guessing games
Codeforces Round #721 (Div. 2)B1. Palindrome Game (easy version)B2. Palindrome game (hard version)
js 图片路径转换base64格式