0% found this document useful (0 votes)
83 views

Linux Essentail Commands Cheetsheet

This document provides a cheat sheet for Linux commands, organized into several sections: 1. File and directory navigation commands like ls, ls -R, and ls -a for listing files and directories. 2. System information commands like history, clear, hostname, hostid, and sudo for viewing system details. 3. File permission commands like chmod that can change permissions for users, groups, and others using symbolic or numeric notation. 4. An introduction explains Linux advantages over Windows like security, stability, and being open-source. The cheat sheet is intended to help students and professionals learn important Linux commands.

Uploaded by

jgovindaraaj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views

Linux Essentail Commands Cheetsheet

This document provides a cheat sheet for Linux commands, organized into several sections: 1. File and directory navigation commands like ls, ls -R, and ls -a for listing files and directories. 2. System information commands like history, clear, hostname, hostid, and sudo for viewing system details. 3. File permission commands like chmod that can change permissions for users, groups, and others using symbolic or numeric notation. 4. An introduction explains Linux advantages over Windows like security, stability, and being open-source. The cheat sheet is intended to help students and professionals learn important Linux commands.

Uploaded by

jgovindaraaj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Linux Commands Cheat Sheet

To view the live version of the


page, click here.

© Copyright by Interviewbit
Contents

Linux Commands Tutorial: Basics to Advanced


1. File and Directory CRUD Navigation Commands
2. System Information Commands
3. File Permission Commands
4. Hardware Information Commands
5. File and Directory Compression Commands
6. Environment Variable Commands
7. User Management Commands
8. Networking Commands
9. Process Commands

Page 1 © Copyright by Interviewbit


Let's get Started

Introduction

Linux is a very famous, open-source operating system. Many developers use Linux for
development purposes because of its high throughput. As a student or even a
professional in the so ware industry, it is very essential to have knowledge of the
Linux OS. Many programmers prefer Linux over Windows OS for development
purposes due to a variety of reasons such as the security of the Linux Operating
System is better than Windows, the Linux terminal is way superior to the windows
command line in many ways, etc.
What is Linux and Why use it?
Before we jump into studying a lot of Linux commands, it is very important to
address this question What is Linux and why is it preferred over Windows OS. Linux is
an open-source operating system whose source code is available for modification
and commercial and non-commercial distribution under the guidelines of the GNU
General Public License.
Linux has a number of advantages over the Windows operating system and is used
widely because of these advantages Below are a few listed:

Page 2 © Copyright by Interviewbit


Linux Commands Cheat Sheet

The major advantage of the Linux Operating System is that it is a freely available
open-source OS. This means that the source code of the Linux Operating System
is available openly in the market (on the internet) and anyone can study it,
modify it and even send it forward for commercial uses too. However, the major
use case of it being an Open Source OS is the study of the Operating System
itself. If anyone has to understand the Operating System as a core subject, it's
working, and what are the things kept in mind while designing an operating
system, you can simply look up the code of Linux OS and get a plethora of ideas.
Privacy and Security are very important for the users, especially nowadays, when
hacking and other cyber malpractices have become so common. Linux
maintains the privacy of the user and is a lot more secure than Windows OS.
However, this does not mean that Linux is completely secured and can never be
attacked. This simply means that it is more secure than Windows and it does not
even require any antivirus so ware to be installed within it.
Linux Operating System is highly stable and does not hang or requires to be
restarted again and again.
Linux is fast and easy to install and can be installed very easily from the internet.
Linux is network friendly.
So, now that we have a fair idea about the Linux Operating System and its
advantages over the Windows OS, let us now move on to the Linux Cheat Sheet and
study the Linux Commands.
Here, we have a cheat sheet prepared for you to refer to all the important Linux
Commands with Examples.

Linux Commands Tutorial: Basics to Advanced


1. File and Directory CRUD Navigation Commands
CRUD stands for Create, Read, Update, and Delete. CRUD operations are said to be
the basic operations on any file or directory or database. Even if you are not a Linux
User, file and directory CRUD operations are something that you should be
comfortable with.

Page 3 © Copyright by Interviewbit


Linux Commands Cheat Sheet

COMMAND MEANING EXAMPLE & SYNTAX

ls (list all Lists all the


directories) files and
directories
inside the Syntax: $ ls
current
directory in
which you are.

ls -R Lists all the


files and
directories
inside the
current
directory as
Syntax: $ ls -R
well as all the
files and
directories of
the sub-
directories as
well.

ls -a Lists all the


files and
directories in
the current
directory and
also lists the
hidden files
(such as .git Syntax: $ ls -a
files). However,
this command
does not list
the files and
directories of
th b
Page 4 © Copyright by Interviewbit
Linux Commands Cheat Sheet

2. System Information Commands


These are some of the general-purpose system information commands that are
important to know and easy to remember.

Page 5 © Copyright by Interviewbit


Linux Commands Cheat Sheet

COMMAND MEANING EXAMPLE & SYNTAX

history This command


displays the list
of all the typed
Syntax: $ history
commands in the
current terminal
session.

clear Clears the


terminal i.e. no
previous
Syntax: $ clear
command will be
visible on the
screen now.

hostname Shows the name


of the system Syntax: $ hostname
host.

hostid Displays the id of


the host of the Syntax: $ hostid
system.

sudo Allows a regular


user to run the
programs with
the security Syntax: $ sudo
privileges of a
superuser or
root.

apt-get This command is


used to install
Syntax: $ apt-get
and add new
packages.

Page 6 © Copyright by Interviewbit


Linux Commands Cheat Sheet

3. File Permission Commands


There are 3 types of people who can use a file and each type has 3 types of access to
the file. This is shown in the diagram given below:

The diagram shows that there are 3 types of people accessing a file and they are:
1. User (u)
2. Group (g)
3. Others (o)
Also, the access that we want to give to each of them is of three types:
1. Read (r)
2. Write (w)
3. Execute (x)
So, each of them can have 0 or more out of these 3 permissions. Now let us
understand the Linux commands that help us give these permissions to the files.
One important thing to note here is that before these 9 slots of the user, group and
others (read, write and execute permissions), there is also one another slot. This slot
is for special files. For instance, if you something as drwxr--r--, here ‘d’ shows that it is
a directory of which you are viewing the permissions. Further, rwx means that the
user has all the three permissions where as r-- means that the group has only read
permission and the write and execute permissions are not there with the group. The
same is the case for others (another r--).

Page 7 © Copyright by Interviewbit


Linux Commands Cheat Sheet

The chmod Command:


Before we jump into the Linux file permission commands and see some examples, it
is very important to understand this chmod command in detail first as understanding
this command completely will clear the entire concept of file permission commands.
The chmod command stands for “change-mode” which means that using this
command, we can change the mode in which some user is able to access the file. This
command is used to change the file permissions. The syntax can be either using
symbols (characters) or numbers. We will see that in detail.
Symbolic Method for granting permissions:
This is the first method of chmod command using which we can give permissions.
The basic syntax is as follows:
chmod [ugoa…][-+=]perms…[,....] FILE….
Let us understand this syntax in detail.
The first set means the type of person to give access to. Here:
1. u → Stands for User
2. g → Stands for Group
3. o → Stands for Others
4. a → Stands for All the users i.e. instead of writing ugo, we can just write a.
If the user's flag is not included in the command i.e. we do not mention for which
kind of people out of u, g and o, are we changing the permissions for, by default, it
takes a i.e. all the users.
The second set is the set of operators. Let us see what they mean.
1. - → removes the mentioned permission
2. + → adds the mentioned permission
3. = → Changes the current permission to the mentioned permission. IF no
permission is mentioned a er using the = operator, all the permissions from the
mentioned class are removed.
The perms stand for permission and ‘,’ is used to separate different permissions. Let
us now see the Linux commands using the symbolic notation of chmod.

Page 8 © Copyright by Interviewbit


Linux Commands Cheat Sheet

COMMAND MEANING EXAMPLE & SYNTAX

ls -l Example: The file


fileName permissions along
with the owner and
This command is other details is
used to show the shown for the file
file permissions file1.txt on the
along with the right.
owner and other
Syntax: $ ls -l
details of the
file1.txt -rw-r--r--
specified file.
1 Guneet Malhotra
197121 0 Feb 25 10:51
file1.txt

r Example: The
command shown in
the right adds the
This command read permission to
represents the the o (other) class
read permission. for the file file1.txt.
Syntax: $ chmod
o+r file1.txt

w Example: This
commands adds
the write
This command permission for a(all)
represents the i.e. user, group and
write permission. others.
Syntax: $ chmod
a+w file1.txt

Page 9 © Copyright by Interviewbit


Linux Commands Cheat Sheet

Numerical Method for granting file permissions


There are numeric codes for each permission. They are as follows:
1. r (read) = 4
2. w (write) = 2
3. x (execute) = 1
4. No permissions = 0
The permissions number of a specific user class is represented by the sum of the
values of all the permissions. For instance, if the user has read and executed
permissions, but not the write permission, then the permissions number for the user
will be read (4) + execute(1) = 5.
For instance, if we have to write a command to provide read and write permissions to
the user, group and others, there can be many ways of doing so. Let us see one
symbolic way:
Symbolic Way
$ chmod ugo+rw file1.txt

We can write this in a numeric way as shown below:


Numeric Way
$ chmod 666 file1.txt

Explanation: We have already studied that if we do not mention u/g/o then by


default the permissions are applied to all. Also, read + write = 4 + 2 = 6. We have
written 6 thrice because of applying the permissions to user, group and others. So,
read and write permissions are applied to the user, group and others (666) for the file
file1.txt.

4. Hardware Information Commands


Let us now see, some of the hardware information commands that give us the
information about the hardware that we are using.

Page 10 © Copyright by Interviewbit


Linux Commands Cheat Sheet

COMMAND MEANING EXAMPLE & SYNTAX

cpu-info This command


is used to
display the
information
about your
CPU. Note that
this command
is not available
by default. It Syntax: $ cpu-info
can be used
a er
installation of
the necessary
package using
sudo apt
install
cpuinfo.

free -h This command


is used to
display the free
and used
memory. -h is
used for Syntax: $ free -h
converting the
information (to
be displayed)
to human-
readable form.

lsusb -tv List all the USB


Syntax: $ lsusb -
connected
tv
devices.

Page 11 © Copyright by Interviewbit


Linux Commands Cheat Sheet

5. File and Directory Compression Commands


The files can be compressed and then extracted to save the storage. We see this
happening many times in our daily lives that we have to compress some file to send it
or we have to extract a downloaded file. There are several commands for file
compression in Linux given below:

Page 12 © Copyright by Interviewbit


Linux Commands Cheat Sheet

COMMAND MEANING EXAMPLE & SYNTAX

gzip
This Example: The
fileName
command is command to zip file1
used to using gzip
compress a compression is shown
file with gzip on the right.
compression. Syntax: $ gzip file1

gunzip Example: The


fileName.gz This command to unzip
command is fileDemo.gz file with
used to unzip gz compression is
a file that has shown on the right.
gzip
Syntax: $ gunzip
compression.
fileDemo.gz

tar cf Example: The


myDir.tar
This command to create an
myDir
command is uncompressed tar
used to create archive for the
an directory demoDir is
uncompressed shown on the right.
tar archive. Syntax: $ tar cf
demoDir.tar demoDir

tar cfz Example: The


myDir.tar This command to create
myDir command is gzip tar archive for the
used to create directory demoDir is
a tar archive shown on the right.
with gzip
Syntax: $ tar cfz
compression.
demoDir.tar demoDir

