Shell(一)常用命令

find + xargs

将当前目录下.bak 的文件,移动到临时/tmp 下面

find . -name "*.bak" | xargs -I '{}' mv {} /tmp

移动到/tmp 临时目录下,不要使用 rm -rf 命令防止误删,其中-I ‘{}’标识占位符

awk

分隔字符串,排序

grep charles /home/zhangcheng.log | awk '{split($0,a,",");if (index(a[11],"5000000000013") > 0 || index(a[11],"5000000000059") > 0) print substr(a[8],9,16),substr(a[11],18,13)}' | sort | uniq

区分奇数行和偶数行

awk '{if (NR%2==1) {printf("%s\t",$0);} else {printf("%s\n",$0);}}' diagnostic.txt

sed

sed 删除不是以^ 开始的行,并且将正则匹配的^[ ]*替换为空

## hmaster
  hmaster-test
##/ hmaster

xx 为上面的3行数据,输出hmaster

cat xx | sed -e '/^## /!d' | sed -e 's/^##[ ]*//g'

删除不带loc的行,替换[ \t]*<loc>为空,</loc>为空
cat sitemap.xml | sed -e '/loc/!d;s/[ \t]*<loc>//g;s/<\/loc>//g'

nc

判断段是否开启

nc -vuz 192.168.99.100 2818

found 0 associations
found 1 connections:
1:	flags=82<CONNECTED,PREFERRED>
	outif (null)
	src 192.168.99.1 port 53888
	dst 192.168.99.100 port 2818
	rank info not available

Connection to 192.168.99.100 port 2818 [udp/rmlnk] succeeded!

连接某个端口,类似 telnet,nc 127.0.0.1 12201

查找 java maven 版本差异
https://www.alicharles.com/article/jar-diff/

https://alicharles.oss-cn-hangzhou.aliyuncs.com/static/images/mp_qrcode.jpg
文章目录
  1. find + xargs
  2. awk
  3. sed
  4. nc