Shell常用命令

 

基本语法

 

while [ 1 ]; do sleep 1; ll; done # 无限循环
while [ $i -lt 10 ]; do echo $i;let "i=$i+1"; done # 有限循环
cat raw.txt | while read line; do echo $line; done # readline
until [ 1 = 0 ]; do sleep 1; ll; done # 无限循环
for i in /media/m* ; do ls -l $i; done # 与目录资源结合
if [ 1 -eq 1 ]; then ll ;fi # test常用判断
if [[ 0 -eq 0 && 1 -eq 0 ]]; then ll ;fi
if [ 0 -eq 0 -a 1 -eq 0 ]; then ll ;fi
if [ ! -e /tmp/111 -a -z "$a" ]; then ll ;fi # 不存在111文件 且a变量长度为0 则执行ll

 

 

 

 

 

常用文本操作命令

 

ps -ef | grep java | grep -v eclipse # 查看进程,筛选出java的,排除eclipse的
echo helloworld | tr -d "o" # 删除字符o,输出 hellwrld
echo 'a:b:c' | tr -s ':' '*' # 替换字符:为*,输出 a*b*c
echo 'a:b:c' | awk -F ':' '{print $1 "+" $3 "+" $2}' # 按:切分后,按下标调整顺序,空格分割输出。a+c+b
awk -F':' '{print $1}' temp2.log | awk '{ arr[$1]++ } END { for( no in arr) { print no , arr[no] } }' | sort -n -t" " -k 2 -r # 一句话实现group by
grep -rn 'ReturnMessageListCount' info.log | awk -F"|" '$3 ==11 {print $0 }'
echo 'a:b:c' | sed -e 's#:#*#g' # 替换字符:为*,输出 a*b*c
zgrep " body size " push-receipt-service-info.1.log.gz | awk '{sum+=$NF}END{print sum}'

 

 

 

 

 

常用命令

 

sudo su admin # 切换为admin身份
sudo -u admin kill -9 xxx # 以admin身份执行kill命令
ps -ef # 查看java进程
zip -9 -p haha -r bak.zip src # 以9级压缩比、haha为密码,压缩src目录,压缩后的文件是bak.zip
gunzip FileName.gz #解压缩

 

 

 

 

 

远程骚操作

curl

curl -H "auth_token:1141d565-a0ac-4577-b816-61c884d888a8" -H "Content-Type:application/json" -X POST --data '{"priority": "normal", "messages": [{"targetType":"its just string","targetValue":"CN_4a4d496fb13027584c3459d3f6d5584d","message":"xxxxxxxxx","priority":"high","appId":"123456"}]}' http://10.13.30.114:8082/server/v1/message/sms/unicast_batch

curl -H "Content-Type:application/json" -X POST --data '{"registrationId":"CN_f733779a0b7fee6c93ac2d4d065ee04b","app_key":"3K0tr62sko6fQHMDqYVEci3X","blackList":[{"appId":"12124145214","source":"net"}],"type":"A","sign_method":"MD5","timestamp":"1540278529604","sign":"2db303aa0f79940a5cdc749a3f72a0a7"}' https://test.opush-test.wanyol.com/sms/v1/sn/blacklist

{"targetType":"2","targetValue":"CN_ad714e2162abba1f42f136dc8cfd2094","message":{"key1":"value1","key2":"value2","key3":"value3"}}
{"priority":"high","messages":[{"targetType":"2","targetValue":"CN_ad714e2162abba1f42f136dc8cfd2094","message":{"key1":"value1","key2":"value2","key3":"value3"}},{"targetType":"2","targetValue":"CN_ad714e2162abba1f42f136dc8cfd2094","message":{"key3":"value3"}}]}
{"messages":[{"targetValue":"CN_ad714e2162abba1f42f136dc8cfd2094","targetType":2,"message":{"key1":"value1","key2":"value2","key3":"value3"}},{"targetValue":"CN_ad714e2162abba1f42f136dc8cfd2094","targetType":2,"message":{"key1":"value1"}}],"priority":"high"}


curl -H "auth_token:37c7c35a-123c-46cd-b8aa-67bb079f2b70" -H "Content-Type:application/x-www-form-urlencoded" -d message='{"data_message":{"description":"xxx","content":"xxx"},"target_type":"2","target_value":"CN_4a4d496fb13027584c3459d3f6d5584d"}' http://10.13.30.114:8082/server/v1/message/instant/data_message/unicast

 

 

安装软件相关

# 安装 rz sz
rpm -ivh /root/lrzsz-0.12.20-36.el7.x86_64.rpm

# jdk8 上传jdk-8u144-linux-x64.tar.gz至/usr/local
cd /usr/local && jdk-8u144-linux-x64.tar.gz
cd /usr/bin;$pr ln -sf /usr/local/jdk1.8.0_144/bin/java java;

# 开发机有/data目录 不需要创建 
mkdir -p /data/web
ln -s /data/web /web

# 新增用户
groupadd -g 1203 push;
useradd -u 1203 -g 1203 -d /web/push push;
echo 'push123' |passwd --stdin push;
chmod 755 /web/push;
chown -R push.push /data

#添加path
vim /etc/profile 在最下面添加export PATH=$PATH:/usr/local/bin

 

句柄相关

统计各进程打开句柄数:
lsof -n|awk '{print $2}'|sort|uniq -c|sort -nr
统计各用户打开句柄数:
lsof -n|awk '{print $3}'|sort|uniq -c|sort -nr
统计各命令打开句柄数:
lsof -n|awk '{print $1}'|sort|uniq -c|sort -nr
统计整个系统打开句柄数:
cat /proc/sys/fs/file-nr
find /proc -print | grep -P '/proc/\d+/fd/'| wc -l

 

公司常用

cat source.txt | awk -F '"' '{print $4}' > appId.txt
cat source.txt | cut -d '(' -f2|cut -d ')' -f1

ss -s
netstat -nap | grep ""

sudo -u push sudo kill
sudo -u push sudo stop.sh
grep -rn 'PINGREQ' ap_life_cycle_trace.log | awk -F"|" '{ if($3 == -1) {print $1}}' 
grep -rn 'ReturnMessageListCount' info.log | awk -F"|" '$3 ==11 {print $0 }'

zgrep -n 'J7ldiRerLHCVPtrCqYVEk7XX' /data1/push/logs/push-receipt-service/2018-07-16/receipt_trace_2018-07-16.log.gz |wc -l

cd /data1/push/logs/push-receipt-service/ ; grep -En "CN_9bdb7565b5fdb388986023f160077330|CN_e7e6561482c060fbf9c733ffe6a2a0e5|CN_32bcd9428870477bcd2da518efb8d2a1|CN_0776be1169109421ef7191ca822882c2|CN_61607fbbbcb564a31867d7c0e9e22e50|CN_a2211e79e4fc4dc0170c324719dcea3b" push-receipt-service-info.log

cd /web/push/push-inbox-service/; sudo -u push ./release/bin/stop.sh ; cd /data/logs/push_inbox/ ; ll -rnlt 

cd /web/push/push-receipt/;sudo -u push ./release/bin/stop.sh  ;cd /data1/push/logs/push-receipt-service/ ; ll
mkdir -p /data1/push/logs/push-receipt-service
chown -R push:push /data1

zgrep " body size " push-receipt-service-info.1.log.gz | awk '{sum+=$NF}END{print sum}'

sudo -u push echo "5bc437652764057cb918ea56|1548147955631" >> /web/push/push-inbox-service/data/bigkey_trace.txt

 

 

你可能感兴趣的:(shell)