Mac tips: Terminal

Wait, don’t be afraid of the mysterious and unknown… just kidding. Terminal can be amazing. Let me show you some super-easy basic features which can save you time. Oh almost forgot, terminal can be fun too.

The dock spacer

This one is my favourite. You can add a blank “Icon” in your dock and move it wherever you want. As result, you can organise apps in a pretty way.

The command:

defaults write com.apple.dock persistent-apps -array-add '{tile-type="spacer-tile";}'

Now restart the UI:

killall Dock

Never sleep again

We all love how efficient macOS is. Battery life is stellar but everything comes with a price. MacOS will put your computer to sleep as much as it can. Sometimes we just need it to stay awake. There are plenty of apps for it, but there is a built-in feature which you can access from terminal.

Just type caffeinate and you are ready to go. Want more options? Check this out:

caffeinate -s keep your whole system awake

caffeinate -i disable your mac from going to idle state

caffeinate -d will keep your display up

This command will prevent your mac from sleep until your terminal windows is open. You can stop this command (and any command) by pressing control+C.

Talk to me

Simple, fun. Useful? Maybe. Your mac can turn text to speech with say command.

The command:

say write here wahetever you wand and your mac will say it.

The useful basics

Want to be the terminal ninja? You’re in the wrong place my friend, but here are some basics.

The commands:

cd = change directory. You can go in and out through your folders with this command.

cd Downloads will enter the Downloads folder

cd .. is one level back in your folder structure

cd SPACE yes just hit spacebar do not type SPACE there. will get you home

ls = list. Will sow you the content of th current folder

df -h will show you the used disk space

uptime = will show your uptime

Download without a browser:

curl -O [URL of file you want to download]

Shutdown or restart you mac:

sudo shutdown -h now

sudo shutdown -r now

View your total download history:

sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'select LSQuarantineDataURLString from LSQuarantineEvent'

Delete your download history:

sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'delete from LSQuarantineEvent'

Copy the content of one folder to another:

ditto -V ~/original/folder/ ~/new/folder/

Speed up Time Machine backups:

sudo sysctl debug.lowpri_throttle_enabled=1

Flush your DNS Cache:

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Add static route (IP address and netmask is an example, change it to yours):

sudo route -n add -net 10.0.0.0/8 192.168.0.254