0%

待整理的脚本(持续更新ing)

记录一些常用/重要,但容易忘记的命令

Git 统计不同版本的文件夹代码行数

1
2
git checkout <commit_id>
find -name "*.py" | xargs cat | wc -l

Git 撤销 commit

1
git revert <commit_id>

Git 撤销单个文件的修改

1
git checkout HEAD -- <文件路径>

Git 暂存

1
2
git stash
git stash pop

Grep 搜索文本并显示文件名和行号

1
grep -Hn "Hello World!" *

Grep 搜索不包含某个字符串的文本并显示文件名和行号

1
grep -Hn "Hello World!" * | grep -v "XXX"

Python 注册全局变量以在所有代码中使用

1
globals()["seed"] = 42

Python 动态修改源码 (Monkey Patching)

1
2
3
4
5
6
7
8
9
# 在源码中
class A:
def forward(self):
...

# 在项目中
def new_forward(self):
...
A.forward = new_forward

wget 下载文件,保存为时间戳

1
wget -O `date +%s`.jpg https://www.baidu.com/img/bd_logo1.png

Nginx 端口转发

1
2
3
4
5
server {
listen 4747;
server_name localhost;
proxy_pass http://x.x.x.x:4747;
}

Linux 统计当前路径下的文件个数

1
ls -l | grep "^-" | wc -l

kill Python 相关进程

1
ps -ef | grep python | grep -v grep | awk '{print $2}' | xargs kill -9