Honestly, command line belongs to long gone days; when people use to control computers by typing mystical commands into a black & white interface. If you are someone who has used computers for decades but never touched command prompt than *high five*.
No wonder, it actually sounds scary and overwhelming! But recently when I encountered the situation where I had to learn basics of Mac command line, I discovered it quite friendly and useful.
If we talk about today’s scenario there are several use cases, where command line is still an absolute requirement!
For readers, who have little or no idea about what Mac Terminal is, here’s a small gist for you. Continuing with 10 Best Terminal Commands, every mac user should know:
Introduction to Mac Terminal
Mac Terminal is nothing but a replica of Windows Command Prompt. It allows users to modify various characteristics of their Mac systems, fonts, files and functions more beyond the standard OS X (GUI).
It’s a text interface, a program that takes in commands for your computer to run. Using Mac terminal is a straightforward process, just enter the command and hit ‘Return’ to execute.
With Terminal application, a simple command is all required to spill every function on mac.
How To Open Terminal On Mac?
Terminal allows you to access the UNIX part of macOS, so you can run scripts, manage files and edit settings using text commands. To launch the Terminal application, use Launchpad, Spotlight or Finder.
Open Terminal On Mac: Using Launchpad
Launchpad is a silver rocket icon present in the Dock. Dock is a panel of menus generally located at the bottom of the screen. Either click on the icon or press F4 to open Launchpad. Once you open it > Click on ‘Other’ folder > Click on ‘Terminal’ app to launch the command prompt of Mac.
If you are unable to find the application through Launchpad you can try other methods mentioned below.
Open Terminal On Mac: Using Spotlight
Spotlight looks like a magnifying glass icon; either you can find it in the dock or use shortcut cmd + space bar. Type ‘Terminal’ into the search box > Terminal will appear in the search results, click it & proceed with the command prompt.
Open Terminal On Mac: Using Finder
Finder is alike Windows Explorer; it organizes your files, folder, apps, and documents and helps you to locate them when you misplace them. Present at the bottom of the screen and looks like a two-toned smiling face icon. Once it’s opened, locate ‘Applications’ folder in the left panel. If you don’t find their head towards the top, choose ‘Applications’. Now, click on ‘Utilities’ & scroll down to find ‘Terminal app > Double-click to launch it.
When launched, Terminal provides a line interface that gives you access of the UNIX features that lie beyond the world of macOS.
Basic Utilities You Will Use On A Regular Basis
Using mac terminal commands are super-easy. Anything written in capital letters with dollar sign ($), like for example “$THIS” is an argument, you have to replace it with the actual argument you want to run.
|man – manual, $UTIL is used to get information about all the utilities in your machine.
|ls – list, list of contents of the directories.
|cd – change directories, if you want to change current working directory.
|cp $FILE $LOCATION
|cp – copies, it copies $FILE to $LOCATION
|Mkdir – make new directory.
|pwd – print working directory, if you ever get lost on your mac, run this command to see where you are.
|mv $FILE $LOCATION
|mv – move, it moves $FILE to $LOCATION
|rm – remove, to remove a file permanently.
|sudo – super user do, in simple language it allows users to perform root tasks on a case by case basis.
|If you want to force stop certain commands from running.
How To Use Terminal On Mac?
Now that you have learnt ‘How to open Terminal on mac’, here are some useful Mac terminal commands & tricks that every user should know:
A command consists of three elements: First, the command itself which calls a particular tool, an option which modifies the output, and an argument which calls the resource on which the command will operate.
So, for an instance if you want to move a file from one place to another, you would use the command move “mv” followed by the file and location where you want to move.
So, you have to enter the following command:
mv ~/Desktop/MyFolder /Volumes/Backup
Here are 10 Mac Terminal Commands:
So, without further ado try these Mac terminal tricks:
1. Want to See Hidden Files/Folders
By default, Mac machines hide stuff for a variety of reasons. Most of the time, there’s no reason for users to know about them. But in case you want to track down those hidden files or folders you can do it using Mac command line.
Enter the following command:
defaults write com.apple.finder AppleShowAllFiles -bool TRUE
2. Download Files Without Using Browser
Terminal can help in downloading files when you don’t want to use web browsers. If you have the URL of the file you wish to download, just enter the following commands.
You have to execute two simple commands, first ‘set the location’ where you want to store your downloaded files. Second, ‘download the file’.
Note: To add the location, either type the full path of the location or you can drag and drop folder as well.
First Command: Set the Location
(Change ‘Downloads’ to a different folder if you want)
Second Command: Download File
curl -O (Enter the URL of the file you want to download)
3. Keep your Mac Awake
Prevent your Mac machine from sleeping. How? Give it some caffeine. Yeah not kidding! Caffeinate is our next command. Just use the command and specify an elapsed period of time you want your system to be active!
Run: caffeinate – u – t 5400 ( 5400 are the number of seconds)
The most popular command used in OS X is Ditto. It’s an incredibly useful command when it comes to copying huge amount of data from one folder to another.
Just type: Ditto – v / Old Folder / New Folder
At the place of ‘old folder’ and ‘new folder’ you have to add the paths of the source and destination of the files. You can see each file in the terminal window as they’re copied from one place to another.
5. Change Location for Screenshots
If you don’t want your system to save screenshots on your Desktop, you can change its location using terminal application. To do so, run the following commands:
– Type: defaults write com.apple.screencapture location (path of the folder where you want screenshots to be saved)
– Click Return
– Type: killall SystemUIServer
6. Change Screenshot File Format
Want to change the file format of screenshots? Using this Mac command line, you can change the default PNG format into PDF, JPEG and more. In the following example we’re changing the default format to PDF.
Execute the following command:
defaults write com.apple.screencapture type PDF
To revert the changes, run the same command again and type PNG in place of PDF.
7. Make your Mac to Automatically Restart After a Crash
We all have faced the issue when our Mac suddenly freezes or crashes. If you don’t want to waste time while it crashes and faces long time system freeze. Then, the following command can help you to reboot your system automatically.
Type: sudo systemsetup – setrestartfreeze on
Remember whenever you’ll use ‘sudo’ command the system will ask you for your Mac username and password. Enter it and proceed.
8. Have a Speaking Mac
Yes, you can make your system to speak. To do so just use the command ‘say’.
say (type whatever you want your Mac to say)
Click ‘Return’ button and it will speak whatever you’ve typed.
9. Play Tetris, Pong and Other Retro Games
You know there are several hidden games in your Mac including Tetris, Snake, Towers of Hanoi, Pong, Solitaire and more.
Want to play them, follow the instructions below:
– Type Emacs and click Enter
– Hit Fn key
– Hit F10
– Then ‘t’ and then ‘g’
You will be presented with all the available games on your machine. Use cursor to select them and Start Playing!
10. Securely Erase Data
Everyone has to certainly delete all the data at some point. After all, a securely deleted data ensures safety of personal information. Even, when you delete data from your system, it leaves fragments of files all over your hard disk drive. In case you want to safely remove all the remaining fragments, then you can execute the coming command.
diskutil secureErase freespace 3 / volumes / name-of-drive
At place of ‘name-of-drive’ you have to type the name of the drive you want to erase data from.
Is there any Mac terminal command you find very useful and we didn’t mention? Do write us in the comment section! Also, please feel free to share interesting Mac terminal tricks on our social media handles.