Skip to main content

Command Line Cheat Sheet – CLI Commands for Easy Reference

What Is a Command Line Interface?

A command line interface (CLI) is a computer's text interface allowing you to type commands for the computer to run.

Below is an image of the Windows PowerShell terminal application.

Windows PowerShell
CLI

The Windows PowerShell command-line interface
note

Command line interfaces are sometimes called terminals.

Syntax of a Terminal's Command

A terminal's command comprises three components: a utility, a flag, and an argument.

Here is the syntax:

utility -flag argument

Note the following:

  • A utility tells the computer the function you want it to run. Many CLI commands require only a utility.

  • A flag alters the utility's mode of operation. In other words, we use flags to specify preferences on how computers should run the utility command.

  • Flags always start with one or two hyphens (-).

  • Flags are typically written after the utility command and before an argument.

  • An argument says the exact action the utility command should perform.

Let's now see some of the widely used commands.

Directory Management Commands

Below are the commands for creating, accessing, and deleting directories on your system.

info

Directories are sometimes called folders.

DescriptionCommand
Check the current working directory's path
pwd
Change directory from the current working directory to another-directory
cd another-directory
Change directory from the current working directory to its parent directory
cd ..
note

The whitespace between cd and .. is essential.

Copy directory1 into directory2
cp -r directory1 directory2
note

The duplicated directory will overwrite an existing directory with the same name.

Remove a directory permanently from your system
rm -r name-of-directory-to-delete
Remove a directory permanently and forcefully from your system
rm -rf name-of-directory-to-delete-forcefully
List out the current directory's content
ls
List out the current directory's content using the long listing format
ls -l
List out all the current directory's content—including all hidden content
ls -a
List out all the current directory's content using the long listing format. Also, include all hidden content
ls -la
Make a new directory
mkdir name-of-new-directory

Files Management Commands

Below are the commands for creating, accessing, and deleting your system's files.

DescriptionCommand
Create a new file
touch name-of-new-file
Create test1.md file
touch test1.md
Create test1.md, test2.md, test3.md, and test4.md files
touch test{1..4}.md
Copy a file into a specific directory
cp file-to-copy directory-to-copy-file-into
note

The duplicated file will overwrite an existing file with the same name.

Display all the content in a specific file
cat filename
Display some of the content in a specific file
less filename
tip
  • Press the 'Enter' key (or the up and down keys) to show more content.
  • Press the Q key to exit the file space.
Display the first ten (10) lines of a specific file
head filename
Display the last ten (10) lines of a specific file
tail filename
Move a file into a new directory
mv file-to-move directory-to-move-file-into
note

The moved file will overwrite an existing file with the same name.

Remove a file permanently from your system
rm name-of-file-to-delete
Remove a file permanently and forcefully from your system
rm -f name-of-file-to-delete-forcefully
Rename a file
mv current-file-name new-file-name

Networking Commands

Below are the commands for downloading and testing network resources.

DescriptionCommand
Download a file
curl -O url-of-the-file
note

The -O flag must be in uppercase.

Test a network host's reachability
ping domain-name.com

System Information Commands

Below are the commands for displaying your system's information.

DescriptionCommand
Display the current date and time
date
Display your CPU's information
cat /proc/cpuinfo
Display your memory's information
cat /proc/meminfo
Display your system's disks usage information
df
Display your current directory's space usage information
du
Clear your terminal's content
clear

Your support matters: Buy me a coffee to support CodeSweetly's mission of simplifying coding concepts.

Tweet this cheat sheet