Last active
June 21, 2023 09:00
-
-
Save kimisme9386/fc93ad75c237d30b0febb63542186085 to your computer and use it in GitHub Desktop.
Linux or mac 指令小技號備忘
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 例如要搜尋第一個符號 "[git tag" 開頭且結尾是 "]" 字元的字串,而且用非貪婪的 regular expression 方式,grep 中要加 "-P" 參數 | |
# Linux | |
grep -o -P "\[git tag .*?\]" | |
# MacOS 只能用 egrep ,因為 grep 沒有 "-P" 參數 | |
egrep -o "\[git tag .*?\]" | |
# 執行成功顯示訊息用 "&&" 串起來,若失敗用 "||" 接著串,潔簡的表達成功或失敗該顯示什麼訊息或執行什麼指令 | |
npx projen build && echo "::set-output name=conclusion::success" || echo "::set-output name=conclusion::failure" | |
# 寫入檔案內容 (override) 並 print 出來 | |
cat <<EOF | sudo tee /etc/modules-load.d/containerd.conf | |
overlay | |
br_netfilter | |
EOF | |
# 新增內容到檔案 (append) 並 print 出來 | |
cat <<EOF | sudo tee -a /etc/modules-load.d/containerd.conf | |
overlay | |
br_netfilter | |
EOF | |
# 使用 sed 註解原來檔案中的設定 | |
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab | |
# APT 指令備忘 | |
apt update | |
apt install -y mysql-server | |
/etc/init.d/mysql start | |
apt install -y memcached | |
apt install -y libmemcached-dev | |
/etc/init.d/memcached start | |
apt list --installed | grep memcached | |
# shell script | |
k8s init Container 用 until 搭配 nslookup 來偵測服務 | |
```bash | |
spec: | |
... | |
initContainers: | |
- name: shipping-svc-check | |
image: busybox:1.27 | |
command: ['sh', '-c', 'until nslookup shipping-svc; do echo waiting for shipping-svc; sleep 2; done'] | |
``` | |
# Mac 被防毒軟體或其他東西擋到時,可以用以下指令 (因為有些防毒軟體 kill process 會自動活過來) | |
``` | |
while true; do P=$(pgrep bitde) && if [[ -n $P ]]; then sudo kill -9 $P;fi; sleep 1; done | |
``` | |
# 拿前五分鐘時間 | |
start=$(date --date '-5 min' +'%Y-%m-%dT%H:%M:%SZ') | |
end=$(date +'%Y-%m-%dT%H:%M:%SZ') | |
curl "localhost:9090/api/v1/query_range?query=node_cpu_seconds_total&start=$start&end=$end&step=1m" | |
# grep 時多印前 N 行或後 N 行 | |
# 後 1 行 | |
grep 'containers' pod.yaml -A1 | |
# 前 1 行 | |
grep 'containers' pod.yaml -B1 | |
列出 log latency 大於多少的行數,並把上一行也列出來 | |
awk '$6 > 1000 { print f "\n" $0 } {f=$0}' < server.log | |
# ag 忽略多個資料夾 | |
ag 'zuoraTreasureDataCallback' --ignore-dir={node_modules,node_modules} | |
# 比對檔案 | |
diff --exclude="temp" -Nu -r sv2-system/sv2/tidy-up-config sv2-system/sv2/tidy-up-config/temp/downtime_20230620 --color=always | less |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment