BLOGTERMINAL · MAC · ZSH ·
Type less.
Do more.
44 aliases to make your Mac terminal faster. Copy one, copy a group, or grab the whole file. Setup takes about a minute.
SETUP
Three steps. About a minute.
Open your config
This opens ~/.zshrc in TextEdit and creates the file if you do not have one yet.
touch ~/.zshrc && open -e ~/.zshrcPaste the aliases
Copy the ones you want from this page, paste them at the bottom of the file, and save.
Copy all 44 aliasesReload the terminal
Run this once, or just open a new terminal window. Then try one: type battery and press Return.
source ~/.zshrc
Prefer one command?
This downloads the full file to ~/.mac-aliases.zsh and loads it from your config. You can read the file first. Read the file.
curl -fsSL https://tonyschaffert.com/blogs/en/mac-terminals-alias/mac-aliases.zsh -o ~/.mac-aliases.zsh && echo 'source ~/.mac-aliases.zsh' >> ~/.zshrc && source ~/.zshrcTHE LIST
Mac terminal aliases
02 / 7 ALIASES
Files and folders
alias ll='ls -lahG'List everything, with sizes you can read.
alias la='ls -AG'Short list that includes hidden files.
alias lt='ls -lahGt'List everything, newest first.
alias cp='cp -iv'Copy, but ask before overwriting.
alias mv='mv -iv'Move, but ask before overwriting.
alias mkdir='mkdir -pv'Create nested folders in one go.
alias dsclean="find . -type f -name '.DS_Store' -delete"Delete every .DS_Store file under the current folder.
03 / 5 ALIASES
Shell shortcuts
alias c='clear'Clear the screen.
alias h='history'Show your command history.
alias reload='source ~/.zshrc'Apply changes to your config without reopening the terminal.
alias zshrc='open -e ~/.zshrc'Open your config in TextEdit.
alias path='echo $PATH | tr ":" "\n"'Print your PATH, one entry per line.
04 / 7 ALIASES
Only on a Mac
alias o='open .'Open the current folder in Finder.
alias cpwd='pwd | tr -d "\n" | pbcopy'Copy the current folder path to the clipboard.
alias showfiles='defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder'Show hidden files in Finder.
alias hidefiles='defaults write com.apple.finder AppleShowAllFiles -bool false && killall Finder'Hide them again.
alias afk='pmset displaysleepnow'Put the display to sleep right now.
alias awake='caffeinate -d'Keep the Mac awake until you press Control C.
alias battery='pmset -g batt'Battery level and time remaining.
05 / 5 ALIASES
Network
alias myip='curl -s https://api.ipify.org && echo'Your public IP address.
alias localip='ipconfig getifaddr en0'Your IP on the local network (Wi-Fi on most Macs).
alias ports='lsof -iTCP -sTCP:LISTEN -n -P'See which apps are listening on which ports.
alias flushdns='sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder'Clear the DNS cache. Asks for your password.
alias speedtest='networkQuality'Internet speed test built into macOS 12 and later.
06 / 11 ALIASES
Git
alias gs='git status -sb'Short status with the branch name.
alias ga='git add'Stage a file.
alias gaa='git add -A'Stage everything.
alias gc='git commit -m'Commit with a message: gc "fix typo".
alias gp='git push'Push.
alias gl='git pull'Pull.
alias gco='git checkout'Switch branch.
alias gb='git branch'List branches.
alias gd='git diff'See what changed.
alias glog='git log --oneline --graph --decorate -15'The last 15 commits as a compact graph.
alias undo='git reset --soft HEAD~1'Undo the last commit and keep your changes.
07 / 2 ALIASES
Power tools
These need Homebrew. The second one also needs fzf: brew install fzf.
alias brewup='brew update && brew upgrade && brew cleanup'Update Homebrew and everything installed with it.
alias cbr='git branch --sort=-committerdate --format="%(refname:short)" | fzf --header "Checkout recent branch" --preview "git diff {1}" | xargs git checkout'Pick a recent branch from a searchable list and switch to it.
CAME HERE FROM A REEL?
More shortcuts
on the way.
Follow @therealtifao for the next one.
All posts