Page 13 © Copyright by Interviewbit


Linux Commands Cheat Sheet

6. Environment Variable Commands

COMMAND MEANING EXAMPLE & SYNTAX

env This
command
displays all
Syntax: $ env
the
environment
variables.

echo Example: The command


$Variable This at the right will display
command the INSTANCE
displays the environment variable.
environment
Syntax: $ echo
variable.
$INSTANCE=

unset This
command
Syntax: $ unset
removes a
variable.

7. User Management Commands

Page 14 © Copyright by Interviewbit


Linux Commands Cheat Sheet

COMMAND MEANING EXAMPLE & SYNTAX

sudo This command


Syntax: $ sudo
adduser is used to add a
adduser username
username user.

sudo Example: Command


passwd -l This command to change the
‘username’ is used to password for user1 is
change the shown
password of a
Syntax: $ sudo passwd
user.
-l 'user1'

sudo Example: Command


userdel -r This command to delete the newly
‘username’ is used to created user1
remove a newly
Syntax: $ sudo
created user.
userdel -r 'user1'

sudo Example: The


usermod -a -
This command command to add
G GROUPNAME
is used to add a user2 to group1 is
USERNAME
user to a shown.
particular Syntax: $ sudo
group. usermod -a -G group1
user2

Sudo Example: The


deluser USER
This command command to delete
GROUPNAME
is used to user1 from group1 is
remove a user shown.
from a group. Syntax: $ sudo
deluser user1 group1

Page 15 © Copyright by Interviewbit


Linux Commands Cheat Sheet

8. Networking Commands

COMMAND MEANING SYNTAX

dir This command is used to


Syntax:
display files in the current
$
directory of a remote
dir
computer.

put This command is used to Syntax:


file upload ‘file’ from local to the $ put
remote computer. file

get This file is used to download Syntax:


file ‘file’ from remote to the local $ get
computer. file

quit Syntax:
This command is used to log
$
out.
quit

9. Process Commands

Page 16 © Copyright by Interviewbit


Linux Commands Cheat Sheet

COMMAND MEANING EXAMPLE & SYNTAX

bg
This command Example: The process
is used to send with id 1 is sent to the
a process to background by
the providing its id to bg.
background. Syntax: $ bg %1

fg Example: The process


This command with id 1 is brought to
is used to run a the foreground with
stopped the help of this
process in the command.
background.
Syntax: $ fg %1

top This command


is used to get
the details of Syntax: $ top
all active
processes.

ps This command
is used to give
the status of Syntax: $ ps
running for a
user.

ps PID
This command Example: Displays the
gives the status status of the process
of a particular with id 12230.
process. Syntax: $ ps 12230

Page 17 © Copyright by Interviewbit


Linux Commands Cheat Sheet

Additional Useful Resources:

Linux MCQ with Answers


Shell Scripting Interview
Unix Interview

Page 18 © Copyright by Interviewbit


Links to More Interview
Questions

C Interview Questions Php Interview Questions C Sharp Interview Questions

Web Api Interview Hibernate Interview Node Js Interview Questions


Questions Questions

Cpp Interview Questions Oops Interview Questions Devops Interview Questions

Machine Learning Interview Docker Interview Questions Mysql Interview Questions


Questions

Css Interview Questions Laravel Interview Questions Asp Net Interview Questions

Django Interview Questions Dot Net Interview Questions Kubernetes Interview


Questions

Operating System Interview React Native Interview Aws Interview Questions


Questions Questions

Git Interview Questions Java 8 Interview Questions Mongodb Interview


Questions

Dbms Interview Questions Spring Boot Interview Power Bi Interview Questions


Questions

Pl Sql Interview Questions Tableau Interview Linux Interview Questions


Questions

Ansible Interview Questions Java Interview Questions Jenkins Interview Questions

Page 19 © Copyright by Interviewbit

You might also like