Handy Terminal Commands For Mac

Posted on
Handy Terminal Commands For Mac Rating: 3,9/5 2204 votes

If you’ve been using a Mac for any length of time, you know that it’s more than just a pretty point-and-click, window-and-icon interface. Beneath the surface of OS X is an entire world that you can access only from the command line. Terminal (in your /Applications/Utilities folder) is the default gateway to that command line on a Mac. With it, instead of pointing and clicking, you type your commands and your Mac does your bidding. Why would you want to do that? For almost all of your computing needs, the regular graphical user interface is enough. But the command line can be handy when it comes to troubleshooting your Mac, to turn on “hidden” settings, and other advanced chores.

Mac Commands

Many of the hints we publish on the website require the use of the command line. It’s a good idea for anyone who isn’t an utter beginner to be familiar with it. If you aren’t already familiar with OS X's command-line interface, this week we'll get you up to speed. The plan is to cover the most important commands you need to know and show you how to use them. First up: How to navigate the file system from the command-line prompt. The prompt By default, when you open Terminal, the first thing you’ll see is something like this: Last login: Tue Apr 23 13:40:35 on ttys000 walden: kirk$ The first line shows the last time you logged into your Mac via the command line; that’s the current time, when you’re using Terminal. The second line is the prompt, and while it can change from system to system depending on configuration, by default it contains several bits of information.

In my prompt, walden is the name of my Mac (same as the name in the Sharing pane of System Preferences), and kirk is my user name. The shows where I am in the file system of my Mac; is a shortcut that means the current user’s home folder. (In the Finder, that’s the folder with your user name and the house icon.) Finally, the $ is a character that the bash shell (the default interface that Terminal uses) displays to indicate that it’s ready to accept a command.

What’s in a folder When you first get to the command line, you’re in your home folder. While you’re there—or when you’re in any folder ( directory in Unix-speak)—you might want to know what’s in it. To do that you use the ls (or list) command. Type ls and press the Return key, and you’ll see the folders (and/or files) in the current directory. The output of the plain ls command is pretty sparse; it shows you the names of files and folders contained in the current directory (including some familiar ones such as Movies, Music, Pictures, and so on). Fortunately, you can add a number of optional switches to the ls command that allow you to see more information.

So, for example, try typing ls -l (that’s a lower-case L), then pressing Return.

Hack The Finder The Finder can be hacked a bit using the Terminal, of course, so we figured we could show you a few tricks, too. Here’s how to hack up the Finder a bit to make it work better for you. Show Hidden Files Sometimes you just want to see it all, right? The Finder hides many configuration files in the finder, some of which you might want to get into to change things.

Most of the time, these files should stay hidden or left alone, but we’re not interested in playing it safe all the time. If you want to see all the files on your Mac for your own reasons, launch Terminal and type or paste in the following command: defaults write com.apple.finder AppleShowAllFiles TRUE Then, issue the command to restart the Finder ( killall Finder) and hit the Return key. If, after you’ve found the hidden files you were looking for, you want to return the Finder to its pristine, hidden-file state, simply do the same thing, except change TRUE to FALSE, and you’ll be good to go. Change Screenshot Formats Sometimes a JPG is all you need.

Taking a screenshot in OS X is as simple as hitting Command-Shift-3 for the whole screen, and Command-Shift-4 for a selection portion of your screen. These screenshots end up on your Desktop in the Finder, and by default are PNG files. If you want to change that default to, say, JPG or PDF, simply type or paste the following command into Terminal. Defaults write com.apple.screencapture type file-extension Just be sure to change “file-extension” above with the three letter suffix for the file type you want. So, if you want your screenshots to default to jpeg files, simply type or paste the following: defaults write com.apple.screencapture type JPG, and you’ll be good to go. Show File Path Info Where the heck am I?

Sometimes, it can get confusing as to where you’re at in the Finder, especially if you have a lot of folders open in windows, and they have similar names. A neat way to remind yourself where you are is to enable the Path View in the title bar of your Finder windows. To do so, simply enter the following into your Terminal app. Defaults write com.apple.finder FXShowPosixPathInTitle -bool YES Now your Finder windows will all show you the file path structure, so you’ll be able to figure out where exactly you are when you get lost in a plethora of open folders and files.

