Cheatsheet Mac CMD
Comandos essenciais do Terminal macOS
Mac CMD
Files and Navigation
Navigation
pwd # current folder
ls -la # list with details
cd ~/Desktop # go to the Desktop
cd .. # go up one level
cd ~ # go to home
open . # open folder in Finder
Moving around the system.
Find Files
find . -name "*.pdf" # by name
mdfind "report" # Spotlight CLI
mdfind -name photo.png # by name
locate file # database
which python3 # binary path
Locate quickly.
Create and Delete
mkdir folder # create folder
mkdir -p a/b/c # create nested
touch file.txt # create empty
rm file.txt # delete
rm -rf folder # delete folder
trash file # move to Trash
Create and remove.
Copy and Move
cp a.txt b.txt # copy file
cp -r folder/ dest/ # copy folder
mv a.txt b.txt # move/rename
ditto src/ dst/ # copy (macOS)
ln -s target link # symbolic link
Copy, move and link.
ls and Information
ls -l # long format
ls -a # include hidden (.files)
ls -lh # human-readable sizes
ls -t # by date
mdls file # Spotlight metadata
file photo.png # file type
File details.
macOS Productivity
open (Open Everything)
open . # Finder in the folder
open file.pdf # default app
open -a Safari url # specific app
open -e notes.txt # TextEdit
open -R file # reveal in Finder
open https://site.com # browser
Open with applications.
Useful Shortcuts
caffeinate # prevent sleep
caffeinate -t 3600 # for 1 hour
pmset displaysleepnow # turn off display
shutdown -s now # shut down the Mac
shutdown -r now # restart
System control.
Clipboard (pbcopy/pbpaste)
cat f.txt | pbcopy # copy to clipboard
pbpaste > output.txt # paste to file
pbpaste | wc -l # count lines
echo "Hello" | pbcopy # text → clipboard
pbpaste | grep error # filter clipboard
The clipboard.
say and afplay
say "Hello world" # text to speech
say -v Joana "Hello" # Portuguese voice
say -o hello.aiff "text" # save audio
afplay sound.mp3 # play audio
afplay /System/Library/Sounds/
Glass.aiff
Audio and speech synthesis.
Screenshots
screencapture photo.png # full screen
screencapture -w f.png # select area
screencapture -x f.png # no sound
screencapture -T 3 f.png # 3s delay
Screenshots via terminal.
Homebrew
Install Homebrew
/bin/bash -c "$(curl -fsSL
https://raw.githubusercontent.com/
Homebrew/install/HEAD/install.sh)"
brew --version # verify
Install the package manager.
Maintenance
brew doctor # diagnose
brew cleanup # clean cache
brew infthe package # details
brew deps package # dependencies
brew pin package # prevent upgrade
Keep Homebrew healthy.
Manage Packages
brew install git # install
brew uninstall git # remove
brew upgrade # upgrade everything
brew update # update formulas
brew list # installed packages
brew search name # search
Basic operations.
Casks (GUI Apps)
brew install --cask firefox
brew install --cask visual-studio-code
brew install --cask docker
brew uninstall --cask app
brew list --cask
Install GUI applications.
Services
brew services list # services
brew services start mysql # start
brew services stop mysql # stop
brew services restart nginx
Manage background services.
System and Information
Mac Information
sw_vers # macOS version
system_profiler # full info
system_profiler SPHardwareDataType
# hardware only
uname -m # architecture (arm64)
hostname # Mac name
System details.
Spotlight and Indexes
mdutil -s / # index status
mdutil -E / # reindex
mdfind -onlyin ~/Docs "pdf"
# scoped search
Manage Spotlight.
Resources
top # real-time processes
df -h # disk space
vm_stat # memory (macOS)
sysctl -n hw.memsize # total RAM
uptime # time and load
Monitor resources.
Power Management
pmset -g # current settings
pmset -g batt # battery status
pmset sleepnow # put Mac to sleep
sudo pmset -a sleep 0 # never sleep
Power control.
Variables and Shell
echo $SHELL # current shell (zsh)
echo $PATH # paths
export VAR="value" # set variable
source ~/.zshrc # reload config
env # all variables
Terminal environment.
Network
Connectivity
ping google.com # test connection
ping -c 4 host # 4 packets
ifconfig # network interfaces
ipconfig getifaddr en0 # local IP
networksetup -listallhardwareports
Diagnose the network.
curl and Transfers
curl -O url # download
curl -I url # headers only
curl -X POST -d "a=1" url
# POST
rsync -av src/ dst/ # synchronize
Transfer data.
Wi-Fi
networksetup -getairportnetwork en0
# current Wi-Fi network
networksetup -listpreferredwirelessnetworks en0
# saved networks
networksetup -setairportpower en0 off
# turn off Wi-Fi
Manage Wi-Fi via terminal.
SSH and SCP
ssh user@host # connect remotely
ssh -p 2222 user@h # custom port
scp f.txt user@h:/tmp # send file
ssh-keygen -t ed25519 # generate key
ssh-copy-id user@host # install key
Secure remote access.
DNS and Ports
dig domain.com # DNS query
nslookup host # resolve DNS
lsof -i :8080 # who uses the port
netstat -an | grep LISTEN
# open ports
traceroute host # path
Ports and resolution.
Disk and Storage
diskutil (Info)
diskutil list # all disks
diskutil info disk0 # details
diskutil info / # system disk
diskutil apfs list # APFS volumes
List and inspect disks.
Disk Space
df -h # free space
du -sh ~/Downloads # folder size
du -h -d 1 ~ # per subfolder
diskutil apfs list # APFS volumes
Analyze storage.
Eject and Mount
diskutil eject /Volumes/USB
# eject external disk
diskutil mount disk2s1
# mount volume
hdiutil attach image.dmg
# mount DMG
Manage volumes.
Permissions and xattr
chmod +x script.sh # executable
xattr -l file # view attributes
xattr -d com.apple.quarantine app
# remove quarantine
sudo chown -R user folder/
Permissions and quarantine.
Processes and Services
View Processes
ps aux # all processes
ps aux | grep Safari # filter
top -o cpu # sort by CPU
pgrep -l node # search by name
activity monitor: open -a "Activity Monitor"
List active processes.
Kill Processes
kill 1234 # kill by PID
kill -9 1234 # force (SIGKILL)
pkill -f node # by name
killall Safari # all with the name
killall Finder # restart Finder
Stop processes.
Background
command & # in background
Ctrl+Z # suspend
bg # resume in background
fg # bring to foreground
jobs # list jobs
nohup cmd & # ignore hangup
Job control.
launchctl (Services)
launchctl list # active services
launchctl load ~/Library/
LaunchAgents/my.plist
launchctl unload ~/Library/
LaunchAgents/my.plist
Manage daemons and agents.
Advanced
defaults (Preferences)
defaults read com.apple.dock
# read Dock preferences
defaults write com.apple.dock
autohide -bool true
killall Dock # apply
defaults delete com.apple.dock
autohide # reset
Change system preferences.
Terminal Shortcuts
Ctrl+C # interrupt
Ctrl+L # clear screen
Ctrl+A # start of line
Ctrl+E # end of line
Ctrl+R # search history
Tab # autocomplete
Cmd+K # clear scrollback
Productivity in Terminal.app.
osascript (AppleScript)
osascript -e 'display dialog
"Hello!"'
osascript -e 'tell application
"Finder" to quit'
osascript -e 'set volume 5'
osascript script.scpt
Automate with AppleScript.
Compression
tar -czvf backup.tar.gz folder/
# create .tar.gz
tar -xzvf backup.tar.gz
# extract
zip -r archive.zip folder/
unzip archive.zip
hdiutil create -size 100m
-fs HFS+ -volname "USB" disk.dmg
Compress and create images.
Pipes and Redirection
cmd1 | cmd2 # output → input
cmd > f.txt # overwrite
cmd >> f.txt # append
cmd 2> errors # stderr to file
pbpaste | sort | uniq | pbcopy
Data flow.