Basics of Something Basic: The Command Line

To start off, what even is the command line? Your command line is a text interface for your computer’s OS (operating system). With it, you can do so many things, travel deep into your computers files, edit, remove and even add some files too. This article will show you some simple tips and tricks for making the most of the command line. Let’s dive in!

Making a List, Checking it Twice

The command line organizes your computer’s files and directories into a tree-like map. The very first directory is known as the root directory and it is the parent of all parents. Each directory that follows can contain other files and other directories. Now, if we want to see what files are in a directory (folder) we can run the command ls in the command line. If you run this when you first open a new terminal window you will probably see something that looks like this.

some of what i see when i run ls in my root directory

Getting Lost in the Deepest of Directories

Before we go about finding our way deep into the trenches of directories I’m going to teach you how to check where you are. The command pwd will tell you right where you are. Our next command cd stands for change directory and just as you would click on a folder in whichever file-finder your computer may use (Windows Explorer for Windows and Finder for Mac), cd can take you through your directories with ease. Say I am in my root directory and I want to change into my Development directory. I would use a command like this:

cd Development

Simple enough, huh? Here’s a quick example of how that would look using all of the commands we’ve discussed so far.

using cd, ls and pwd

cd can take us down one directory at a time or we can double it up and travel even further down. We can go down as many directories as we want at once.

cd Development/code/Mod1/rmi-frontend/src/alt/arts-and-crafts

We could seriously go down as far as we might like but what goes down must come up. If you want to travel the other way back up you can use this command to travel up one level and the following command to travel up 2 levels at once.

cd ..
cd ../..

Wooh! All of that has treated us to some serious traversing. Now lets learn a bit about creating directories and files right from the command line.

traversing with cd

Making some dirs

Oftentimes you’re on such a roll when you’re working with the command line you don’t have time to use another piece of software to create a directory or a file, you need it quick and you need it now. Thats where mkdir (make a directory) and touch come in. First make sure you are inside of whichever directory you’d like to create a new directory inside of, (hint hint you can use pwd to double check) and then use the following command mkdir <file-name> and voila! A new directory appears right before your eyes. Here is an example of how you would create a directory, change into that directory and then create a new file inside of that directory.

mkdir trvlr
cd trvlr
touch index.js

touch creates a new file for you inside of whichever directory you are inside of. Pretty simple but pretty magic, gotta love good a good old fashioned command line, line of code.

Simple Helper Commands

These are just a few simple helper commands that can be used to make your experience with the command line a little bit more enjoyable. clear can be used to clear your busy terminal window and make it nice and readable again. tab can used to autocomplete an entry while typing, so for instance if i was typing out a command..

cd Dev[tab]
cd Development

I hit the tab button on my keyboard and saved myself so much typing (not that much but still though). In addition to these two slightly helpful tools, you can also use the up and down arrows on your keyboard to cycle through your previous commands.

Wrapping it up..

You can utilize all of these commands to traverse through your entire computers filesystem, up, down and back around. You now can even create a few new files in just a moment now. There is still plenty to learn about the command line and just how powerful and enjoyable it truly is. So go ahead and research some more about everything that the command line can do!

Software Engineering Student at Flatiron School

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store