HOLIDAY SALE! Save 50% on Membership with code HOLIDAY50. Save 15% on Mentorship with code HOLIDAY15.

2) Tools of the Developer Trade Lesson

What is the CLI?

7 min to complete · By Ryan Desmond

The CLI is a direct line of communication between us developers and the underlying operating system you're working on. It allows us to run commands to accomplish tasks - without needing to use any application or user interface that someone else designed.

Why Use CLI?

As a software developer, you must become comfortable using the command line interface (CLI, aka "the terminal"). The CLI (or terminal) can be a bit intimidating at first but don't worry - in no time; you'll be whipping around in there like you're the master of the universe! :)

What are CLI Commands?

Even though there is an enormous list of possible commands in the CLI, many are constantly used for basic functionality. Before entering a command, there are three important things:

  1. Open a terminal window.
  2. Hit the Enter button after writing each command below.
  3. Update all fields wrapped in carrots < >.

The commands below demonstrate basic CLI usage for a Linux/Mac OS, or Git Bash in Windows.

List Contents of the Current Directory

Show every file and folder (directory) inside the current working directory.

ls

To list the contents of the current directory, including extra information, add the a' and l` flags. Here, the "a" and "l" are arguments that you're passing to the "ls" command. Arguments always follow the "-".

ls -al

Change Directories

Change your current working directory to another place on your hard drive.

cd /Users/<your\_machine\_user_name>/Desktop

For example, I am moving to my Desktop:

cd /Users/Robert/Desktop

Move Up One Directory

Moving up one directory is equivalent to moving outside the directory that you're currently inside.

cd ../

Move To Your Home Directory

Move to the home directory of the currently logged-in user.

cd ~

Move to the Root Directory of Your Machine

Move to the machine's root directory, which is the highest directory possible.

cd /

Move to the Last Directory You Were In

Move to the last directory that you were in. This is like the back button!

cd -

Print the current working directory (to make sure you are where you think you are!).

pwd

Copy a File from One Place to Another

Copy a file from one directory to another.

cp </path/to/existing/file.txt> </path/to/new/location>

Recursively Copy a Directory from One Location to Another

Copy a directory and everything inside of it to another location. Without the r flag, the cp command will not work on a directory.

cp -r /path/to/existing/folder /path/to/new/location

Move a File from One Place to Another

Move a file's location from one place to another.

mv /path/to/existing/folder /path/to/new/location

Recursively Move a Folder from One Location to Another

Move a folder and everything inside from one place to another.

mv -r /path/to/existing/folder /path/to/new/location

See the Instruction Manual for Any Command

Have the documentation printed in the terminal for any command.

man <command>

Create a New Directory

Create a new directory with the name you provide.

mkdir <directory_name>

Delete a File

Delete a file from your machine that is in the current working directory.

rm <file_name>

Delete a File in a Different Directory

Delete a file from your machine that is in a different directory.

rm </path/to/file_name>

Delete a Directory and All Its Contents Recursively

Delete a folder and everything inside from your machine.

rm -r </path/to/directory_name>

Summary: What is CLI?

  • The CLI stands for command-line interface
  • The CLI is the direct form of communication with your machine

List of Basic Commands

  1. List the contents of the current directory
  2. Change directories
  3. Move up one directory
  4. Move to your home directory
  5. Move to the root directory of your machine
  6. Move to the last directory you were in
  7. Print the Working directory
  8. Copy a file from one place to another
  9. Recursively copy a directory from one location to another
  10. Move a file from one place to another
  11. Recursively Move a Folder from one location to another
  12. See the instruction manual for any command
  13. Create a new directory
  14. Delete a file
  15. Delete a file in a different directory
  16. Delete a directory and all its contents recursively

Now you know how to move around and interact with your machine without the help of an application like Finder!