Shell常用骚操作

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/b2222505/article/details/78062993

 

基本语法

 

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 #解压缩

 

 

 

 

 

远程骚操作

 

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

 

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

 

 

 

 

展开阅读全文

没有更多推荐了,返回首页