Shell
-
tar:
-h --dereference # archive and dump the files they point to tar -tcf file.tar # list the contents of a tar file tar -xvf test.tar -C /path/to/destination # extract to specified dir # tar WITHOUT symblinks find /path/to/folder -name "*.py" -not -type l -print0 | tar --null --files-from - -cvf test.tar
-
Redirect and save log:
YOUR_COMMAND_HERE 2>&1 | tee log.txt
-
awk:
-
ls and concat full path.
ls /path/*.jpg | awk '{print "/path/"$1}'
-
search process and kill
ps aux | grep username | grep python | awk '{print $2}' | xargs kill -9
-
-
find:
-
grep:
-
Find pattern under a path
grep -rnw '/path/to/find' -e 'string-pattern'
-
-
sed:
-
xargs:
-
Copy files in list
cat test.list | xargs cp -t /path/to/dst
-
Git
-
git diff
-
diff 两个 branches:
git diff branch-a branch-b
-
diff 两个 branches 中的同一个文件 file:
git diff branch-a branch-b -- file
-
撤销未提交的 conflict:
git reset
-
-
delete a branch
- delete a local branch:
git branch -d branch_name
- delete a remote branch:
git push remote_name --delete branch_name
- delete a local branch:
LaTeX
1. 交叉引用
% cref must be loaded after hyperref
\usepackage{cleveref}
\crefname{equation}{Eq.}{Eq.}
\crefname{figure}{Fig.}{Fig.}
\crefname{table}{Tab.}{Tab.}
\crefname{section}{Sec.}{Sec.}
-
Convert PDF to PDF/A
gs -dPDFA -dBATCH -dNOPAUSE -sProcessColorModel=DeviceRGB -sDEVICE=pdfwrite -sPDFACompatibilityPolicy=1 -sOutputFile=output_filename.pdf input_filename.pdf
-
Crop PDF
pdfcrop --margins '0 0 0 0' example.pdf
The cropped pdf will be saved at 'example-crop.pdf' (install the command via: 'apt-get install texlive-extra-utils')
-
Concat multiple PDFs
pdftk a.pdf b.pdf cat output a-b.pdf
Concat 'a.pdf' and 'b.pdf' into a single pdf file ('a-b.pdf'). pdftk can be installed via: snap install pdftk (or alternatively apt-get install pdftk).
-
删除 PDF 文件中的某些页
-
删除 “a.pdf” 中的 1-3 页,并保存到 “b.pdf”:
pdftk a.pdf cat 4-end output b.pdf
-
删除 “a.pdf” 中的 3-5 页,并保存到 “b.pdf”:
pdftk a.pdf cat 1-2 6-end output b.pdf
pdftk 在 ubuntu (>=18) 上可以通过 snap install pdftk 安装,Windows 可以从官网下载安装包。
-
删除 “a.pdf” 中的 1-3 页,并保存到 “b.pdf”:
SSH Tunnel 内网穿透
- 内网机器 A,IP 地址为 host-private,用户名为 private-user;
- 公网机器 B,有公网 IP host-public,用户名为 public-user。
假设有两个机器:
首先在内网机器 A 上生成 ssh key(如果已经有的话可以不用再生成):ssh-keygen -t rsa -C "[email protected]"
然后将生成的 ssh key 拷贝到公网机器 B 上:ssh-copy-id public-user@host-public
在公网机器 B 上修改 ssh 服务的配置文件(Ubuntu 系统在 /etc/ssh/ssh_config
),添加以下内容:
# 启用以支持端口监听在 0.0.0.0,否则为 localhost
GatewayPorts yes
# 30秒发一次心跳,失败3次断开与客户端的连接
ClientAliveInterval 30
ClientAliveCountMax 3
并重启 B 机器的 ssh 服务:service sshd restart
。
在内网机器 A 上安装 autossh:apt-get install autossh
。
然后运行:autossh -M 0 -CNR port-b:0.0.0.0:port-a public-user@host-public -f
,就可以将内网机器的 port-a 端口映射到外网机器的 port-b 端口上,
-f
参数表示程序会退出并在后台运行。
例如运行autossh -M 0 -CNR 10022:0.0.0.0:22 public-user@host-public -f
,将 A 机器的 22 端口(ssh 服务监听的端口)映射到 B 机器的 10022 端口上,
然后就可以通过ssh private-user@host-public -p 10022
ssh登录在内网的 A 机器。
可以用类似的命令将多个端口映射出去,这样可以在外网访问查看 tensorboard,jupyter-notebook 等。