Hack The User Interface Now, let’s look at some commands you can issue in the Terminal to mess around with the user interface, to help you use your Mac the way you want, rather than the way they want. Whoever they are.

Handy terminal commands mac

Disable Window Animations Snappier on that older Mac, for sure. Mountain Lion has a window animation that make things look slick, but can slow down vital workflow, especially on older Macs. To get rid of this subtle but occasionally annoying feature, zoom up to open animation, and issue the following command into your Terminal app: defaults write NSGlobalDomain NSAutomaticWindowAnimationsEnabled -bool false Now the windows will just appear without any opening animations, which should help things feel a bit snappier when running OS X on an older Mac. Change false to true to bring it back. Get Rid Of Smooth Scrolling Direct scrolling is the new black. When you launch a Safari window that needs scrolling and hit the space bar, OS X is set up to animate the scrolling down motion, so it feels smooth and silky. Some users complain about this effect being jerky and unattractive on Retina Macbooks, and would like to disable it.

All you need to do is issue the following command into Terminal: defaults write -g NSScrollAnimationEnabled -bool NO Now, when you hit the space bar in Safari or other scrolling windows, it will jump right to the next area on the page, rather than animating down. Change NO to YES to get it back.

Dump The Rubber Banding Effect Too bouncy! When you’re scrolling up or down in any OS X application, including the Finder, you may notice a sort of bouncy, rubber-band effect when you scroll past the top or bottom of a page or list too quickly. This mimics iOS beahvior, which is aesthetically pleasing, but it can be annoying at times, or slow down your process on an older Mac. To get rid of this feature, type or paste the following Terminal command: defaults write -g NSScrollViewRubberbanding -int 0 Now this only works in some apps, so you’ll have to quit them and relaunch to make sure. Safari or Chrome don’t seem to lose the effect, but Finder and Evernote do, so play around with it to see if the apps you want to disable this within will work. Enable Key Repeats Get rid of that annoying alt character popup. It used to be simple to get a repeated key on your Mac; just hold down any key and it would repeat after a certain amount of delay time.

Terminal

Now, however, in many OS X apps like TextEdit, you can’t do that anymore, as an alternate character popup menu will appear if you hold down a key that has those associated with it. If you want to get rid of that popup feature, and get your key repetition back, simply issue the following command in Terminal: defaults write -g ApplePressAndHoldEnabled -bool false Now you can hold down any key and get a repeat. Make Your Mac More Secure Now, we’re going to spend a little time with Terminal commands to make your Mac just a bit more secure and private. Feel free to follow along at home.

Read more at Erase Free Hard Drive Space Securely Even the NSA won’t be able to see what’s in your free space. When you delete files from your Mac’s hard drive, they don’t actually go anywhere. What gets deleted is your Mac’s ability to use them in any functional way. When new files are put on the Mac, they might (or might not) overwrite some or all of the older, already-trashed files.

Cool Mac Terminal Commands

To keep your files private, you might want to securely delete files from the Trash, and you might also want to delete all the files from the free space on your Mac. To do so, simply type or paste the following command into Terminal: diskutil secureErase freespace 3/Volumes/hard-drive-name Replace “hard-drive-name” with the actual name of your hard drive, and then hit enter. You’ll get a progress bar, and if you have a big drive, it will take some time, as it overwrites each sector 35 times, five times as much as the US Department of Defense recommends, so you can assume it’s safely removed. This will get rid of any lingering files that you’ve already thrown away on your Mac, but didn’t do so securely. Reset Privacy Data On Your Mac Less sharing = more privacy. We all add new apps all the time, and in our socially-networked world, it’s hard not to jsut give the apps the permissions they need to run, and then move on.

Sometimes, though, you might want to just revoke all app access to your private data and start over from scratch. In OS X 10.8 Mountain Lion, you can use Terminal to do just that. You’ll be revoking access to specific data services for all apps, one data service at a time. So, to revoke access to the Address Book, for example, you’ll want to enter the following command into Terminal: tccutil reset AddressBook This should revoke all access to Contacts data from your Address Book. For something like your Location Data, enter the following: tccutil reset CoreLocationAgent You can get a full list of these types of services by typing launchctl list into Terminal. There is, of course, a Privacy preference pane in the System Preferences app, but this is a bit more direct. And geeky, too!

