Skip to content

Instantly share code, notes, and snippets.

@Paul-van-Klaveren
Last active April 2, 2025 13:26
Show Gist options
  • Save Paul-van-Klaveren/5e4fa7aab0bfc36e958728d85145d71b to your computer and use it in GitHub Desktop.
Save Paul-van-Klaveren/5e4fa7aab0bfc36e958728d85145d71b to your computer and use it in GitHub Desktop.
Some Terminal tips presented during a Monthly iOS Community Gathering at ABN AMRO

macOS Terminal app icon. Copyright © 2025 Apple Inc. All rights reserved. Terminal Tips

"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.

Topics


Typing and Navigation

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!)

"Where am I on the file system?"

~ 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

Re-using previous commands

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


Chaining commands

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

Other examples

opendiff <file1> <file2> Opens FileMerge (installed with Xcode) and compares <file1> with <file2>

"Is it even there?"

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

@Paul-van-Klaveren
Copy link
Author

💡 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 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment