Learn Basic Linux Commands (With Syntax)

Learn Basic Linux Commands (With Syntax)

9 mins read30K Views Comment
Updated on Dec 21, 2023 18:45 IST

"Linux commands" refer to the instructions or inputs that users provide to perform specific operations in the Linux operating system. Linux, being a command-line-oriented operating system, relies heavily on these commands for managing files, software, and system settings. Let us understand more!


Linux is a popular open-source Unix-like operating system (OS). It is software that manages a system’s hardware and resources. It is used in desktops, smartphones, laptops, enterprise servers, and home appliances such as modems and routers. If you are considering using Linux, then you need to be familiar with the basic Linux commands. In this article, we will explain the different commands in Linux with syntax so that you understand their functionality in a better way.

Explore popular Linux Courses

Basic Linux Commands With Syntax

Linux operating system has many commands. In this blog, we will take a look at the 20 most important Linux commands that are commonly used by programmers and developers. These commands will help you navigate through Linux operating system.

To gain hands-on knowledge of these commands, you will have to open the command line first on your desktop or laptop. The Linux Command Line Interface (CLI) is a text-based interface that will enable you to type text commands to instruct the computer to do specific tasks. The Linux command line is case-sensitive.

Also read: Difference between Linux and Unix

ls command

The ls command allows the user to view the contents of a directory. It lists the files and directories. The ls command displays the contents of the current working directory by default (if the user does not specify any other directory). To check the content of other directories, you can type the ls command followed by the directory path.

ls command syntax

ls [Options] [File]

Some of the common option tags that you can use with the ls command:

Option Description
ls –R lists all the files in the sub-directories as well
ls –S sorts and lists all the contents in the specified directory by size
ls -al list the files and directories with detailed information
ls -a shows the hidden files in the specified directory

Also Read: Top Linux Interview Questions and Answers


The clear command clears the terminal screen. This command ignores any command-line parameters and does not take any argument

clear command syntax

$ clear

pwd command

The full form of pwd command is Print Working Directory. It allows users to find the path of the current working directory or folder they are in. The pwd command has two options:

  • -L: prints a symbolic path
  • -P: prints the actual full path

pwd command syntax

$ pwd

cd command

Use the cd command to navigate through the Linux files and directories. You will have to write the full path or the name of the directory to use this command.

For example, if you are working in /home/username/Documents and want to go in the Pictures subdirectory of the same directory, you can write cd Pictures.

If you want to go to a new directory, you can write cd followed by the absolute path of the directory – cd /home/username/Music.

Command Description
cd to go to the home folder
cd.. to move one directory up
cd- move to your previous directory

cp command

You can use the cp command to copy files from the current directory to a different directory.

cp source file destination file. In case you need a copy of the file second.txt in the same directory you have to use the cp command

cp command syntax

$ cp source file destination file

Example – to copy the contents of the red file into the blue file.

$ cp red.txt blue.txt

mv command

Use the mv command to move a file from a given directory to a different directory. It helps programmers to organize data easily. You can also use this command to rename files. The file or directory that is moved is deleted from the working directory.

mv command syntax – to move a file

$ mv <Filename> <Directory_Name>

mv command syntax – to rename a file

mv old_filename new_filename

Also Read: Top Unix Interview Questions and Answers

rm command

The rm command deletes directories as well as the contents within them. This command needs to be used carefully as it deletes everything.

rm command syntax

$ rm <filename>

rmdir command

rmdir allows users to delete a directory, provided that the directory is empty. You will need to ensure that there is no file or subdirectory under the directory that you want to delete.

$ rmdir <directoryname>

touch command

With the touch command, you can create a new blank file with the given name.

touch command syntax

$ rmdir <directoryname>

You can also create multiple files simultaneously

$ touch <filename1> <filename2>

locate command

The locate command enables users to locate a file. If you don’t remember the exact file name, you can use the -i argument to make it case-insensitive.

$ locate <filename>

sudo command

sudo stands for ‘SuperUser Do’. It enables users to run some commands as a super user or System Administrator that normal users cannot do. You can run such commands that need elevated rights on a Linux system.

sudo command syntax

sudo command_you_want_to_execute

Must Read: Top Online IT Courses

df command

With the df command, users can get the information related to file systems about total space and available space. You can get a report on display the size, available space, and system’s disk space usage, and more. This command shows the result in percentage and KBs.

df command syntax 

df [File]

df command options

Option Description
-x excludes specific filesystems
-T, –print-type prints the type of file system
-a, –all includes duplicate and files that are inaccessible
-m shows the result in megabytes

