

Bash 日常应用总结
source link: https://pandaychen.github.io/2022/06/10/BASH-NOTE/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

0x00 前言
本文汇总下笔者常用的Bash指令备份
0x01 BASH
1、批量查找文件内容
主要使用grep -rl
,如下面指令,查询当前目录下所有出现yyyy
字符串的文件列表:
grep yyyy -rl --include="*.txt" ./
2、批量替换文件内容
常用sed
搭配grep
指令使用,如下面指令,将当前目录./
下的所有.txt
文件中的yyyy
字符串替换为xxxx
sed -i s/yyyy/xxxx/g `grep yyyy -rl --include="*.txt" ./`
3、批量kill进程
ps aux|grep nginx|grep -v grep|awk '{print $2}'|xargs kill -9
4、仅替换当前目录下的文件内容
sed -i s/xxxx/yyyy/g ./*.txt
5、在匹配行的位置上面或者下面添加指定内容、删除指定行内容
注意下面sed
指令替换那列的a
和i
这两个参数:
sed -i /xxxx/d ./*.txt #删除命中查询条件的行
sed -i /7777/a77777 ./*.txt #在命中查询条件的下一行添加77777
sed -i /7777/i77777 ./*.txt #在命中查询条件的上一行添加77777
6、解析pcap抓包文件
下面示例,通过tcpdump -r
指令对抓包中的源IP进行TOP统计,并按照数量进行排序
tcpdump -r xxxx.pcap |awk '{print $3}'|awk -F '\.' '{print $1"."$2"."$3"."$4}' |sort |uniq -c |sort -nr -k 1
Related Issues not found
Please contact @pandaychen to initialize the comment
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK