The Mac’s Terminal is at once scary and powerful. It’s like a whole other computer living underneath the pretty interface of macOS. Sometimes, it’s convoluted. Other times, it seems laser-focused, offering a much quicker way to get things done. Instead of clicking and dragging your way through multiple screens, you just type a line of text.
However, the Mac Terminal is pretty intimidating if you’re not used to it. Today we will learn five super-useful Terminal tricks that make getting around much easier.
You’ll see how it can integrate with the Finder, and how you can drag and drop files and folders into a text-based Terminal window.
Mac Terminal tricks and tips
These tricks are like learning to right-click the mouse — they’re the shorthand that makes Terminal much easier to use. Before long, you’re going to look like a badass hacker from a TV cop show.
First, open a Terminal window on your Mac
Terminal is a Mac app. You will find it inside the Applications > Utilities folder. Launch it, and it will probably open a window that looks like a regular TextEdit window, a white pane with black text. You can change the appearance in the app’s preferences.
I find black on white easier to read, but I also like to be able to spot the Terminal window amongst other open windows. So I go for green text on a black background. (You can choose from several preset profiles.)
The Terminal can do pretty much everything your Mac can do in normal use, and more. Usually, you’ll be working on a file, or a folder full of files, and running commands on those files. Most of the following tips show you how to work with files and folders more easily.
How to open a folder in the Mac Terminal
To open a folder, you just type cd (change directory), followed by the folder’s path. For instance, to open the Documents folder in your home directory, just type
cd ~Documents and hit return. You are now “in” your Documents folder. However, you can’t see any of the files inside — yet.
To list all the files in the current folder, type ls (list files) and hit Return. All the files and folders will be listed. How can you tell the difference? The folders are listed first, and the files after. And the files are shown with their file suffix —
interesting file.txt, for example.
But what if you don’t know the path? Or don’t care to type it? After all, you probably have the folder open in a Finder window already. This is the first trick. Just type cd (including the space), and then drag any folder from the Finder into the Terminal window. Its path will be pasted into Terminal, and you can just hit Return to open it.
Open current Terminal path in the Finder
How about the other way around? You’re deep inside some directory on your Mac, and you want to open it in the Finder. This one is even easier. Just type open . (that’s open space period). Then hit Return, and the current folder will open in a Finder window.
The up arrow
Imagine that you typed a long, carefully crafted Terminal command. And now you want to use it again. Perhaps you want to apply the same command to a different file. Do you have to type it all out again? Copy and paste the command? Nope. Just hit the up arrow, and your previously typed command will be added to the current command line, ready for you to edit or reuse.
Keep tapping the up arrow to continue back in time, one command at a time.
Make delete work properly
If you’re used to using the ⌘, ⌥ and ⇧ keys to move the cursor around your text, or deleting an entire line using ⇧ ⌘ backspace, for example, then the Terminal will quickly frustrate you. While ⌥ ← will move the cursor back an entire word at a time, ⌥ backspace deletes just one letter.
There are two options here. One is to tap Escape before tapping the backspace key. That will delete the entire word before the cursor. Or, of you have a path like
~/Documents/Folder/Another Folder/textfile.txt, then Escape Backspace will delete chunks of that path, treating the / characters as spaces.
Or, you can click Edit > Use Option as Meta Key in the menubar (⌥⌘O), and the Option key will modify your shortcuts in the same way it does in a normal text editor.
You won’t realize how deep the ⌘Z undo shortcut is ingrained in your brain until you use Terminal. Pasted the wrong thing into a window? Tough. There’s no undo. Or is there?
The closest equivalent to ⌘Z is ⌃_. Yes, that’s a pain to get used to, but it more or less works. If you paste in a long command or path, then you might need to hit the shortcut a few times before it all goes away, but it sure beats deleting the entire mistake, one letter at a time.
More Terminal tips
If you have any more tips for Mac Terminal noobs, please add them in the comments. Specifically, tricks and tips that will help folks transition from the regular macOS environment to the alien world of the command line.
And, if you are entering this world for the first time, good luck! Hopefully these tricks will smooth your journey.