Skip to content

Instantly share code, notes, and snippets.

@TsaiKoga
Last active April 12, 2019 05:37
Show Gist options
  • Save TsaiKoga/9b7f84ce373140aebcc8d04e7f540ebb to your computer and use it in GitHub Desktop.
Save TsaiKoga/9b7f84ce373140aebcc8d04e7f540ebb to your computer and use it in GitHub Desktop.
commonly used commands in terminal 常用终端命令
# check the listening ports
# 查看服务器中正在监听的端口:
netstat -tupln
# check if can connect the port of the host server
# 本地查看远程服务器的端口开启是否能够访问
telnet www.xxx.com 3306
# trace how many routes hops
# 查看访问的地址经过多少路由
traceroute -d xxx.xxx.xxx.xxx
# 查看系统并发连接数:-----------------------
# Check
# CLOSED 无连接是活动的或正在进行
# LISTEN 服务器在等待进入呼叫
# SYN_RECV 一个连接请求已经到达,等待确认
# SYN_SENT 应用已经开始,打开一个连接
# ESTABLISHED 正常数据传输状态/当前并发连接数
# FIN_WAIT1 应用说它已经完成
# FIN_WAIT2 另一边已同意释放
# ITMED_WAIT 等待所有分组死掉
# CLOSING 两边同时尝试关闭
# TIME_WAIT 另一边已初始化一个释放
# LAST_ACK 等待所有分组死掉
#-------------------------------------------
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
# check QPS in production mode from log
# 在生产上从日志查看每秒请求数
tail -f log | cut -d ' ' -f2 | uniq -c
#> 80 13:35:07]
#> 76 13:35:08]
# 查看空间中大于等于 1G 的目录文件,层级为1
# check the occupancy space which greater than 1G
du -h --max-depth=1 | grep 'G' | sort
# check the process
# 查看启动的进程
ps aux
# print the line number
# 输出行号
awk 'print NR, $1$2'
# find the 4 field greater than 19/Mar/2019:09:45:00 and less than 19/Mar/2019:09:55:00, and print this whole line.($0 presents the wholeline,$1 presents the first field)
# 找到文件中第 4 列,时间大于 19/Mar/2019:09:45:00 并且小于 19/Mar/2019:09:55:00 的一整行记录($0 代表一整行,$1代表第一列)
cat access.log | awk '{if($4>"[19/Mar/2019:09:45:00 +0800]" && $4<"[19/Mar/2019:09:55:00 +0800]")print $0'}
# send the post request:
# 发出 POST 请求:
curl --X POST -H "Content-Type: text/plain" --data "this is raw data" http://78.41.xx.xx:7778/
curl --header "Content-Type: application/json" --request POST --data '{"username":"xyz","password":"xyz"}' http://localhost:3000/api/login
# insert the line into specific line in file:
# 将文本插入文件中匹配的行:
sed '/<\/Host>/i\<Connector executor="tomcatThreadPool" po" URIEncoding="UTF-8" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />' /opt/appstack/apache-tomcat/conf/server.xml
# create user and password
# 创建用户和密码:
useradd testuser
passwd testuser
# delete user
# 删除用户
userdel testuser
# change the directory owner
# 更改目录所属者(通常网站权限无法访问时更改)
chown -R daemon app/
# enable the port TCP input:
# 防火墙端口添加入规则:
iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
# check the iptables status
# 是否开启防火墙
service iptables status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment