Mar 16, 2017 For many people, the MacOS Terminal window (or the Command Prompt on Windows) is a scary place to be. It’s viewed by many as the feature only hoodie-wearing Red Bull-guzzling hackers in Hollywood movies use, and if the ordinary man or woman in the street uses it for something, then watch out because the whole world is going to cave in.
For many people, the MacOS Terminal window (or the Command Prompt on Windows) is a scary place to be. It’s viewed by many as the feature only hoodie-wearing Red Bull-guzzling hackers in Hollywood movies use, and if the ordinary man or woman in the street uses it for something, then watch out because the whole world is going to cave in.
- List of my most used commands and shortcuts in the terminal for Mac - 0nn0/terminal-mac-cheatsheet.
- Begin opening macOS Catalina’s Terminal by going to Finder Applications Utilities Terminal. Type one of the following commands into Terminal: To download the latest macOS update, type.
I felt that way for a LONG time, afraid to go anywhere near these windows for fear of permanently killing my computer and setting off Skynet. But then I realized I was missing out on a lot of cool stuff and time-saving features by not learning how to use it.
The mouse or trackpad are both useful in their own way, but nothing beats typing out a command on the keyboard. It’s faster, easier, and doesn’t break your rhythm when you are “in the zone”. A Google search will throw up lots of “cool Terminal commands” articles (almost as many as “where do babies come from?” articles), but with each new incarnation of Mac, some Terminal commands stop working, some become redundant, and new ones are created.
So here are the useful ones I have found. All but one have been tested on MacOS Sierra and they work.
Show Hidden Files On MacOS
As with all other operating systems, there’s a very good reason why you don’t see hidden files by default. Simply because deleting the wrong file would nuke your computer and that wouldn’t be good. So by default, the hidden files are….well, hidden.
But sometimes it may be necessary to view the hidden files, if you are troubleshooting a problem. For example, I cannot get a file in the trash to delete, and it was only after several weeks of cursing in a dozen ancient languages that I finally looked at the hidden files and discovered the stubborn file was coming from a SD card.
So to view the hidden files, fire up the Terminal window and type (or CMD+C and CMD+V)
defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder
Commands For Terminal Mac
And….hidden files become unhidden!
When you have finished, you can conceal the hidden files again, by inputting the same command, but replacing TRUE with FALSE. Please do that. I don’t want you telling me you accidentally deleted a critical system file and now your Mac is kaput.
Copy Contents Of Folder Into a New Folder
Lovers of the mouse and trackpad will be copying their files and folders across different drives, simply by dragging the folder. But you can copy folders and files from one drive to another simply by using a Terminal command.
Start with ditto -v and then put the path of the folder you want to copy, and finally the path of the folder the copied files should end up in. Hit “enter” and let the Mac do its copying thing.
ditto -V /downloads/files/ /usb/files/
Change Screenshot Format
My Macbook churns out screenshots as PNG format, but depending on what you’re doing, PNG is not really the best image format. Sometimes JPG is better or maybe you want GIF screenshots?
Either way, if you are not happy with the format your Mac is making screenshots as, you can change the format by entering the following command. Replace JPG with your desired format (unless you want JPG of course).
defaults write com.apple.screencapture type JPG
killall SystemUIServer
Delete Your Entire Download History
I am a huge online privacy and security fanatic, and when I discovered this one, I was horrified. If I had remained ignorant, some police officer might have discovered that I download David Hasselhoff fan pictures from Google on a regular basis.
Basically your Mac keeps a running log of EVERYTHING that you download. Don’t believe me, enter the following command into Terminal. I’ll wait.
sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'select LSQuarantineDataURLString from LSQuarantineEvent'
See, told you!
But don’t worry, there’s an easy way to wipe that history. Just enter the following command and hit “enter”.
sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'delete from LSQuarantineEvent'
Now enter the first command again, and your download history will be gone. Just be sure to run this command on a regular basis. Especially if you are crossing the US border and are likely to have your computer searched.
Delete Terminal History
If keeping a log of your download history wasn’t bad enough, a log of all your Terminal commands is also kept. Which isn’t as sensitive as your download history obviously, but nevertheless….
To view your Terminal usage history, enter :
history
To delete your Terminal usage history, enter :
history -c
And it’s all gone.
Enable Airdrop On Older Unsupported Macs & On Ethernet
This is the one I didn’t test because I have a MacBook which DOES support Airdrop. But I included it here because it was simply too good to ignore. If you have an older Mac, try it out and see if it works. If it doesn’t, let me know and I will remove this one.
defaults write com.apple.NetworkBrowser BrowseAllInterfaces -bool TRUE
killall Finder
To reverse this, enter the above command, but replace TRUE with FALSE.
Check How Long It’s Been Since You Rebooted Your Mac
I have a really bad habit – I rarely shut down or reboot my Mac. I just put the lid down and put it in sleep mode. Partly because I am just too lazy. But I should do shut down or restart it more often. It blows away all the internal cobwebs, and it is also a sound security policy.
To see how long your Mac has been running since its last shutdown/restart, typeuptime
When I checked, it told me 17 days. Oops.
Order Your Mac To Automatically Reboot When It Freezes
Thankfully my Mac is not at the stage where it freezes on-cue, so technically I haven’t tested this one either. But I have put it into Terminal, and the command was accepted. So I assume it works. I’ll know soon enough when the Mac freezes for the first time.sudo systemsetup -setrestartfreeze on
Basically the command tells the Mac to automatically restart when the system freezes. True, you could just press the “off” button, but this way it’s automated and you don’t have to do anything.
Install Updates Without Launching App Store
To see all available updates to your installed software, it is normal to open the Mac App Store, and head to the Updates tab. But you can completely bypass the App Store and check for updates via the Terminal.
In case you are a newbie to the Terminal, “sudo” is a “super-user” command which gives you complete access and control to all functions of your computer. Running Sudo gives you the security privileges of all other users on your system.
So to find all available updates….
sudo softwareupdate -l
If it finds any updates, run the followinng command to install them.

