The 10 Most Commonly Used Linux Commands

What Is a Linux Command?

A Linux command is a program or utility that runs on the command line interface (CLI) – a console that interacts with the system via texts and processes. It’s similar to the Command Prompt application in Windows.

Linux commands are executed on Terminal by pressing Enter at the end of the line. You can run commands to perform various tasks, from package installation to user management and file manipulation.

Here’s what a Linux command’s general syntax looks like:

bash CommandName [option(s)] [parameter(s)]

A command may contain an option or a parameter. In some cases, it can still run without them. These are the three most common parts of a command:

  • CommandName is the rule that you want to perform.

  • Option or flag modifies a command’s operation. To invoke it, use hyphens (-) or double hyphens (--).

  • Parameter or argument specifies any necessary information for the command.

Keep in mind that all Linux commands are case-sensitive.

Here is the list of basic Linux commands:

  1. sudo command Short for superuser do, sudo is one of the most popular basic Linux commands that lets you perform tasks that require administrative or root permissions. When using sudo, the system will prompt users to authenticate themselves with a password. Then, the Linux system will log a timestamp as a tracker.

Example:

sudo apt update

This command updates your system’s package list using administrative privileges.

  1. pwd command Use the pwd command to find the path of your current working directory. Simply entering pwd will return something like this:

/home/username

This command is useful when you want to know where you are in the file system.

  1. cd command The cd command stands for change directory. It allows you to navigate through different directories in the file system.

Example:

cd Documents

This command changes your current working directory to Documents.

To go back to the previous directory, use this command:

cd ..

To go back to your home directory, use this command:

cd ~

To go to any directory from anywhere, use an absolute path:

cd /home/username/Documents
  1. ls command The ls command lists all files and directories in your current working directory.

Example:

ls

This command will return something like this:

Desktop Documents Downloads Music Pictures Videos

You can also use some options with this command, such as:

  • -a to show all files, including hidden ones.

  • -l to show detailed information, such as permissions, size, and modification date.

  • -h to show human-readable file sizes.

  • -t to sort files by modification time.

Example:

ls -alht

This command will return something like this:

total 28K
drwxr-xr-x 7 username username 4.0K May 17 00:48 .
drwxr-xr-x 5 username username 4.0K May 17 00:48 Documents
drwxr-xr-x 2 username username 4.0K May 17 00:48 Desktop
drwxr-xr-x 2 username username 4.0K May 17 00:48 Downloads
drwxr-xr-x 2 username username 4.0K May 17 00:48 Music
drwxr-xr-x 2 username username 4.0K May 17 00:48 Pictures
drwxr-xr-x 2 username username 4.0K May 17 00:48 Videos
drwxr-xr-x 3 root root 4.0K May 16 23:59 ..
-rw-r--r-- 1 username username 220 May 16 23:59 .bash_logout
-rw-r--r-- 1 username username 807 May 16 23:59 .profile
-rw-r--r-- 1 username username .04 May 16 23:59 .bashrc
  1. mkdir command The mkdir command creates a new directory in your current working directory or a specified path.

Example:

mkdir NewFolder

This command creates a new directory named NewFolder in your current working directory.

To create multiple directories at once, use this command:

mkdir NewFolder1 NewFolder2 NewFolder3

To create a nested directory structure, use this command:

mkdir -p NewFolder/Subfolder/Subsubfolder

This command creates a new directory named NewFolder with two subdirectories named Subfolder and Subsubfolder.

  1. touch command

The touch command creates a new empty file in your current working directory or a specified path.

Example:

touch NewFile.txt

This command creates a new empty file named NewFile.txt in your current working directory.

To create multiple files at once, use this command:

touch NewFile1.txt NewFile2.txt NewFile3.txt

This command creates three new empty files named NewFile1.txt, NewFile2.txt, and NewFile3.txt in your current working directory.

The touch command can also be used to change the access and modification times of existing files.

Example:

touch -a ExistingFile.txt

This command updates the access time of ExistingFile.txt to the current time.

  1. cp command

The cp command copies files or directories from one location to another.

Example:

cp SourceFile.txt DestinationFolder

This command copies SourceFile.txt from your current working directory to DestinationFolder.

To copy multiple files at once, use this command:

cp SourceFile1.txt SourceFile2.txt DestinationFolder

This command copies SourceFile1.txt and SourceFile2.txt from your current working directory to DestinationFolder.

To copy a directory and its contents recursively, use this command:

cp -r SourceFolder DestinationFolder

This command copies SourceFolder and all its subdirectories and files to DestinationFolder.

  1. mv command

The mv command moves files or directories from one location to another.

Example:

mv SourceFile.txt DestinationFolder

This command moves SourceFile.txt from your current working directory to DestinationFolder.

To move multiple files at once, use this command:

mv SourceFile1.txt SourceFile2.txt DestinationFolder

This command moves SourceFile1.txt and SourceFile2.txt from your current working directory to DestinationFolder.

To move a directory and its contents recursively, use this command:

mv SourceFolder DestinationFolder

This command moves SourceFolder and all its subdirectories and files to DestinationFolder.

The mv command can also be used to rename files or directories.

Example:

mv OldName.txt NewName.txt

This command renames OldName.txt to NewName.txt in your current working directory.

  1. rmcommand

The rmcommand removes files or directories from your file system.

Example:

rm FileToDelete.txt

This command deletes FileToDelete.txt from your current working directory.

To delete multiple files at once, use this command:

rm FileToDelete1.txt FileToDelete2.txt FileToDelete3.txt

This command deletes FileToDelete1.txt, FileToDelete2.txt, and FileToDelete3.txt from your current working directory.

To delete a directory and its contents recursively, use this command:

rm -r FolderToDelete

This command deletes FolderToDelete and all its subdirectories and files from your file system.

  1. catcommand

The catcommand concatenates files and prints them on the standard output (usually the terminal).

Example:

cat FileToRead.txt

This command prints the contents of FileToRead.txt on the terminal.

To concatenate multiple files and print them on the standard output, use this command:

cat FileToRead1.txt FileToRead2.txt FileToRead3.txt

Last updated

Was this helpful?