Learn Basic Linux Commands (With Syntax) : Updated On Dec 21, 2023 18:45 IST

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Learn Basic Linux Commands (With Syntax)

Shiksha Online
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

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 22-Dec-20 23.
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.

Is Command

clear Command

pwd Command

cd Command

cp Command

mv Command

rm Command

rmdir Command

touch Command

locate Command

sudo Command

df Command

du Command

chown Command

echo Command

head Command

tail Command

uname Command

history Command

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 22-Dec-20 23.
man Command

useradd Command

cat Command

ping Command

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 f iles in the sub-directories as well

ls –S sorts and lists all the contents in the specif ied directory by size

ls -al list the f iles and directories with detailed inf ormation

ls -a shows the hidden f iles in the specif ied directory

Also Read: Top Linux Interview Questions and Answers

clear

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

clear command syntax

$ clear

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 22-Dec-20 23.
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 f ull 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 f older

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

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 22-Dec-20 23.
$ 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>

t ouch command

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

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 22-Dec-20 23.
touch command syntax

$ rmdir <directoryname>

You can also create multiple files simultaneously


$ touch <f ilename1> <f ilename2>

locat e 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 <f ilename>

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

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 22-Dec-20 23.
Option Description

-x excludes specif ic f ilesystems

-T , –print-type prints the type of f ile system

-a, –all includes duplicate and f iles 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 f orm

-s gives a summary of the output total size

Example

$ 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 f ile_name

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

chown owner_name f ile_name

echo command

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

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 22-Dec-20 23.
echo command syntax

$echo “<String>”

Example

$ echo “T his is an example of echo”

head command

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.

Syntax

$ head -n <number> <Filename>

t ail 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.

Syntax

tail -n <number> <Filename>

What is Awk Command in Linux?


Here we will understand the co ncept o f Awk co mmand in Linux. Yo u will also
find its features, AWK Script, alo ng with examples.

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 22-Dec-20 23.
What is Grep Command in Linux?
Here yo u will understand the Grep co mmand in Linux. We have also explained
o ptio ns descriptio n and sample co mmands. Let’s check o ut.

How t o Delet e a File in Linux?


Need to clear so me space o n yo ur Linux system? It’s easier than yo u might
think! With a simple co mmand, yo u can swiftly delete any file. But what’s the right
way...re ad m o re

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 inf ormation

-s displays the kernel version of the system

-r displays the kernel release

uname command syntax

uname [Option]

Example

uname -s

Check out the best Operating System Courses

hist ory command

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

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 22-Dec-20 23.
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]

Example

$ man head

useradd command

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

useradd command syntax:

useradd [options] username

Example :

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>

Example :

cat newf ile.txt

A few other use of cat command in Linux:

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 22-Dec-20 23.
Option Function

cat > [fileName] Create a new f ile.

cat [old_file] > [new_file] Copy content f rom old f ile to new f ile.

Concatenate contents of multiple f iles into one


cat [file1, file2,….] > [new file name]
f ile.

cat –n [File_Name] / cat -b


Display line numbers.
[File_Name]

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>

Example :

ping google.com

Also Read: Top Linux Interview Questions and Answers

Conclusion

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.

FAQs

What is Linux?

What are Linux commands?

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 22-Dec-20 23.
What is the ls command in Linux?

What is the purpose of the pwd command?

How can I view the contents of a f ile in the terminal?

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 22-Dec-20 23.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy