Useful Commands for macOS



Nov 19, 2018


This post contains my personal collection of useful macOS commands.

Most of them are specific to the macOS, however, some are univrersal.

Hidden Files

Show hidden files:

defaults write AppleShowAllFiles YES;
killall Finder /System/Library/CoreServices/

Hide hidden files:

defaults write AppleShowAllFiles NO;
killall Finder /System/Library/CoreServices/

Restart Wi-Fi

networksetup -setairportpower en0 off; \
sleep 0.1; \
ifconfig en0 down; \
sleep 1; \
dscacheutil -flushcache; \
killall -HUP mDNSResponder; \
killall mDNSResponderHelper; \
sleep 0.1; \
ifconfig en0 up; \
sleep 0.1; \
networksetup -setairportpower en0 on


Flush DNS cache:

sudo killall -HUP mDNSResponder

Update for macOS Catalina and later:

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

IP Address

Get local IP address:

ifconfig | grep "inet " | grep -v | cut -d\  -f2

Get public IP address:


Copyright ©Jennifer