---
title: "shell | 今日所學 | OOZOU"
description: "來自 OOZOU 團隊的簡短實用 shell 筆記。"
canonical: https://oozou.com/zh-Hant/til-topics/shell
locale: zh-Hant
---

# shell | 今日所學

> 來自 OOZOU 團隊的簡短實用 shell 筆記。

- [在 Bash 和 Zsh 執行無痕／私密指令](https://oozou.com/zh-Hant/til/run-incognito-private-commands-for-bash-and-zsh-112) ([markdown](https://oozou.com/zh-Hant/til/run-incognito-private-commands-for-bash-and-zsh-112.md)) (2020-12-08): 只要在指令前面加一個空格，它就不會被存進 ~/.bash\_history。例如  qrencode -o out.png "Some secret text"
- [用 homebrew 升級 postgres 資料庫](https://oozou.com/zh-Hant/til/upgrade-postgres-database-with-homebrew-76) ([markdown](https://oozou.com/zh-Hant/til/upgrade-postgres-database-with-homebrew-76.md)) (2020-10-22): 要升級 postgres，可以執行
- [用 Amazon AWS S3 CLI 複製檔案並設定權限](https://oozou.com/zh-Hant/til/amazon-aws-s3-cli-copy-with-set-perms-14) ([markdown](https://oozou.com/zh-Hant/til/amazon-aws-s3-cli-copy-with-set-perms-14.md)) (2020-10-13): 打開 term（或同類終端機）並貼上以下內容：
- [憤怒的 Docker 大清除](https://oozou.com/zh-Hant/til/angry-docker-purge-72) ([markdown](https://oozou.com/zh-Hant/til/angry-docker-purge-72.md)) (2020-10-13): 如果你在 Docker 上遇到 No Space left 錯誤，這是暴力解法：
- [用相同檔名 + 前綴來備份檔案](https://oozou.com/zh-Hant/til/back-up-a-file-with-same-name-prefix-42) ([markdown](https://oozou.com/zh-Hant/til/back-up-a-file-with-same-name-prefix-42.md)) (2020-10-13): 注意：其實你可以在任何指令中使用 !#:1，因為那代表傳給指令的最後一個參數。
- [Bash alias 與魔法](https://oozou.com/zh-Hant/til/bash-aliases-and-magic-46) ([markdown](https://oozou.com/zh-Hant/til/bash-aliases-and-magic-46.md)) (2020-10-13): 我在使用者資料夾裡有一個獨立的檔案，叫做 ~/.aliases，用來存放我所有的 bash alias。我很常用 alias，也常常新增，所以我寫了一個 bash function 來即時新增…
- [查詢 IKEA 商品庫存](https://oozou.com/zh-Hant/til/check-for-ikea-item-availability-70) ([markdown](https://oozou.com/zh-Hant/til/check-for-ikea-item-availability-70.md)) (2020-10-13): 如果你正在等某件 IKEA 商品補貨，這裡有一個能自動掌握最新狀態的實用解法。這篇指南會說明如何用 shell script 檢查 IKEA 的庫存狀況，並在…
- [用 shell script 檢查指令是否存在](https://oozou.com/zh-Hant/til/check-if-command-exists-with-shell-script-52) ([markdown](https://oozou.com/zh-Hant/til/check-if-command-exists-with-shell-script-52.md)) (2020-10-13): 用 shell script 檢查指令是否存在
- [建立你自己的 git 指令（alias）](https://oozou.com/zh-Hant/til/create-your-own-git-commands-aliases-15) ([markdown](https://oozou.com/zh-Hant/til/create-your-own-git-commands-aliases-15.md)) (2020-10-13): 有沒有想過縮短 git 指令？你當然可以用 shell alias，但你得一直記著前後脈絡，才不會忘記每個 alias 代表什麼。其實你可以用 alias 在 git 裡定義自己的…
- [刪除 Git 中已經 merge 的 branch](https://oozou.com/zh-Hant/til/delete-already-merged-branchs-in-git-36) ([markdown](https://oozou.com/zh-Hant/til/delete-already-merged-branchs-in-git-36.md)) (2020-10-13): 你可以在 egrep -v 'master|develop|foo|bar' 中放行更多 branch
- [刪除已 merge 的 git branch](https://oozou.com/zh-Hant/til/delete-merged-git-branches-51) ([markdown](https://oozou.com/zh-Hant/til/delete-merged-git-branches-51.md)) (2020-10-13): 刪除所有已經 merge 的本機 git branch 的實用 git 指令 git branch --merged | egrep -v "(^\\|master|dev)" | xargs git branch -d*
- [在 Git 中比較本機檔案與遠端版本的差異](https://oozou.com/zh-Hant/til/diff-a-local-file-with-remote-version-in-git-35) ([markdown](https://oozou.com/zh-Hant/til/diff-a-local-file-with-remote-version-in-git-35.md)) (2020-10-13): 只要執行下面的指令，就能取得與遠端版本的 diff
- [根據 commit 找出所屬的 branch](https://oozou.com/zh-Hant/til/find-a-branch-based-on-a-commit-53) ([markdown](https://oozou.com/zh-Hant/til/find-a-branch-based-on-a-commit-53.md)) (2020-10-13): c198bb715 Make default expired description logic pretty `
- [把先前的 commit 強制 push 到 repo](https://oozou.com/zh-Hant/til/force-push-previous-commit-to-repo-44) ([markdown](https://oozou.com/zh-Hant/til/force-push-previous-commit-to-repo-44.md)) (2020-10-13): 如果你已經 push 了一些程式碼，想要 force push 某個較早的 commit，可以這樣做 shell git push origin +commit\sha^:branch\name
- [取得目前的 git branch 名稱](https://oozou.com/zh-Hant/til/get-current-git-branch-name-43) ([markdown](https://oozou.com/zh-Hant/til/get-current-git-branch-name-43.md)) (2020-10-13): 取得目前的 git branch 名稱
- [瀏覽單一檔案的 Git 歷史紀錄（GUI）](https://oozou.com/zh-Hant/til/go-through-a-file-git-history-gui-67) ([markdown](https://oozou.com/zh-Hant/til/go-through-a-file-git-history-gui-67.md)) (2020-10-13): 瀏覽單一檔案的 Git 歷史紀錄（GUI）
- [終止卡住的 rails](https://oozou.com/zh-Hant/til/kill-rails-that-got-stuck-63) ([markdown](https://oozou.com/zh-Hant/til/kill-rails-that-got-stuck-63.md)) (2020-10-13): 我想終止在特定 port 上執行的 rails。（我的筆電上跑著好幾個 rails 伺服器。）
- [終止無回應的 SSH session](https://oozou.com/zh-Hant/til/kill-unresponsive-ssh-session-65) ([markdown](https://oozou.com/zh-Hant/til/kill-unresponsive-ssh-session-65.md)) (2020-10-13): SSH session 偶爾會失去回應。如果我讓筆電進入睡眠，這種情況相當常見。與其直接關掉分頁，你可以使用 SSH Escape Characters 來終止 session
- [列出目錄結構並排除一個或多個目錄](https://oozou.com/zh-Hant/til/list-directory-structure-except-one-or-more-dirs-24) ([markdown](https://oozou.com/zh-Hant/til/list-directory-structure-except-one-or-more-dirs-24.md)) (2020-10-13): 想過在顯示目前目錄結構時排除一兩個目錄嗎？
- [用 hub 從命令列建立 pr](https://oozou.com/zh-Hant/til/make-a-pr-from-command-line-using-hub-3) ([markdown](https://oozou.com/zh-Hant/til/make-a-pr-from-command-line-using-hub-3.md)) (2020-10-13): 先用 brew 安裝 hub：brew install hub 然後使用像下面範例這樣的簡單指令：hub pull-request -m "best pr ever" -b oozou:develop -h feature/awesome-improvements
- [從你的 branch 移除不要的 commit](https://oozou.com/zh-Hant/til/remove-unwanted-commit-from-your-branch-34) ([markdown](https://oozou.com/zh-Hant/til/remove-unwanted-commit-from-your-branch-34.md)) (2020-10-13): 從你的 branch 移除不要的 commit
- [在 Git 中還原被刪除的檔案](https://oozou.com/zh-Hant/til/restore-a-deleted-file-in-git-5) ([markdown](https://oozou.com/zh-Hant/til/restore-a-deleted-file-in-git-5.md)) (2020-10-13): 在 Git 中還原被刪除的檔案
- [對不同的輸入重複執行同一個指令](https://oozou.com/zh-Hant/til/run-same-command-on-different-input-inputs-71) ([markdown](https://oozou.com/zh-Hant/til/run-same-command-on-different-input-inputs-71.md)) (2020-10-13): 如果你必須對不同的輸入重複執行同一個指令。
- [查看先前 commit 中被刪除的檔案 [git]](https://oozou.com/zh-Hant/til/see-deleted-files-in-previous-commits-git-60) ([markdown](https://oozou.com/zh-Hant/til/see-deleted-files-in-previous-commits-git-60.md)) (2020-10-13): 查看先前 commit 中被刪除的檔案 [git]
- [用 cURL 發送訊息到 Slack](https://oozou.com/zh-Hant/til/send-messages-to-slack-using-curl-26) ([markdown](https://oozou.com/zh-Hant/til/send-messages-to-slack-using-curl-26.md)) (2020-10-13): Slack 允許你透過 Webhooks 服務發送訊息
- [對舊的 repo 做 shallow clone](https://oozou.com/zh-Hant/til/shallow-clone-a-old-repo-2) ([markdown](https://oozou.com/zh-Hant/til/shallow-clone-a-old-repo-2.md)) (2020-10-13): 如果你接下來要作業的 repo 不需要完整的 git 歷史，可以指定 clone 深度，只 clone 這個 repo 的 x 個 revision。
- [用 `host` 取得更多網域資訊](https://oozou.com/zh-Hant/til/use-host-to-get-more-information-about-domains-20) ([markdown](https://oozou.com/zh-Hant/til/use-host-to-get-more-information-about-domains-20.md)) (2020-10-13): 你可能會用 dig 從 DNS 伺服器查詢網域的 A/CNAME/MX 等紀錄。但如果只是想快速看個概況，就用 host 吧：
- [使用 Git 的 aliases 功能](https://oozou.com/zh-Hant/til/using-git-s-aliases-feature-61) ([markdown](https://oozou.com/zh-Hant/til/using-git-s-aliases-feature-61.md)) (2020-10-13): Git 允許你透過 config 在內部建立 alias。你的全域 config 應該位於 ~/.gitconfig
- [在 Github 上監看 CI 狀態](https://oozou.com/zh-Hant/til/watch-ci-status-on-github-47) ([markdown](https://oozou.com/zh-Hant/til/watch-ci-status-on-github-47.md)) (2020-10-13): 安裝了 Github 的 hub 之後，你可以像這樣取得目前 branch 的 ci-status：
- [列出檔案樹的 Zsh function](https://oozou.com/zh-Hant/til/zsh-function-to-list-file-tree-17) ([markdown](https://oozou.com/zh-Hant/til/zsh-function-to-list-file-tree-17.md)) (2020-10-13): 在命令列瀏覽目錄時，若能以「tree」格式查看目錄與子目錄的結構，通常會很有幫助。雖然已經有很多現成工具，例如…

All notes: [今日所學](https://oozou.com/zh-Hant/til) ([markdown](https://oozou.com/zh-Hant/til.md)).

---

Contact OOZOU: hello@oozou.com · +66 2544 0000 · https://oozou.com/zh-Hant/contact

More for AI agents: https://oozou.com/llms.txt · every page has a markdown twin at its URL plus ".md"
