# command line

# List of common exit codes for GNU/Linux

# docker

docker 构建指定参数 docker build --build-arg <参数名称>=<值>
ARG 指令有生效范围,如果再 FROM 指令之前指定,那么只能用于 FROM 指令中,如果后续还需要使用,需要重新声明

事先准备一个有丰富调试工具的镜像,在需要调试时,使用镜像启动容器,并设置参数与被调试容器使用同样的 namespace,这样就可以进行调试了
docker run -it --network=container:$TARGET_ID --pid=container:$TARGET_ID --ipc=container:$TARGET_ID busybox

kubectl-debug (opens new window)

# comm

#find lines only in file1
comm -23 file1 file2

#find lines only in file2
comm -13 file1 file2

#find lines common to both files
comm -12 file1 file2
1
2
3
4
5
6
7
8

# cmake

list all options
cmake -LAH

# find

指定文件夹类型

-type d

# git

git rebase first commit

git rebase -i --root

git merge vs git rebase: Avoiding Rebase Hell (opens new window)

Use git pull --unshallow and it will download the entire commit history.

# 指定 ssh 秘钥

export GIT_SSH_COMMAND='ssh -i ~/.ssh/private-key'

# 查看上一个 commit 更改的文件

git diff-tree --no-commit-id --name-only -r HEAD

# 解决中文乱码

git config core.quotepath false

# 解决 fatal detected dubious ownership in repository

# GDB

thread apply all bt打印所有线程栈

# make

# tcpdump

tcpdump -D列出所有 NIC

# perf

# install

apt-get install linux-tools-common linux-tools-generic linux-tools-`uname -r`
1

在一些定制的 linux 发行版比如 tlinux 中上边的命令不好用,需要自己拉源码进行安装
在 arch 为宿主的 ubuntu 容器中也会有类似的问题,估计还是得拉对应内核版本的源码安装

编译 perf 的时候注意一下输出的 features,有一些 features 如果没有开启,用起来会有问题
build perf

# usage

git clone https://github.com/brendangregg/FlameGraph.git
 perf record -F 99 --call-graph dwarf \
     /path/to/executable \
 && perf script -i perf.data \
 | ./FlameGraph/stackcollapse-perf.pl \
 | ./FlameGraph/flamegraph.pl > flamegraph.svg
1
2
3
4
5
6
# 如何查看可执行文件是否带有 debug info
# call-graph 参数解释

DWARF is a debugging file format used by many compilers and debuggers to support source level debugging. It addresses the requirements of a number of procedural languages, such as C, C++, and Fortran, and is designed to be extensible to other languages. DWARF is architecture independent and applicable to any processor or operating system. It is widely used on Unix, Linux and other operating systems, as well as in stand-alone environments. (opens new window)

# sed


# 在匹配的模式后追加一行
sed -e '/pattern/a appended-content'
# 在匹配的模式前插入一行
sed -e '/pattern/i inserted-content'

1
2
3
4
5
6

# sort

sort file in-place

sort -o file.txt{,}
1