sudo softwareupdate -ia
Please bear in mind though that it only checks for updates for software downloaded from the App Store. If you have installed software from a third-party website, this command will not check those programs.
Change Default Name Of a Screenshot
When the Mac takes a screenshot, it gives it a pretty ugly looking filename.
That looks pretty crap, so you can change it to something else, something more to your liking. So…
defaults write com.apple.screencapture name 'newscreenshotname'
Obviously replacing “newscreenshotname” with the desired new name you want.
Add a Message In The Login Window
There are many ways to customize your Mac, but one of the best ways is to put a message on your login screen. Some people put their contact information there, in case they lose their laptop and some kind-hearted soul wants to return it. Others (like myself) have funny pithy little remarks.
Since I am a huge Trekkie (and a huge fan of Mr Spock), my screen says….yep, you guessed it…
So to add your message/quote/whatever, type the following (replacing “Live Long & Prosper” with your own desired message).
sudo defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText 'Live Long & Prosper'
If you suddenly decide one day to have no message at all, type the following (basically the same command, but minus any message).
sudo defaults delete /Library/Preferences/com.apple.loginwindow LoginwindowText
Download a File Without a Browser
If someone you trust sends you a download link (say by instant messaging), there’s no need to open a browser to begin that download. You can tell Terminal instead to download it for you.
Obviously replace the URL with the URL of what you want to download.
curl -O https://download.mozilla.org/?product=firefox-52.0-SSL&os=osx&lang=en-US
Create An Empty File For Testing
If you are testing something, or building something, you may need to make a fake file of a certain size. Terminal can make one for you.
mkfile 500mb test.exe
After “mkfile”, just type in the size you want the file (either in KB, MB, or GB), and then the name and file format of the file. The command above will make a 500MB file called test.exe (an empty file of course).
Quit The Finder
It will occur to new Mac users very quickly that there is no easy way to shut down the Finder. You can shut down all other programs, but not the Finder. But if your Mac is running slow, shutting down the Finder can actually free up a lot of much needed memory space.
But if Apple doesn’t give you a default close function, you need to make it yourself.
defaults write com.apple.finder QuitMenuItem -bool true
killall Finder
Now check your Finder menu at the top of the screen, and you will see a “Quit Finder” option at the bottom.
The Finder logo will remain in the Dock but the little dot underneath will now blink out. Also note that the Trash bin will now be inaccessible until you open the Finder again by clicking on the Dock icon.
Clear The Terminal Screen Completely
Finally, to clear your Terminal screen and make it blank again, type –
clear
Can you suggest any others that we may not know? If so, let us know in the comments below.
Hidden behind beautiful Mac screens is the world of Terminal Command lines. Knowing how to use these commands will help you increase your work efficiency in a great way.
Below is a list of the most basic commands divided by purpose of use:
CORE COMMANDS
| Key/Command | Description |
|---|---|
| cd [folder] | Change directory e.g. cd Documents |
| cd | Home directory |
| cd ~ | Home directory |
| cd / | Root of drive |
| cd – | Previous directory |
| ls | Short listing |
| ls -l | Long listing |
| ls -a | Listing incl. hidden files |
| ls -lh | Long listing with Human readable file sizes |
| ls -R | Entire content of folder recursively |
| sudo [command] | Run command with the security privileges of the superuser (Super User DO) |
| open [file] | Opens a file ( as if you double clicked it ) |
| top | Displays active processes. Press q to quit |
| nano [file] | Opens the file using the nano editor |
| vim [file] | Opens the file using the vim editor |
| clear | Clears the screen |
| reset | Resets the terminal display |
CHAINING COMMANDS
| Key/Command | Description |
|---|---|
| [command-a]; [command-b] | Run command A and then B, regardless of success of A |
| [command-a] && [command-b] | Run command B if A succeeded |
| [command-a] || [command-b] | Run command B if A failed |
| [command-a] & | Run command A in background |
PIPING COMMANDS
Macos Command Line Reference
| Key/Command | Description |
|---|---|
| [command-a] | [command-b] | Run command A and then pass the result to command B e.g ps auxwww | grep google |
COMMAND HISTORY
| Key/Command | Description |
|---|---|
| history n | Shows the stuff typed – add a number to limit the last n items |
| Ctrl + r | Interactively search through previously typed commands |
| ![value] | Execute the last command typed that starts with ‘value’ |
| ![value]:p | Print to the console the last command typed that starts with ‘value’ |
| !! | Execute the last command typed |
| !!:p | Print to the console the last command typed |
FILE MANAGEMENT
| Key/Command | Description |
|---|---|
| touch [file] | Create a new file |
| pwd | Full path to working directory |
| . | Current folder, e.g. ls . |
| .. | Parent/enclosing directory, e.g. ls .. |
| ls -l .. | Long listing of parent directory |
| cd ../../ | Move 2 levels up |
| cat | Concatenate to screen |
| rm [file] | Remove a file, e.g. rm data.tmp |
| rm -i [file] | Remove with confirmation |
| rm -r [dir] | Remove a directory and contents |
| rm -f [file] | Force removal without confirmation |
| cp [file] [newfile] | Copy file to file |
| cp [file] [dir] | Copy file to directory |
| mv [file] [new filename] | Move/Rename, e.g. mv file1.ad /tmp |
| pbcopy < [file] | Copies file contents to clipboard |
| pbpaste | Paste clipboard contents |
| pbpaste > [file] | Paste clipboard contents into file, pbpaste > paste-test.txt |
DIRECTORY MANAGEMENT
| Key/Command | Description |
|---|---|
| mkdir [dir] | Create new directory |
| mkdir -p [dir]/[dir] | Create nested directories |
| rmdir [dir] | Remove directory ( only operates on empty directories ) |
| rm -R [dir] | Remove directory and contents |
| less [file] | Output file content delivered in screensize chunks |
| [command] > [file] | Push output to file, keep in mind it will get overwritten |
| [command] >> [file] | Append output to existing file |
| [command] < [file] | Tell command to read content from a file |
SEARCH
| Key/Command | Description |
|---|---|
| find [dir] -name [search_pattern] | Search for files, e.g. find /Users -name 'file.txt' |
| grep [search_pattern] [file] | Search for all lines that contain the pattern, e.g. grep 'Tom' file.txt |
| grep -r [search_pattern] [dir] | Recursively search in all files in specified directory for all lines that contain the pattern |
| grep -v [search_pattern] [file] | Search for all lines that do NOT contain the pattern |
| grep -i [search_pattern] [file] | Search for all lines that contain the case-insensitive pattern |
| mdfind [search_pattern] | Spotlight search for files (names, content, other metadata), e.g. mdfind skateboard |
| mdfind -onlyin [dir] -name [pattern] | Spotlight search for files named like pattern in the given directory |
HELP
| Key/Command | Description |
|---|---|
| [command] -h | Offers help |
| [command] –help | Offers help |
| info [command] | Offers help |
| man [command] | Show the help manual for [command] |
| whatis [command] | Gives a one-line description of [command] |
| apropos [search-pattern] | Searches for command with keywords in description |