---
title: "shell | 今日所学 | OOZOU"
description: "来自 OOZOU 团队的简短实用 shell 笔记。"
canonical: https://oozou.com/zh-Hans/til-topics/shell
locale: zh-Hans
---

# shell | 今日所学

> 来自 OOZOU 团队的简短实用 shell 笔记。

- [在 Bash 和 Zsh 运行无痕／私密命令](https://oozou.com/zh-Hans/til/run-incognito-private-commands-for-bash-and-zsh-112) ([markdown](https://oozou.com/zh-Hans/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-Hans/til/upgrade-postgres-database-with-homebrew-76) ([markdown](https://oozou.com/zh-Hans/til/upgrade-postgres-database-with-homebrew-76.md)) (2020-10-22): 要升级 postgres，可以运行
- [用 Amazon AWS S3 CLI 复制文件并设置权限](https://oozou.com/zh-Hans/til/amazon-aws-s3-cli-copy-with-set-perms-14) ([markdown](https://oozou.com/zh-Hans/til/amazon-aws-s3-cli-copy-with-set-perms-14.md)) (2020-10-13): 打开 term（或同类终端）并粘贴下面的内容：
- [愤怒的 Docker 大清除](https://oozou.com/zh-Hans/til/angry-docker-purge-72) ([markdown](https://oozou.com/zh-Hans/til/angry-docker-purge-72.md)) (2020-10-13): 如果你在 Docker 上遇到 No Space left 错误，这是暴力解法：
- [用相同文件名 + 前缀来备份文件](https://oozou.com/zh-Hans/til/back-up-a-file-with-same-name-prefix-42) ([markdown](https://oozou.com/zh-Hans/til/back-up-a-file-with-same-name-prefix-42.md)) (2020-10-13): 注意：其实你可以在任何命令中使用 !#:1，因为它代表传给该命令的最后一个参数。
- [Bash alias 与魔法](https://oozou.com/zh-Hans/til/bash-aliases-and-magic-46) ([markdown](https://oozou.com/zh-Hans/til/bash-aliases-and-magic-46.md)) (2020-10-13): 我在用户目录下单独放了一个文件 ~/.aliases，用来存放我所有的 bash alias。我很常用 alias，也经常新增，所以写了一个 bash function 来随手添加…
- [查询 IKEA 商品库存](https://oozou.com/zh-Hans/til/check-for-ikea-item-availability-70) ([markdown](https://oozou.com/zh-Hans/til/check-for-ikea-item-availability-70.md)) (2020-10-13): 如果你正在等某件 IKEA 商品补货，这里有一个能自动掌握最新状态的实用解法。这篇指南会说明如何用 shell script 检查 IKEA 的库存状况，并在…
- [用 shell script 检查命令是否存在](https://oozou.com/zh-Hans/til/check-if-command-exists-with-shell-script-52) ([markdown](https://oozou.com/zh-Hans/til/check-if-command-exists-with-shell-script-52.md)) (2020-10-13): 用 shell script 检查命令是否存在
- [创建你自己的 git 命令（alias）](https://oozou.com/zh-Hans/til/create-your-own-git-commands-aliases-15) ([markdown](https://oozou.com/zh-Hans/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-Hans/til/delete-already-merged-branchs-in-git-36) ([markdown](https://oozou.com/zh-Hans/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-Hans/til/delete-merged-git-branches-51) ([markdown](https://oozou.com/zh-Hans/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-Hans/til/diff-a-local-file-with-remote-version-in-git-35) ([markdown](https://oozou.com/zh-Hans/til/diff-a-local-file-with-remote-version-in-git-35.md)) (2020-10-13): 只要运行下面这条命令，就能拿到与远程版本的 diff
- [根据 commit 找出所属的 branch](https://oozou.com/zh-Hans/til/find-a-branch-based-on-a-commit-53) ([markdown](https://oozou.com/zh-Hans/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-Hans/til/force-push-previous-commit-to-repo-44) ([markdown](https://oozou.com/zh-Hans/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-Hans/til/get-current-git-branch-name-43) ([markdown](https://oozou.com/zh-Hans/til/get-current-git-branch-name-43.md)) (2020-10-13): 获取当前的 git branch 名称
- [浏览单个文件的 Git 历史记录（GUI）](https://oozou.com/zh-Hans/til/go-through-a-file-git-history-gui-67) ([markdown](https://oozou.com/zh-Hans/til/go-through-a-file-git-history-gui-67.md)) (2020-10-13): 浏览单个文件的 Git 历史记录（GUI）
- [终止卡住的 rails](https://oozou.com/zh-Hans/til/kill-rails-that-got-stuck-63) ([markdown](https://oozou.com/zh-Hans/til/kill-rails-that-got-stuck-63.md)) (2020-10-13): 我想终止在特定 port 上运行的 rails。（我的笔记本上跑着好几个 rails 服务器。）
- [终止无响应的 SSH session](https://oozou.com/zh-Hans/til/kill-unresponsive-ssh-session-65) ([markdown](https://oozou.com/zh-Hans/til/kill-unresponsive-ssh-session-65.md)) (2020-10-13): SSH session 偶尔会失去响应。如果我让笔记本进入睡眠，这种情况相当常见。与其直接关掉标签页，你可以使用 SSH Escape Characters 来终止 session
- [列出目录结构并排除一个或多个目录](https://oozou.com/zh-Hans/til/list-directory-structure-except-one-or-more-dirs-24) ([markdown](https://oozou.com/zh-Hans/til/list-directory-structure-except-one-or-more-dirs-24.md)) (2020-10-13): 想过在显示当前目录结构时排除一两个目录吗？
- [用 hub 从命令行创建 pr](https://oozou.com/zh-Hans/til/make-a-pr-from-command-line-using-hub-3) ([markdown](https://oozou.com/zh-Hans/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-Hans/til/remove-unwanted-commit-from-your-branch-34) ([markdown](https://oozou.com/zh-Hans/til/remove-unwanted-commit-from-your-branch-34.md)) (2020-10-13): 从你的 branch 移除不要的 commit
- [在 Git 中还原被删除的文件](https://oozou.com/zh-Hans/til/restore-a-deleted-file-in-git-5) ([markdown](https://oozou.com/zh-Hans/til/restore-a-deleted-file-in-git-5.md)) (2020-10-13): 在 Git 中还原被删除的文件
- [对不同的输入重复运行同一条命令](https://oozou.com/zh-Hans/til/run-same-command-on-different-input-inputs-71) ([markdown](https://oozou.com/zh-Hans/til/run-same-command-on-different-input-inputs-71.md)) (2020-10-13): 如果你必须对不同的输入重复运行同一条命令。
- [查看先前 commit 中被删除的文件 [git]](https://oozou.com/zh-Hans/til/see-deleted-files-in-previous-commits-git-60) ([markdown](https://oozou.com/zh-Hans/til/see-deleted-files-in-previous-commits-git-60.md)) (2020-10-13): 查看先前 commit 中被删除的文件 [git]
- [用 cURL 发送消息到 Slack](https://oozou.com/zh-Hans/til/send-messages-to-slack-using-curl-26) ([markdown](https://oozou.com/zh-Hans/til/send-messages-to-slack-using-curl-26.md)) (2020-10-13): Slack 允许你通过 Webhooks 服务发送消息
- [对旧的 repo 做 shallow clone](https://oozou.com/zh-Hans/til/shallow-clone-a-old-repo-2) ([markdown](https://oozou.com/zh-Hans/til/shallow-clone-a-old-repo-2.md)) (2020-10-13): 如果你接下来要开发的 repo 不需要完整的 git 历史，可以指定 clone 深度，只 clone 这个 repo 的 x 个 revision。
- [用 `host` 获取更多域名信息](https://oozou.com/zh-Hans/til/use-host-to-get-more-information-about-domains-20) ([markdown](https://oozou.com/zh-Hans/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-Hans/til/using-git-s-aliases-feature-61) ([markdown](https://oozou.com/zh-Hans/til/using-git-s-aliases-feature-61.md)) (2020-10-13): Git 允许你通过 config 在内部创建 alias。你的全局 config 应该位于 ~/.gitconfig
- [在 Github 上监控 CI 状态](https://oozou.com/zh-Hans/til/watch-ci-status-on-github-47) ([markdown](https://oozou.com/zh-Hans/til/watch-ci-status-on-github-47.md)) (2020-10-13): 安装了 Github 的 hub 之后，你可以像这样获取当前 branch 的 ci-status：
- [列出文件树的 Zsh function](https://oozou.com/zh-Hans/til/zsh-function-to-list-file-tree-17) ([markdown](https://oozou.com/zh-Hans/til/zsh-function-to-list-file-tree-17.md)) (2020-10-13): 在命令行浏览目录时，若能以“tree”格式查看目录和子目录的结构，通常会很有帮助。虽然已经有很多现成工具，例如…

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

---

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

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