Basics of the command line

danimal92 profile image Daniel Zaltsman ・2 min read

The command line interface is what developers use to navigate around their directories and manipulate files. This skill is critical for developers because it allows for greater control over your system, whether it's using npm to install packages and ruby gems, using git, or using it for direct control over your files.

In this short lesson, it's assumed that you are either running a Mac or Linux based OS. They are almost 100% the same, and the commands I'm going to show you are definitely no different. Open up the terminal on your computer and we'll get started.

General structure

Alt Text

As you can see, this is the general structure of a command. What we need to look at here is the command, option, and argument. The command is the action taking place on the specific argument. Options are there to give additional instructions to the command, such as forcing a delete if there may be complications.

Whenever you see you a dollar sign with some text, this means that it's a terminal command, and whatever text comes after the the dollar sign is what you're going to type into the terminal.

$ whoami

$ whoami

This command displays the username of the current user.

$ pwd

$ pwd

This command is going to show you which directory you're currently in/accessing. It stands for "Primary working directory."

$ ls

$ ls

This command allows you to list all the files of the directory you're accessing.

$ cd

This stands for "Change Directory", and it is how we maneuver around our system. If you wanted to go to a specific folder, you need to type out the path of the folder you want to go to, like so:

$ cd /Users/Dan/Desktop/

If you knew your desired location was in this directory's parent directory, you can type:

$ cd ..

If the directory is in the directory that you're accessing, you can type:

$ cd ./[dir_name]

$ touch

touch example.txt

This command allows you to create a file inside of the directory you're accessing. The file type needs to be specified.

$ rm

$rm example.txt

User giveth, and user taketh away. This is the remove command. It is able to delete a single or multiple files at once. In order to remove an empty directory, you can use rmdir, like so:

$rmdir dir_name

If you wanted to remove non-empty directories, you can use rm with two options: -r(recursive) and -f(force):

$rm -rf dirname

Posted on by:

danimal92 profile

Daniel Zaltsman


Full stack developer with a passion for problem solving and creating products that are useful to the everyday consumer.


markdown guide