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 console or the console? Heck, there was an entire war played out by Nintendo and Sega accurately entitled the Console Wars, but that’s a different story. SNES Playstation 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 from here, or make any , or even in Python (I’ll get to chapter 2 sometime, I promise). push to Heroku commits and pushes to GitHub write a console-based game 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. Don’t let this be you Navigating the Terminal Like a Pro With your Terminal displayed, the first command you can put into the command line is this: whoami 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: pwd Type that in and press enter. What do you see? stands for . Wherever your Terminal is currently point will be displayed and, don’t worry, nothing will be set ablaze. Here’s the next command: pwd print working directory ls stands for . It lists all the files and folders of your current location. If you started from your main directory, 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 with the following command: ls short listing ls long listing ls -l Basically the same command, but with a bit more information. When working with a file with git initialized, another popular command would be: ls -a 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: cd Desktop Also note that you don’t have to type in this entire command. The Terminal is smart enough to assume things, so after typing , you may be able to press Tab and have the rest of the word autocomplete. We live in the future, indeed. cd Des Now that we’re in (or on) the Desktop, let’s make a folder: mkdir new-folder Run one more time and see a brand new folder called that wasn’t initially there. Let’s run and go inside. Then, run one more time just to make sure we made it. ls new-folder cd new-folder pwd From here, let’s make a file: touch index.js The command creates a new file, in our case, a brand new JavaScript file. If using Visual Studio Code, we could set an option to have VSCode open anything in this folder as well: touch code . 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: rm index.js Easy enough. Now we have an empty folder. Let’s try running those two periods to jump back to the Desktop. Try this: cd .. This takes you back up to your Desktop. And now, let’s run one more to delete our : new-folder rmdir 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 Uptime tells you how long your Mac has been running. caffeinate Don’t want your computer to sleep? Hilariously keep it from sleep mode with the command. caffeinate ditto -V /old/work/ /new/work/ The command is super useful if you’d like to transfer a lot of data from one folder to another. ditto clear Lastly, if you’re having trouble everything since you’ve been writing so many commands, the command gives you a blank screen, while still pointing to where you had been previously. This could also be done by holding down and pressing the letter . clear control l Happy coding!
Share Your Thoughts