"Terminal, shell, command line interpreter (CLI), command prompt etc."
Disclaimer 1: No right or wrong way, these tips are subjective — 'you do you'!
Disclaimer 2: I hope you'll take away something from this — you might know all of this by heart already.
Disclaimer 3: Limited preparation time … I tried to group some topics, will not attempt to present a complete overview of the Terminal — nor go too much in-depth.
Let me know if you like more tips.
✅ Some shortcuts will also work in Xcode (and other macOS apps)
⌃
A
Jump to beginning of prompt ✅
⌃
E
Jump to end of prompt ✅
⌥
Click
Place cursor at clicked position
⌃
W
Delete previous word
⌃
U
Delete everything from cursor to beginning of prompt
⌃
K
Delete everything from cursor to end of prompt ✅
⌃
Y
Paste last deleted string ✅
⌃
X
E
Open the external $EDITOR with current cmd input, edit command, then run it. (Defaults to TextEdit)
⌘
K
Clear screen & clear scrollback data of terminal
⌘
Up/Down
Jump to previous/next bookmark (can be prompt!)
~
Your home dir
pwd
Shows the full path of the directory you’re currently in
cd -
Goto previous directory pwd
Save yourself some time typing common/long paths by adding an environment variable for them in your ~/.zshrc
, e.g:
export DerivedData="$HOME/Library/Developer/Xcode/DerivedData"
❯ cd $DerivedData
⌘
⇧
A
Selects output of previous command. (which you can then copy to share)
Esc
.
Paste the last parameter of the previous command. (Useful if that's a long path)
⌃
R
Reverse search through the history of commands, while typing; pressing ⌃
R
again shows next match.
<command> # comment
Add comment to a command so you can easily find it using ⌃
R
vs.
history
Shows command history
![#]
Execute command [#] from e.g. ~/.zsh_history
Use pipes |
to chain commands and their output.
sort -u
Sort the input and only show unique values
head -3
Show first 3 lines of input
tail -3
Show last 3 lines of input
wc -l
Count lines of input
history | tail -10 # Show last 10 commands
history | grep xcrun # Show all xcrun commands
find . -name "*.swift" | xargs wc -l # Count lines in all .swift files
opendiff <file1> <file2>
Opens FileMerge (installed with Xcode) and compares <file1> with <file2>
Find something inside your code base or project file:
grep <query> <file>
grep -C2 <query> # Show 2 lines of context above&below match
grep -r <query> # recursively search for query
Triple click
Selects entire line — drag to select multiple lines
💡 If you want to learn more about the macOS Terminal app, you can also take a look at Keyboard shortcuts in Terminal on Mac over at Terminal User Guide for macOS Sequoia 😉