Useful Terminal Commands (OS X)
Mac OS X guide Tue 21 August, 2018
Get to know the built-in terminal on your Mac
The Terminal is a powerful command line interface on Mac OS X. Terminal can perform simple tasks like navigating and editing files, but can also be used to monitor your network or computer, access a remote server and configure hidden settings.
All of the terminal commands listed here are perfectly safe to use. Any preference changes are completely reversible. That being said, Terminal does what you tell it to, so be careful what you wish for…
Basically, when typing commands, especially after entering sudo, ensure they are typed correctly to avoid any unwanted changes.
Using sudo means we are requesting to run as a superuser. It can generally be understood as “superuser do.” By default, sudo requires entering our Mac’s login password.
(Remember: You won’t see the cursor move when typing your password in terminal.)
Our list of useful Terminal commands
Change default screenshot directory on OS X
By default, any screenshots you take on your Mac will save to your desktop. If you’d like to change that to a custom directory like /Documents/Screenshots, then you can do that quite easily with the following steps
1. Open “Terminal” Application, found in /Applications/Utilities and enter the following command
defaults write com.apple.screencapture location
2. Now enter a space after “location” and drag the folder you created over to Terminal (which will insert the file path of the folder), or enter the location yourself.
3. Hit Enter on your keyboard, then type in:
$ killall SystemUIServer
4. Press Enter again and you’re done.
Download Youtube Videos and Extract Mp3 file.
To do this you will need youtube-dl, which is a command line program that allows you to download videos from YouTube. For further information, view the youtube-dl documentation. You can install youtube-dl with Homebrew by running the following command. (If you haven’t used this before, check our 30 second guide to install homebrew.)
$ brew install youtube-dl
Hit enter and let it install. Downloading a video is very simple. All you need to do is give youtube-dl a URL and it will do the rest.
$ youtube-dl https://youtu.be/Agl1TgVfls0
To download the mp3 directly from youtube without using FFMPEG
$ youtube-dl --extract-audio --audio-format mp3 [Vid URL]
Monitor your network with Iftop
Iftop is a system monitor tool that produces a list of network connections. It displays a table of current bandwidth usage.
(If you have homebrew installed skip to step 3)
1. Press Command+Space and type Terminal and press enter/return key.
2. Run in Terminal app:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
and press enter/return key.
If the screen prompts you to enter a password, please enter your Mac’s user password to continue. When you type the password, it won’t be displayed on screen, but the system will accept it. So just type your password and press ENTER/RETURN key. Then wait for the command to finish.
brew install iftop
When that’s installed you’re done.
4.You can now use
Monitor system activities with htop
Htop is an interactive process-viewer and process-manager. It is an alternative to the Unix program top (which comes pre-installed on Mac).
It shows a frequently updates list of processes running on the computer, which will usually be ordered by the amount of CPU Usage. Htop uses colour and gives visual information about processor, swap and memory status.
1. You’ll need Homebrew installed, you probably know what that is and how to do that by now though, so proceed to the next step.
2. Install Xcode from the Mac App Store. (Performing any system updates can resolve issues at this stage)
3. Install htop using Homebrew
$ brew install htop
4. Run the following in a terminal window to view system activity
Prevent your Mac from going to sleep
Ever needed to leave your Mac on to do something and it went to sleep? Prevent this with a simple command.
Entering the command on its own will keep the Mac awake until you terminate it by pressing Ctrl+C or closing the terminal window.
Add a time parameter by entering the following
$ caffeinate -u -t 1200
The 1200 represents the number of seconds, so our above command will stop the Mac from going to sleep in the next twenty minutes.
View the weather forecast in terminal
Since we aren’t using windows, you’ll probably want access to a weather application. To get the data we need to use curl.
1. Install Curl using Homebrew
$ brew install curl
2. Run the following command
$ curl wttr.in/london
I’m using the example ‘London’ as a city name but you can edit that to anywhere else.
Add a personalised message to your Mac’s lock screen
Open “Terminal” Application, found in /Applications/Utilities and enter the following command with your own custom message:
sudo defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText “If lost please call (+44)7777-777-777”
Next time you go to the lock screen you will see your new message.
|sftp||Establishes an sftp connection to a remote system.|
|bye||Quits the SFTP session|
|help||Lists all SFTP commands|
|ls||Lists the contents of the remote working directory.|
|lls||Lists the contents of the local working directory.|
|cd||Changes the remote working directory.|
|lcd||Changes the remote working directory.|
|mkdir||Creates a directory on the remote system.|
|rmdir||Deletes a directory on the remote system.|
|get||Copies a file from the remote working directory to the local working directory.|
|put||Copies a file from the local working directory to the remote working directory.|
|delete||Deletes a file from the remote working directory.|
Here’s a list of some super useful keyboard shortcuts you can use while watching videos on Youtube. Become a speed user on Youtube and save time today!read more
All Macs have a built-in Apache HTTP server which you can set up and utilise in a few minutes with zero experience. Use an Apache Server to create a website and host it locally on your Mac. This could be something like a custom homepage for your browser or…read more
Since no one actually knows Google’s secret algorithm the best practice of optimising a website for search engines is using tested methods which usually work. Unsurprisingly, many people don’t know the first thing about crawling, bots, indexing or the practice of SEOread more
Beginners guide to Install Homebrew on Terminal (In 30 seconds). Homebrew is the most popular package manager for Mac OS X Terminal, and it’s free!read more
FTP (File Transfer Protocol) is a popular method for transferring files between two remote systems. This method allows you to upload files from your computer to your WordPress site. To do this you will need an FTP client, which is a desktop app that connects your computer to your WordPress hosting account.read more