When I first started out as a software tester, I would always get nervous when I had to do anything with the command line, and I was so impressed when my coworkers could type tiny commands and get dozens of lines of text in response. The one thing that helped me when learning the command line was a course I took in Linux. I was confused for much of the course, but I did manage to learn some commands, and over the years I’ve been able to gradually expand my knowledge.
The command line is hugely helpful when you want to navigate through your system’s folder structure, create new folders or files, or execute runnable files. In this post, I’ll be walking you through some simple commands that can help you get started using the command line like a pro. Most of the commands I’ll be sharing will work in both Mac and Windows; when there are differences between the two, I’ll point them out.
First, let’s look at some useful keys:
The up arrow
The up arrow copies whatever command you just ran, and if you click on the up arrow more than once, you can cycle back through all of the commands you have run so far. For example, if you ran these three commands:
and then you were to click the up arrow, you’d see cd .. . If you clicked the up arrow again, you’d see cd Documents, and if you were to click it a third time, you’d see ls.
The up arrow is really helpful for those times when you ran a complicated command and you need to run it again, but you don’t feel like typing it all over again. Simply click the up arrow until you’ve returned to the command you want, then click Return to run the command again.
The tab key
The tab key has auto-complete functionality. To see how this works, let’s imagine that you have a folder called MyFolder that contains three sub-folders:
If you wanted to navigate from MyFolder to graduationPics using the cd command (more on this later), you could simply type:
and then click the tab key. The folder name will auto-complete to graduationPics.
This command is helpful when you don’t feel like typing out an entire folder name. Typing just the first few letters of the folder and hitting tab, then Return, is a really fast way to navigate.
In order for the auto-complete to work, you need to type enough letters that there’s only one possible option left when you click the tab key. For example, when you type
and then click the tab key, the command line doesn’t know if you mean LettersToDad or LettersToMom. The Windows command line will cycle through the possible options as you repeatedly click the tab key. In Mac, if you click the tab key a second time, it will return your possible options.
Next, let’s learn some navigation skills:
The command prompt: The command prompt is a symbol that indicates that the command line is ready to receive commands. In Mac, the command prompt looks like this: $. In Windows, the command prompt looks like this: >. The command prompt is preceded by the working directory.
The term working directory refers to whatever directory (folder) you are in when you are using the command line. When you first open the command line window, you’ll be in your home directory. This is your own personal directory. For example, in Windows, my personal directory is C:/users/kjackvony. In Mac, my personal directory is /Users/K.Jackvony, but the directory location will display only as ~ , which means the home directory.
ls or dir
This command – ls in Mac and dir in Windows – will list all the files and folders in your working directory.
cd <folder name>
This command will change your working directory to the folder you specify. For example, if you said cd Documents, your working directory would change to the Documents folder.
This command moves you up one level in the directory.
Let’s look at an example. I am using a Mac, so I’ll use ls rather than dir.
1. I begin in my home directory:
2. I type ls to see what’s in my home directory, and I get this response:
3. I type cd Documents, and my working directory is now the Documents folder:
4. I type ls to see what’s in my Documents folder, and I get this response:
Blog Post Notes
Images for Testing
5. I type cd “Blog Post Notes” (I’m using quote marks because the directory name has spaces in it), and my working directory is now the Blog Post Notes folder:
Blog Post Notes$
6. I type cd .. and I’m taken back to the Documents folder:
7. I type cd .. again and I’m taken back to my home folder:
Now that you see how the example works, take some time to try it in your own command line, with your own folders! Remember that if you are using Windows, your prompt will look like a > rather than a $, and you’ll want to type dir instead of ls to see what’s in your working directory.
Next week we’ll continue the command line adventure by learning some more navigation skills and how to create our own files and folders.