Terminal

Reschedule Time Machine Backups Seriously, every FIVE minutes? That’s a bit intense.

A core feature of any data security plan is the backup system you use. Mac OS X’s Time Machine backups are fantastic and automatic, making sure your stuff is backed up on the fly, every hour. If you want to change the interval at which it backs your stuff up, however, you can do that via Terminal. Simply enter the following command into your Terminal app. Sudo defaults write/System/Library/LaunchDaemons/com.apple.backupd-auto StartInterval -int 1800 You’ll need to enter your admin password here as you’re invoking the Super User command, sudo.

The 1800 there at the end will change your Time Machine backups to every 30 minutes, as it is an interval of seconds. To change it to back up every 15 minutes, use 900 in that spot.

If you want to change it back to every hour, simply replace the 1800 in the above command to 3600. Hack The Dashboard Now, let’s look at the Dashboard with its widgets and things and see what we can do to hack it a bit. Read more at Put Your Dashboard Widgets On The Desktop Maybe I’ll use the calculator a bit more, now?

Honestly, I don’t use the Dashboard too much, as their functionality is limited, and it’s just faster to open a dedicated app that I can switch to with Command-Tab. However, maybe if I was able to drop them on the Desktop, I’d end up using a few of the more useful ones more often. It’s worth a shot, right? All you need to do to make this happen is type or paste the following command into the Terminal app: defaults write com.apple.dashboard devmode YES Then enter the following command, as well.

Killall Dock Once that’s done, launch Dashboard with F12 (or whatever other keyboard shortcut you have defined for the Dashboard), and find the widget you want out of there. Click and hold on it, move it a bit, and then hit F12 again to dismiss the Dashboard. The widget should then appear above whatever app you’re in, and stay in the foreground.

To get rid of the widget from the Desktop, and put it back in the Dashboard, do the same thing in reverse. Click and hold on the widget, hit the F12 key to bring up the Dashboard, move the widget around a bit, and then release the mouse button. Widget replaced. Get Rid Of Dashboard Altogether Maybe you don’t like the Dashboard, have RAM issues, or otherwise want to just kill it completely. That’s not horribly difficult; just use the Terminal. Type or paste the following command into the Terminal app, then hit Enter. Defaults write com.apple.dashboard mcx-disabled -boolean YES Then, go ahead and restart the Dock again, with the following: killall Dock Now you’ll have no more Dashboard.

So sad, see ya later. If you want to bring it back, of course, there’s a simple command to bring it back, replacing the YES above with a NO: defaults write com.apple.dashboard mcx-disabled -boolean NO Then killall Dock and you’re good to go. Make Unsupported Features Work Again Ok, so let’s take a look at a few of the newer features of the OS X world, and how to make them work on older, unsupported Macs using some Terminal magic. Enable AirDrop Over Ethernet You can do it! AirDrop is one of those newer features, introduced in OS X Mountain Lion, that lets you share files to other supported AirDrop Macs on the same WiFi network as yours.

Other folks can do the same thing to your Mac, as well. Unfortunately, AirDrop doesn’t work on older Macs, nor over Ethernet, by default. If you’d like to try to make it work on your older Mac, simply past or type the following into your Terminal app: defaults write com.apple.NetworkBrowser BrowseAllInterfaces -bool true Then, log out of your Mac and log back in to check and see if it worked.

Now, AirDrop should work on your older, unsupported Mac as well as over Ethernet. If you ever want to turn this ability off for any reason, simply replace ‘true’ in the command above with ‘false.’ Enable Time Machine For Unsupported Network Volumes I wish I had a real time machine. Time Machine rocks, mainly because it backs stuff up on our Macs without us having to do much of anything to make it regular and consistent. One issue, hoever, with Time Machine is that it only works with supported drives on the network. Like Apple’s own Airport Extreme with Time Machine. What if you have a network-attached storage device that you want to back your data up to? These drives tend to be a lot less expensive per storage unit than anything Apple sells, but they aren’t directly supported by Mac OS X.

To make it so you can see these unsupported drives within the Time Machine system, all you need to do is launch Terminal and then issue the following command: defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1 This tweak isn’t officially supported by Apple, and as such won’t have any guarantee of working as well as an Apple solution. However, if you’re willing to risk it, this might be a great thing to try.