The Mac Terminal, also known as a “command line” or “Terminal emulator,” is one of the essential apps on Mac and Linux. It’s an interface for entering commands to receive immediate results and offers direct access to the true power of your Mac.
There are several advantages to using terminal commands to accomplish tasks. Read on for a basic intro to executing Terminal commands and some useful basic commands to get started.
How to Open a Mac Terminal
Using “Spotlight” to open a Terminal on Mac is the quickest and easiest way. Follow the steps below to open a Terminal window:
- In the menu bar at the top right corner of your screen, click on the magnifying glass icon. “Spotlight” will open.
- In the search bar, type “
Terminal
” and hit “Enter.”
The Terminal will open and be ready for use.
Getting to Know the Terminal
The best way to become comfortable with the Terminal app is by understanding how the commands work. So here are a few introductory pointers to get you started:
How to Execute a Command
First and foremost, to run a command, enter its syntax at the cursor, then hit “Return” to run the command.
Things to Remember About Commands
Two points to remember about command are:
- Every command has three components: the command name, arguments that tell the command what resources to work on, and an option that changes the output.
- Most commands are case sensitive. For example, if you want to move a file from one folder to another, you’d use the “move” command “mv” with a lowercase m and v. Here’s how to do just that:
% mv ~/Downloads/MyFile.txt ~/Documents/Work/MyFile.txt
List of Available Commands
For a list of all the available commands, long-press the “Escape” key, then press “Y” to the question asking whether you’d like to see all the options. Then to see more commands, hit “Return.”
How to Flush DNS Cache
There are plenty of reasons why you should consider flushing your Mac’s DNS cache every once in a while. For example, it can help prevent page loading problems and 404 errors. On macOS El Capitan and above, here’s a command to flush the DNS on your Mac:
udo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
How to Download a File Without a Browser?
With a terminal, you can download a file directly from the internet without using a browser. This method is useful when you have a direct download link. Enter the command lines:
cd ~/Downloads/
curl -O [URL]
The command needs a direct download link as an argument (URL).
To download the file to another directory, replace “downloads” with the directory name.
How to Download and Delete your Entire Download History
Mac keeps meticulous records of every single file you’ve ever downloaded. To ensure privacy, knowing how to delete the entire list is useful. To retrieve the list first, enter the following command:
sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'select LSQuarantineDataURLString from LSQuarantineEvent'
And then to delete it:
sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'delete from LSQuarantineEvent'
Now try entering the first command again, and you’ll see an empty list.
How to Display Hidden Folders and Files
To ensure critical files are not deleted by mistake, macOS keeps them hidden, which in principle is a great idea. However, whenever you want to view a hidden file on an external drive, this feature becomes a hindrance. Luckily, with Terminal, you can get around this. Here is the Terminal command that allows you to see hidden files:
defaults write com.apple.finder appleshowallfiles -bool true
You’ll now get to see all hidden files.
How to Copy Contents From One Folder to Another
Using Terminal to copy file contents from one folder to another is fairly straightforward. Here’s what you need to enter:
% cp-R ~/[original]/[folder name]/ ~/[new]/[folder name]/
And swap “original” with the existing directory and “new” for the directory’s name to copy the contents to.
How to Access iCloud Drive
For direct access to your data via your iCloud drive, enter the following command:
cd ~/Library/Mobile Documents/com~apple~CloudDocs/
How to Mac Your Mac Talk
Forget Siri because using this command is even cooler; you can get your Mac to say whatever you want. Get your Mac to repeat after you by using the “say” command followed by the words to say in quotes, for example:
say “HELLO, ALPHR”
How to Keep Your Mac Awake
There are many apps available to disable Mac’s sleep function. If you want to reduce the number of apps installed, you can enter the following Terminal command instead:
caffeinated
This will prevent your Mac from falling into Sleep mode. When you’re ready to allow it to sleep, just press the “CTRL” + “C” buttons.
How to Increase the Frequency of Checking for MacOS Updates?
To ensure that you’re keeping on top of your computer security, you can ask your Mac to check for critical patches and updates more often. Here’s how you’ll tell it to check for updates every day:
defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1
How to Play Tetris
Who doesn’t love a game of Tetris? Many of us can spend hours playing it. If you’re a fan of this classic game, here’s how to access Mac’s secret Tetris game:
- In the Terminal, type “Emacs” and hit “Return.”
- Press the “Fn” and “F10” keys together.
- Press the “T” key followed by the “G” key.
- Eventually, you’ll be asked to “Choose your game.” Tetris is under the “T” option (press “T” then “Return”).
Alternatively, you can choose another gaming classic, like Snake or Solitaire, by following the on-screen instructions.
How to Shut Down Mac
When it’s time to give your Mac a break, enter the following command to shut it down:
$ sudo shutdown -h now
Alternatively, to restart it, enter:
$ sudo shutdown -r now
Taking Command With Mac Terminal Commands
The Mac Terminal command line system offers more control over your MacOS, allowing you to run tasks more quickly and efficiently. To use it just requires getting to grips with the basic commands and functions. Once you’ve become comfortable working with commands, you can use command prompts for more complex and fun tasks.
What kind of tasks do you prefer using the Mac Terminal for? Tell us about your experience using Mac Terminal commands in the comments section.
Disclaimer: Some pages on this site may include an affiliate link. This does not effect our editorial in any way.