Useful Commands for macOS

Avatar

Jennifer

Nov 19, 2018

Overview

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 com.apple.finder AppleShowAllFiles YES;
killall Finder /System/Library/CoreServices/Finder.app

Hide hidden files:

defaults write com.apple.finder AppleShowAllFiles NO;
killall Finder /System/Library/CoreServices/Finder.app

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

DNS

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 127.0.0.1 | cut -d\  -f2

Get public IP address:

curl http://bot.whatismyipaddress.com

Copyright ©Jennifer