As a macOS user, the Terminal is one of our most powerful tools. Whether you are a developer or just an advanced user, mastering some Shell tricks can multiply your work efficiency.
This article shares 5 Zsh/Bash tips I use every day. They require no complex plugin installations and work right out of the box.
1. Quickly Return to the Previous Directory (cd -)
This is perhaps the simplest yet most practical command.
When you are frequently switching between a deep directory like /Users/levi/project/src/components/ and a system directory like /etc/nginx/, you don’t need to type the full path every time.
Simply type:
cd -The system will automatically take you back to “the directory you were in last.”
2. Command Too Long? Use Ctrl + A and Ctrl + E
When you’ve typed a massive command in the terminal and realize you forgot to add sudo at the very beginning, or misspelled a word:
- Do NOT frantically spam the left arrow key.
- Press
Ctrl + A: The cursor instantly jumps to the beginning of the line. - Press
Ctrl + E: The cursor instantly jumps to the end of the line.
These two shortcuts are standard Readline bindings and work universally across most Shell environments.
3. Search Command History (Ctrl + R)
This is an operation that makes you look very “geeky.”
What if you want to execute a complex docker run command you ran a few days ago, but can’t remember the exact parameters?
- Press
Ctrl + R. - Type a keyword (e.g.,
docker). - The terminal will automatically show the most recent matching history record.
- If you want to find an even older one, just keep pressing
Ctrl + R.
4. Free Your Hands with Aliases
If you find yourself frequently typing long commands, like git commit -m "update", you must set up aliases.
Edit your ~/.zshrc file:
# Quick commitalias gcm="git commit -m"# Quick status checkalias gs="git status"# Show hidden files with human-readable sizesalias ll="ls -lah"# Quick flush DNS cachealias flushdns="sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder"After saving, run source ~/.zshrc. From now on, you only need to type gcm "message".
5. open . - Open the Current Folder Graphically
Sometimes manipulating files in the terminal gets tiring, and you just want to use Finder to drag and drop files. Just type:
open .macOS will immediately pop up a Finder window displaying the exact directory your terminal is currently in. This trick is especially handy when managing blog image assets.
Summary
The purpose of tools is to serve people. While these terminal tips may seem minor, the few seconds saved every day accumulate into a massive efficiency boost.
If this article helped you, please share it with others!
Some information may be outdated





