常用命令

本文最后更新于:9 小时前

总结和记录下一些常用的 cmd。

git

git tag

1
2
3
4
5
6
7
8
# 本地打标签
git tag -a v1.0.0 -m "first release"
# 推送本地标签到远程
git push origin v1.0.0
# 删除本地tag
git tag -d v1.0.0
# 删除远程标签
git push --delete origin v1.0.0

git branch

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 切换分支
git checkout [branch_name]
git pull
# 创建新分支
git checkout -b [branch_name]
# 删除本地分支
git branch -D [branch_name]
# 删除远程分支
git push origin --delete [branch_name]
# 清除未保存的文件
git clean -f

# git 回滚远程分支
git reset --hard [branch]
git push -f

# 用 release 分支重置 test 分支
git reset --hard origin/release
git push origin test --force

cherry pick

1
2
3
# 合并某个 commit 到对应分支
git checkout [branch_name]
git cherry-pick [commit-id]

other git cmd

1
2
3
4
5
6
7
8
# 设置邮箱和用户名
git config user.name "name"
git config user.email "email"
# 查看配置
git config --list

# 撤销本次 commit,但是保留代码
git reset --soft HEAD~1

go

go bulid

1
2
# 编译指定版本的二进制文件
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o [target_name]

go pprof

1
2
3
4
5
6
7
8
9
10
11
# 获取分析文件,默认会获取30s的数据
go tool pprof http://[ip]:[port]/debug/pprof/profile
go tool pprof http://127.0.0.1:19219/debug/pprof/profile

top [n] # 查看前n个占用CPU的函数
proto # 数据proto文件

go tool pprof -http=:8084 profile001.pb.gz # 解析获取的proto文件,在本地分析CPU数据

# pprof 查看内存情况
go tool pprof http://127.0.0.1:8081/debug/pprof/heap

linux

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 查看进程线程
ps -T -p <pid>

# 下载文件
wget [url]

# 上传文件:
scp -i [private_key_path] [local_path] [ip/domain]:[remote_path]
# 下载文件:
scp -i [private_key_path] [ip/domain]:[remote_path] [local_path]

# 查看端口占用:
lsof -i:[port]

# 抓包
tcpdump -Xns 500 -i [eth0] port [port]

#将指定文件通过各种编码显示
od -c file

# unzip 解压
unzip [zip file] -d [target folder]

# 从容器下载文件到本地
安装: apt-get install lrzsz
sz [file_name]

# 显示进程上下文切换次数
pidstat -w -p [pid] 1

# 查看DNS解析
nsloopup [domain]
安装:apt-get install dnsutils

# 查询网络链路状态
mtr -wbz -c 20 www.baidu.com

mysql

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# login
mysql -h [host] -P [port] -u [user_name] -p

# 查看索引
show index form [table_name];

# 查看建表命令
show create table [table_name];


# 查询表数据大小
SELECT TABLE_NAME AS 'Table', ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024, 2) AS 'Total Size (MB)', ROUND(DATA_LENGTH / 1024 / 1024, 2) AS 'Data Size (MB)', ROUND(INDEX_LENGTH / 1024 / 1024, 2) AS 'Index Size (MB)' FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'airpay_is_card_center_vn_db';

# set json
UPDATE metric_slo_record_tab SET extra_data = JSON_SET(extra_data, '$.cyclical_error_flag', true) WHERE id = 1;

// 查询 DB 数据大小
SELECT
table_schema AS db,
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS used_mb
FROM information_schema.tables
WHERE table_schema = 'shopee_payment_module_limit_tw_db'
GROUP BY table_schema;

证书

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# jks -> p12, need password
keytool -importkeystore -srckeystore xxx.jks -destkeystore test.p12 -srcstoretype jks -deststoretype pkcs12

# p12 -> crt
openssl pkcs12 -in test.p12 -out test.crt

# show crt info 查看证书信息
openssl x509 -in xxx.crt -text

# 校验证书链
openssl verify -CAfile <(cat root.crt immediate.crt) server.crt

# 公钥私钥是否匹配
diff -e <(openssl x509 -pubkey -noout -in cert.crt) <(openssl rsa -pubout -in cert.key)

sftp

1
sftp -oIdentityFile=[key_path] -P22 [user]@[host]

本文作者: Uyouii
文章链接: https://uyouii.cool/posts/6fc55794/
版权声明: 本博客文章除特别声明外, 均采用署名4.0国际(CC BY 4.0)国际许可协议进行授权, 转载请注明出处


常用命令
https://uyouii.cool/posts/6fc55794/
作者
Uyouii
发布于
2026年6月7日下午4点37分
许可协议