Command Line Basics

Introduction

Feeling scared of the command line? You’re not alone. We have this image of developers staring intently at a black screen with white or green text flashing across as they wildly enter incomprehensible commands to hack into the corporate mainframe (no doubt while guzzling soda and wiping neon orange Cheetos dust off their keyboard).

That black screen or window is the command line interface (CLI), where you’re able to enter commands that your computer will run for you. While there’s no need for you to reenact the scene above, working with the command line is a critical skill for you to learn as a developer. The command line is like our base of operations, from which we can launch other programs and interact with them. It has a syntax of its own to learn, but since you’ll be entering the same commands dozens of times, you’ll quickly pick up the commands you need most.

In this introductory lesson to the command line, you’ll learn how to navigate around your computer and how to manipulate files and directories (also known as folders) directly from the comfort of the command line. You’ll soon see that this isn’t as difficult as you may think. The commands you will learn in this lesson are very straightforward, so don’t be intimated by the prospect of using the command line for the first time.

Why learn this now?

You will be making heavy use of the command line throughout this curriculum, and the upcoming installations project will require you to install many different software programs using the command line. Additionally, you will primarily be using Git within the command line (more on this later). As part of the bigger picture, you may well be using the command line on a daily basis in your career as a software developer, making it an indispensable skill in your toolset.

Learning Outcomes

By the end of this lesson, you should be able to do the following:

  • Describe what the command line is.
  • Open the command line on your computer.
  • Use the command line to navigate directories and display directory contents.
  • Use the command line to create a new directory and a new file.
  • Use the command line to rename or destroy a directory and a file.

Assignment

Note: Many of these resources assume you’re using a Mac or Linux environment. You can either skip ahead to the installations section and follow the instructions to install Linux or use an online IDE like AWS Cloud9, which provides a terminal window that you can use to practice.

  1. Read through chapter 1 of Conquering the Command Line.
  2. (Optional) If you’d like some more practice, complete the first 2 sections of this interactive Codecademy course to get practice navigating and manipulating directories and files.

Exercise

In this exercise, you will practice creating files and directories and deleting them.

  1. Create a new directory in your home directory with the name test.
  2. Navigate to the test directory.
  3. Create a new file called test.txt. Hint: use the touch or echo command.
  4. Navigate back out of the test directory.
  5. Delete the test directory.

That’s it–you’re done with command line basics! If you commit to doing most things from the command line from here on out, these commands will become second nature to you. Moving and copying files is much more efficiently done through the command line, even if it feels like more of a hassle at this point.

Additional Resources

This section contains helpful links to other content. It isn’t required, so consider it supplemental material for if you want to dive deeper into something.

  • The free online book Learn Enough Command Line to Be Dangerous is a great resource for mastering the command line. It goes into more depth than you really need at this point, so just focus on chapters 1 and 4. Feel free to refer to the rest of the book (it’s great!) whenever you like.
  • ExplainShell.com is a great resource for if you want to deconstruct a particularly strange shell command or learn how Bash works through guess-and-check.

Knowledge Check

This section contains questions for you to check your understanding of this lesson. If you’re having trouble answering the questions below on your own, clicking the small arrow to the left of the question will reveal the answers.

What is the command line?
    • The command line is a way to interact with the computer using specific words called "commands".
How do you open the command line on your computer?
    • On Linux: Open the programs menu and search for "Terminal". You can also open the terminal by pressing CTRL + ALT + T.
    • On Mac: Open your applications folder and find "Terminal".
How can you navigate to a particular directory?
    • You can use the cd command to change directories.
Where will cd on its own navigate you to?
    • On Linux and Mac, it will navigate you home.
Where will cd .. navigate you to?
    • It will navigate you "up" one folder, that is, into the parent of the current directory.
How do you display the name of the directory you are currently in?
    • On Linux and Mac, use the pwd (print working directory) command.
How do you display the contents of the directory you are currently in?
    • On Linux and Mac, use the ls command. Use ls -l to display the files in a list.
How do you create a new directory?
    • You can do this using the mkdir command.
How do you create a new file?
    • On Linux and Mac, use the touch command, e.g., touch new-file.txt.
How do you destroy a directory or file?
    • On Linux and Mac, use the rm command. To destroy folders, use rm -r or rmdir.
How do you rename a directory or file?
    • On Linux and Mac, use the mv command, e.g., mv folder/old-file.txt folder/new-file.txt.

Web Development 101

Command Line Basics

Have a question?

Chat with our friendly Odin community in our Discord chatrooms!

Open Discord

Are you interested in accelerating your web development learning experience?

Get started

Thinkful

  • 5-6 months

    5-6 months

  • Job Guarantee

    Job Guarantee

  • 1-on-1 Mentorship

    1-on-1 Mentorship