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.
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
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
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 :
To delete your Terminal usage history, enter :
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
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, type
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
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 –
Can you suggest any others that we may not know? If so, let us know in the comments below.