Learn Basic Linux Commands (With Syntax) : Updated On Dec 21, 2023 18:45 IST
Learn Basic Linux Commands (With Syntax) : Updated On Dec 21, 2023 18:45 IST
Learn Basic Linux Commands (With Syntax) : Updated On Dec 21, 2023 18:45 IST
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!
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
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 –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
clear
The clear command clears the terminal screen. This command ignores any
command-line parameters and does not take any argument
$ 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
$ 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.
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
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 <Filename> <Directory_Name>
mv old_filename new_filename
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>
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_you_want_to_execute
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
du command
The du (Disk Usage) command shows how much space a file or a directory takes.
du command syntax
$ du
Option Description
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
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
head command
This command allows users to view the first lines of any text file. It shows the first
ten lines by default.
$ head [Filename]
You can also manually input the number of lines you want to view.
Syntax
t ail command
$ 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
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.
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
uname [Option]
Example
uname -s
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.
Example
$ man head
useradd command
Example :
useradd newperson1
Cat Command
cat <filename.extension>
Example :
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 [old_file] > [new_file] Copy content f rom old f ile to new f ile.
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”.
Example :
ping google.com
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?
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?
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.