There’s a movie from 2004 where Tom Hanks plays a man from the fictitious country of Krakozhia. Hanks’ character, Viktor Navorski, is forced to live inside of JFK airport’s terminal since his passport is no longer valid.
While using Mac’s Terminal may not be as heart-wrenching as being forced to spend months inside of an airport, there’s a particular anxiety that comes from a blank screen that lacks any sort of GUI or prompt to tell you how to maneuver. However, mastering the Terminal pays dividends as a developer, so it’s definitely in your best interest to level up.
What is the Terminal and How Do I Get There?
The Terminal is a Mac program that acts as an interface to the console. And what is the console, you ask? Well, it’s the whole system being used, so in this case, probably your laptop. Remember back in the 90’s when video game machines were referred to as the SNES console or the Playstation console? Heck, there was an entire war played out by Nintendo and Sega accurately entitled the Console Wars, but that’s a different story.
To get to the Terminal, hold down command and press spacebar. Then, type in Terminal (actually, using the spotlight search is one of the biggest shortcuts for Mac users). Once you open the Terminal, it will look pretty bare, but trust me, it’s lot smoother to push to Heroku from here, or make any commits and pushes to GitHub, or even write a console-based game in Python (I’ll get to chapter 2 sometime, I promise).
For now, let’s just run through the basics of how to navigate around the Terminal without setting fire to your computer. Leave that to that dog meme.
Navigating the Terminal Like a Pro
With your Terminal displayed, the first command you can put into the command line is this:
No surprises there. Your computer will tell you who you are, based on what you initially set your computer up as. But now, let’s get to the more practical:
Type that in and press enter. What do you see? pwd stands for print working directory. Wherever your Terminal is currently point will be displayed and, don’t worry, nothing will be set ablaze. Here’s the next command:
ls stands for short listing. It lists all the files and folders of your current location. If you started from your main directory, ls may have given you listings such as the Desktop, Documents, or Downloads. Oh, and in case you wanted to see a little bit more information about these files and folders, you can also see what’s called the long listing with the following command:
Basically the same command, but with a bit more information. When working with a file with git initialized, another popular command would be:
Similarly, this lists whatever is in the current folder, but listing ‘a’ allows even hidden files (such as anything that starts with a period, like your .gitignore and others) to be displayed.
Next, let’s move into your Desktop folder. This can be done with the ‘change directory command:
Also note that you don’t have to type in this entire command. The Terminal is smart enough to assume things, so after typing cd Des, you may be able to press Tab and have the rest of the word autocomplete. We live in the future, indeed.
Now that we’re in (or on) the Desktop, let’s make a folder:
Run ls one more time and see a brand new folder called new-folder that wasn’t initially there. Let’s run cd new-folder and go inside. Then, run pwd one more time just to make sure we made it.
From here, let’s make a file:
That period basically means everything in the current folder. Similarly, running two periods will have you jump upwards from your current location. But before we do that, let’s try deleting this file we just made:
Easy enough. Now we have an empty folder. Let’s try running those two periods to jump back to the Desktop. Try this:
This takes you back up to your Desktop. And now, let’s run one more to delete our new-folder:
And voila, we’ve successfully created a folder with a file inside, then delete both the folder and file. Getting the hang out this yet? It takes sometime, but becoming a Terminal power user should definitely be on your bucket list.
Here are a couple more commands that may be interesting to check out:
Uptime tells you how long your Mac has been running.
Don’t want your computer to sleep? Hilariously keep it from sleep mode with the caffeinate command.
ditto -V /old/work/ /new/work/
The ditto command is super useful if you’d like to transfer a lot of data from one folder to another.
Lastly, if you’re having trouble everything since you’ve been writing so many commands, the clear command gives you a blank screen, while still pointing to where you had been previously. This could also be done by holding down control and pressing the letter l.