du command

The du (Disk Usage) command shows how much space a file or a directory takes.

du command syntax

$ du

du command has the below options:

Option Description
-h shows human-readable form
-s gives a summary of the output total size


$ du -h

chown command

All files are owned by a specific user in Linux. With the chown command, you can change the ownership of a file or folder to the specified username.

chown owner_name file_name

Example – to make linuxuser1 the owner of the file.ext

chown owner_name file_name

echo command

The echo command displays a text or a string to the standard output or a file.

echo command syntax

$echo “<String>”


$ echo “This is an example of echo”

This command allows users to view the first lines of any text file. It shows the first ten lines by default.

head command syntax

$ head [Filename]

You can also manually input the number of lines you want to view.


$ head -n <number> <Filename>

tail command

This command shows the last ten lines of a text file.

tail command syntax

$ head [Filename]

The number of output lines is ten by default, however, this can be changed to any number with the -n (number) option.


tail -n <number> <Filename>
What is Awk Command in Linux?
What is Awk Command in Linux?
Here we will understand the concept of Awk command in Linux. You will also find its features, AWK Script, along with examples.
What is Grep Command in Linux?
What is Grep Command in Linux?
Here you will understand the Grep command in Linux. We have also explained options description and sample commands. Let’s check out.
How to Delete a File in Linux?
How to Delete a File in Linux?
Need to clear some space on your Linux system? It’s easier than you might think! With a simple command, you can swiftly delete any file. But what’s the right way...read more

uname command

uname stands for Unix Name. This command prints detailed information about your Linux system. The information includes machine name, kernel, operating system, and more. Different options tell about different pieces of information.

Option Description
-a this option displays everything
-v shows the kernel information
-s displays the kernel version of the system
-r displays the kernel release

uname command syntax

uname [Option]


uname -s

Check out the best Operating System Courses

history command

The history command shows the previously used commands. It displays the information about the commands executed by a user.

history command syntax

$ history

man command

This command is used to check the reference manual pages for commands or programs.

man command syntax

$ man [Command Name]


$ man head

useradd command

It is used to add or remove a user on a Linux server.

useradd command syntax:

useradd [options] username


useradd newperson1

Suggested Read: Linux vs Windows

Cat Command

The cat command is used to display the contents of a file.

Syntax of cat command:

cat <filename.extension>


cat newfile.txt

A few other use of cat command in Linux:

Option Function
cat > [fileName] Create a new file.
cat [old_file] > [new_file] Copy content from old file to new file.
cat [file1, file2,….] > [new file name] Concatenate contents of multiple files into one file.
cat –n [File_Name] / cat -b [File_Name] Display line numbers.
cat -e [fileName] Display $ character at the end of each line.

Ping command

Utilize the ping command to check your connection to a server. It checks the reachability of a host on an Internet Protocol (IP) network”.

Syntax of ping command:

ping <Domain Name>


ping google.com

Also Read: Top Linux Interview Questions and Answers


We hope this article helped you to become familiar with the most commonly used basic Linux commands and concepts. The information provided in this blog will help you feel comfortable the next time you work with the Linux operating system.


What is Linux?

Linux is one of the widely used server-based operating systems. It is considered to be a highly reliable and secure system compared to other operating systems (OS). Linux is a completely free, open-source, easy to maintain, lightweight, fast, portable, and highly stable operating system.

What are Linux commands?

Commands are the instructions that a user gives to the computer to do a specific task. Any task ranging from basic to complex tasks can be performed by executing Linux commands. An understanding of the basic Linux commands will enable you to navigate directories, display information, change permissions, and more.

What is the ls command in Linux?

The ls command in Linux is used to list files and directories within the current directory. By default, it shows just the names, but it can provide detailed information (like file size, permissions, modification date) when used with options, such as ls -l for a long listing format.

What is the purpose of the pwd command?

The pwd command stands for "Print Working Directory." It displays the full path of the current directory you are in. This command is helpful when you have navigated through several directories and want to confirm your current directory location.

How can I view the contents of a file in the terminal?

 There are several commands for viewing file contents. cat displays the entire content of a file on the screen. For larger files, less or more can be used to view the content page by page, allowing for easier reading and navigation.

About the Author

This is a collection of insightful articles from domain experts in the fields of Cloud Computing, DevOps, AWS, Data Science, Machine Learning, AI, and Natural Language Processing. The range of topics caters to upski... Read Full Bio