Linux Tutorial
Linux is an open-source operating system. It is like Windows,
Mac, Android, etc.
UNIX is also an operating system like Linux. It is an commercial
OS. It consists of three parts: Kernel, Shell and Programs. Most
of the Unix and Linux commands are similar in nature.
Our Linux tutorial includes all topics of Linux OS such as Linux
commands, Directories, Files, Man Pages, File Contents, File
Permissions, shells, VI editor etc. There is also given Linux
interview questions to help you better understand the Linux
operating system.
Structure Of Linux Operating System
An operating system is a collection of software, each designed for
a specific function.Linux OS has following components:
1) Kernel
Linux kernel is the core part of the operating system. It establishes
communication between devices and software. Moreover, it
manages system resources. It has four responsibilities:
o device management: A system has many devices connected
to it like CPU, a memory device, sound cards, graphic cards,
etc. A kernel stores all the data related to all the devices in
the device driver (without this kernel won't be able to control
the devices). Thus kernel knows what a device can do and
how to manipulate it to bring out the best performance. It
also manages communication between all the devices. The
kernel has certain rules that have to be followed by all the
devices.
o Memory management: Another function that kernel has to
manage is the memory management. The kernel keeps track
of used and unused memory and makes sure that processes
shouldn't manipulate data of each other using virtual
memory addresses.
o Process management: In the process, management kernel
assigns enough time and gives priorities to processes before
handling CPU to other processes. It also deals with security
and ownership information.
o Handling system calls: Handling system calls means a
programmer can write a query or ask the kernel to perform a
task.
2) System Libraries
System libraries are special programs that help in accessing the
kernel's features. A kernel has to be triggered to perform a task,
and this triggering is done by the applications. But applications
must know how to place a system call because each kernel has a
different set of system calls. Programmers have developed a
standard library of procedures to communicate with the kernel.
Each operating system supports these standards, and then these
are transferred to system calls for that operating system.
The most well-known system library for Linux is Glibc (GNU C
library).
3) System Tools
Linux OS has a set of utility tools, which are usually simple
commands. It is a software which GNU project has written and
publish under their open source license so that software is freely
available to everyone.
With the help of commands, you can access your files, edit and
manipulate data in your directories or files, change the location of
files, or anything.
4) Development Tools
With the above three components, your OS is running and
working. But to update your system, you have additional tools
and libraries. These additional tools and libraries are written by
the programmers and are called toolchain. A toolchain is a vital
development tool used by the developers to produce a working
application.
5) End User Tools
These end tools make a system unique for a user. End tools are
not required for the operating system but are necessary for a user.
Some examples of end tools are graphic design tools, office
suites, browsers, multimedia players, etc.
Why use Linux?
This is one of the most asked questions about Linux systems. Why
do we use a different and bit complex operating system, if we
have a simple operating system like Windows? So there are
various features of Linux systems that make it completely
different and one of the most used operating systems. Linux may
be a perfect operating system if you want to get rid of viruses,
malware, slowdowns, crashes, costly repairs, and many more.
Further, it provides various advantages over other operating
systems, and we don't have to pay for it. Let's have a look at some
of its special features that will attract you to switch your operating
system.
Free & Open Source Operating System
Most OS come in a compiled format means the main source code
has run through a program called a compiler that translates the
source code into a language that is known to the computer.
Modifying this compiled code is a tough job.
On the other hand, open-source is completely different. The
source code is included with the compiled version and allows
modification by anyone having some knowledge. It gives us the
freedom to run the program, freedom to change the code
according to our use, freedom to redistribute its copies, and
freedom to distribute copies, which are modified by us.
In short, Linux is an operating system that is "for the people, by
the people."
And we can dive in Linux without paying any cost. We can install
it on Multiple machines without paying any cost.
It is secure
Linux supports various security options that will save you from
viruses, malware, slowdowns, crashes. Further, it will keep your
data protected. Its security feature is the main reason that it is the
most favorable option for developers. It is not completely safe,
but it is less vulnerable than others. Each application needs to
authorize by the admin user. The virus cannot be executed until
the administrator provides the access password. Linux systems do
not require any antivirus program.
Favorable choice of Developers
Linux is suitable for the developers, as it supports almost all of
the most used programming languages such
as C/C++, Java, Python, Ruby, and more. Further, it facilitates
with a vast range of useful applications for development.
Developers find that the Linux terminal is much better than the
Windows command line, So, they prefer terminal over the
Windows command line. The package manager on Linux system
helps programmers to understand how things are done. Bash
scripting is also a functional feature for the programmers. Also,
the SSH support helps to manage the servers quickly.
A flexible operating system
Linux is a flexible OS, as, it can be used for desktop applications,
embedded systems, and server applications. It can be used from
wristwatches to supercomputers. It is everywhere in our phones,
laptops, PCs, cars and even in refrigerators. Further, it supports
various customization options.
Linux Distributions
Many agencies modified the Linux operating system and makes
their Linux distributions. There are many Linux distributions
available in the market. It provides a different flavor of the Linux
operating system to the users. We can choose any distribution
according to our needs. Some popular distros are Ubuntu, Fedora,
Debian, Linux Mint, Arch Linux, and many more.
For the beginners, Ubuntu and Linux Mint are considered useful
and, for the proficient developer, Debian and Fedora would be a
good choice. To Get a list of distributions, visit Linux
Distributions.
How does Linux work?
Linux is a UNIX-like operating system, but it supports a range of
hardware devices from phones to supercomputers. Every Linux-
based operating system has the Linux kernel and set of software
packages to manage hardware resources.
Also, Linux OS includes some core GNU tools to provide a way
to manage the kernel resources, install software, configure the
security setting and performance, and many more. All these tools
are packaged together to make a functional operating system.
How to use Linux?
We can use Linux through an interactive user interface as well as
from the terminal (Command Line Interface). Different
distributions have a slightly different user interface but almost all
the commands will have the same behavior for all the
distributions. To run Linux from the terminal, press the
"CTRL+ALT+T" keys. And, to explore its functionality, press the
application button given on the left down corner of your desktop.
Advantages of Linux
Linux is an open-source operating system like Windows and
MacOS. It is not just limited to the operating system, but
nowadays, it is also used as a platform to run desktops, servers,
and embedded systems. It provides various distributions and
variations as it is open source and has a modular design.
The kernel is a core part of the Linux system.
Linux system is used to manage various services such as process
scheduling, application scheduling, basic peripheral devices,
file system, and more. Linux provides various advantages over
other operating systems such as Windows and macOS. So, it is
used in almost every field, from cars to home appliances and
smartphones to servers (supercomputers).
In this section, we will see some major advantages of the Linux
system. Further, we will see the advantages of Linux over other
operating systems and will determine why it is better than other
operating systems.
Why is Linux better than other operating systems?
There are many features of the Linux operating system that
demonstrate that it is better than other operating systems.
However, in some prospective other operating systems can be
more useful than Linux. Let's see the top 20 advantages of Linux
OS.
Top 20 Advantages of Linux
Following are top 20 advantages of the Linux operating system:
1. pen Source
As it is open-source, its source code is easily available. Anyone
having programming knowledge can customize the operating
system. One can contribute, modify, distribute, and enhance the
code for any purpose.
2. Security
The Linux security feature is the main reason that it is the most
favorable option for developers. It is not completely safe, but it is
less vulnerable than others. Each application needs to authorize
by the admin user. The virus is not executed until the
administrator provides the access password. Linux systems do not
require any antivirus program.
3. Free
Certainly, the biggest advantage of the Linux system is that it is
free to use. We can easily download it, and there is no need to buy
the license for it. It is distributed under GNU GPL (General Public
License). Comparatively, we have to pay a huge amount for the
license of the other operating systems.
4. Lightweight
Linux is lightweight. The requirements for running Linux are
much less than other operating systems. In Linux, the memory
footprint and disk space are also lower. Generally, most of the
Linux distributions required as little as 128MB of RAM around
the same amount for disk space.
5. Stability
Linux is more stable than other operating systems. Linux does not
require to reboot the system to maintain performance levels. It
rarely hangs up or slow down. It has big up-times.
6. Performance
Linux system provides high performance over different networks.
It is capable of handling a large number of users simultaneously.
7. Flexibility
Linux operating system is very flexible. It can be used for desktop
applications, embedded systems, and server applications too. It
also provides various restriction options for specific computers.
We can install only necessary components for a system.
8. Software Updates
In Linux, the software updates are in user control. We can select
the required updates. There a large number of system updates are
available. These updates are much faster than other operating
systems. So, the system updates can be installed easily without
facing any issue.
9. Distributions/ Distros
There are many Linux distributions available in the market. It
provides various options and flavors of Linux to the users. We
can choose any distros according to our needs. Some popular
distros are Ubuntu, Fedora, Debian, Linux Mint, Arch
Linux, and many more.For the beginners, Ubuntu and Linux
Mint would be useful and, Debian and Fedora would be good
choices for proficient programmers.
10. Live CD/USB
Almost all Linux distributions have a Live CD/USB option. It
allows us to try or run the Linux operating system without
installing it.
11. Graphical User Interface
Linux is a command-line based OS but, it provides an interactive
user interface like Windows.
12. Suitable for programmers
It supports almost all of the most used programming languages
such as C/C++, Java, Python, Ruby, and more. Further, it offers a
vast range of useful applications for development.
The programmers prefer the Linux terminal over the Windows
command line. The package manager on Linux system helps
programmers to understand how things are done. Bash
scripting is also a functional feature for the programmers. It also
provides support for SSH, which helps in managing the servers
quickly.
13. Community Support
Linux provides large community support. We can find support
from various sources. There are many forums available on the
web to assist users. Further, developers from the various
opensource communities are ready to help us.
14. Privacy
Linux always takes care of user privacy as it never takes much
private data from the user. Comparatively, other operating
systems ask for the user's private data.
15. Networking
Linux facilitates with powerful support for networking. The
client-server systems can be easily set to a Linux system. It
provides various command-line tools such as ssh, ip, mail, telnet,
and more for connectivity with the other systems and servers.
Tasks such as network backup are much faster than others.
16. Compatibility
Linux is compatible with a large number of file formats as it
supports almost all file formats.
17. Installation
Linux installation process takes less time than other operating
systems such as Windows. Further, its installation process is
much easy as it requires less user input. It does not require much
more system configuration even it can be easily installed on old
machines having less configuration.
18. Multiple Desktop Support
Linux system provides multiple desktop environment support for
its enhanced use. The desktop environment option can be selected
during installation. We can select any desktop environment such
as GNOME (GNU Network Object Model
Environment) or KDE (K Desktop Environment) as both have
their specific environment.
19. Multitasking
It is a multitasking operating system as it can run multiple tasks
simultaneously without affecting the system speed.
20. Heavily Documented for beginners
There are many command-line options that provide
documentation on commands, libraries, standards such as manual
pages and info pages. Also, there are plenty of documents
available on the internet in different formats, such as Linux
tutorials, Linux documentation project, Serverfault, and more. To
help the beginners, several communities are available such as Ask
Ubuntu, Reddit, and StackOverflow.
For more head to head comparison of Linux system, visit Linux
vs. Windows.
Basic Linux Commands
o Linux Directory Commands
o Linux File Commands
o Linux File Content Commands
o Linux User Commands
o Linux Filter Commands
o Linux Utility Commands
o Linux Networking Command
Linux Directory Commands
1. pwd Command
The pwd command is used to display the location of the current
working directory.
Syntax:
1. pwd
Output:
2. mkdir Command
The mkdir command is used to create a new directory under any
directory. Syntax: mkdir <directory name>
Output:
3. rmdir Command
The rmdir command is used to delete a directory.
Syntax:
1. rmdir <directory name>
Output:
4. ls Command
The ls command is used to display a list of content of a directory.
Syntax:
1. ls
Output:
5. cd Command
The cd command is used to change the current directory.
Syntax:
1. cd <directory name>
Output:
Linux File commands
6. touch Command
The touch command is used to create empty files. We can create
multiple empty files by executing it once.
Syntax:
1. touch <file name>
2. touch <file1> <file2> ....
Output:
7. cat Command
The cat command is a multi-purpose utility in the Linux system.
It can be used to create a file, display content of the file, copy the
content of one file to another file, and more.
Syntax:
1. cat [OPTION]... [FILE]..
To create a file, execute it as follows:
1. cat > <file name>
2. // Enter file content
Press "CTRL+ D" keys to save the file. To display the content of
the file, execute it as follows:
1. cat <file name>
Output:
8. rm Command
The rm command is used to remove a file.
Syntax:
rm <file name>
Output:
9. cp Command
The cp command is used to copy a file or directory.
Syntax:
To copy in the same directory:
1. cp <existing file name> <new file name>
To copy in a different directory:
Output:
10. mv Command
The mv command is used to move a file or a directory form one
location to another location.
Syntax:
1. mv <file name> <directory path>
Output:
11. rename Command
The rename command is used to rename files. It is useful for
renaming a large group of files.
Syntax:
1. rename 's/old-name/new-name/' files
For example, to convert all the text files into pdf files, execute the
below command:
1. rename 's/\.txt$/\.pdf/' *.txt
Output:
Linux File Content Commands
12. head Command
The head command is used to display the content of a file. It
displays the first 10 lines of a file.
Syntax:
1. head <file name>
Output:
13. tail Command
The tail command is similar to the head command. The difference
between both commands is that it displays the last ten lines of the
file content. It is useful for reading the error message.
Syntax:
1. tail <file name>
Output:
14. tac Command
The tac command is the reverse of cat command, as its name
specified. It displays the file content in reverse order (from the
last line).
Syntax:
1. tac <file name>
Output:
15. more command
The more command is quite similar to the cat command, as it is
used to display the file content in the same way that the cat
command does. The only difference between both commands is
that, in case of larger files, the more command displays screenful
output at a time.
In more command, the following keys are used to scroll the page:
ENTER key: To scroll down page by line.
Space bar: To move to the next page.
b key: To move to the previous page.
/ key: To search the string.
Syntax:
1. more <file name>
Output:
16. less Command
The less command is similar to the more command. It also
includes some extra features such as 'adjustment in width and
height of the terminal.' Comparatively, the more command cuts
the output in the width of the terminal.
Syntax:
1. less <file name>
Output:
Linux User Commands
17. su Command
The su command provides administrative access to another user.
In other words, it allows access of the Linux shell to another user.
Syntax:
1. su <user name>
Output:
18. id Command
The id command is used to display the user ID (UID) and group
ID (GID).
Syntax:
1. id
Output:
19. useradd Command
The useradd command is used to add or remove a user on a Linux
server.
Syntax:
1. useradd username
Output:
20. passwd Command
The passwd command is used to create and change the password
for a user.
Syntax:
1. passwd <username>
Output:
21. groupadd Command
The groupadd command is used to create a user group.
Syntax:
1. groupadd <group name>
Output:
Linux Filter Commands
22. cat Command
The cat command is also used as a filter. To filter a file, it is used
inside pipes.
Syntax:
1. cat <fileName> | cat or tac | cat or tac |. . .
Output:
23. cut Command
The cut command is used to select a specific column of a file. The
'-d' option is used as a delimiter, and it can be a space (' '), a slash
(/), a hyphen (-), or anything else. And, the '-f' option is used to
specify a column number.
Syntax:
1. cut -d(delimiter) -f(columnNumber) <fileName>
Output:
24. grep Command
The grep is the most powerful and used filter in a Linux system.
The 'grep' stands for "global regular expression print." It is
useful for searching the content from a file. Generally, it is used
with the pipe.
Syntax:
1. command | grep <searchWord>
Output:
25. comm Command
The 'comm' command is used to compare two files or streams. By
default, it displays three columns, first displays non-matching
items of the first file, second indicates the non-matching item of
the second file, and the third column displays the matching items
of both files.
Syntax:
1. comm <file1> <file2>
Output:
26. sed command
The sed command is also known as stream editor. It is used to
edit files using a regular expression. It does not permanently edit
files; instead, the edited content remains only on display. It does
not affect the actual file.
Syntax:
1. command | sed 's/<oldWord>/<newWord>/'
Output:
27. tee command
The tee command is quite similar to the cat command. The only
difference between both filters is that it puts standard input on
standard output and also write them into a file.
Syntax:
1. cat <fileName> | tee <newFile> | cat or tac |.....
Output:
28. tr Command
The tr command is used to translate the file content like from
lower case to upper case.
Syntax:
1. command | tr <'old'> <'new'>
Output:
29. uniq Command
The uniq command is used to form a sorted list in which every
word will occur only once.
Syntax:
1. command <fileName> | uniq
Output:
30. wc Command
The wc command is used to count the lines, words, and characters
in a file.
Syntax:
1. wc <file name>
Output:
31. od Command
The od command is used to display the content of a file in
different s, such as hexadecimal, octal, and ASCII characters.
Syntax:
1. od -b <fileName> // Octal format
2. od -t x1 <fileName> // Hexa decimal format
3. od -c <fileName> // ASCII character format
Output:
32. sort Command
The sort command is used to sort files in alphabetical order.
Syntax:
1. sort <file name>
Output:
33. gzip Command
The gzip command is used to truncate the file size. It is a
compressing tool. It replaces the original file by the compressed
file having '.gz' extension.
Syntax:
1. gzip <file1> <file2> <file3>...
Output:
34. gunzip Command
The gunzip command is used to decompress a file. It is a reverse
operation of gzip command.
Syntax:
1. gunzip <file1> <file2> <file3>. .
Output:
Linux Utility Commands
35. find Command
The find command is used to find a particular file within a
directory. It also supports various options to find a file such as
byname, by type, by date, and more.
The following symbols are used after the find command:
(.) : For current directory name
(/) : For root
Syntax:
1. find . -name "*.pdf"
Output:
36. locate Command
The locate command is used to search a file by file name. It is
quite similar to find command; the difference is that it is a
background process. It searches the file in the database, whereas
the find command searches in the file system. It is faster than the
find command. To find the file with the locates command, keep
your database updated.
Syntax:
1. locate <file name>
Output:
37. date Command
The date command is used to display date, time, time zone, and
more.
Syntax:
1. date
Output:
38. cal Command
The cal command is used to display the current month's calendar
with the current date highlighted.
Syntax:
1. cal<
Output:
39. sleep Command
The sleep command is used to hold the terminal by the specified
amount of time. By default, it takes time in seconds.
Syntax:
1. sleep <time>
Output:
40. time Command
The time command is used to display the time to execute a
command.
Syntax:
1. time
Output:
41. zcat Command
The zcat command is used to display the compressed files.
Syntax:
1. zcat <file name>
Output:
42. df Command
The df command is used to display the disk space used in the file
system. It displays the output as in the number of used blocks,
available blocks, and the mounted directory.
Syntax:
1. df
Output:
43. mount Command
The mount command is used to connect an external device file
system to the system's file system.
Syntax:
1. mount -t type <device> <directory>
Output:
44. exit Command
Linux exit command is used to exit from the current shell. It takes
a parameter as a number and exits the shell with a return of status
number.
Syntax:
1. exit
Output:
After pressing the ENTER key, it will exit the terminal.
45. clear Command
Linux clear command is used to clear the terminal screen.
Syntax:
1. clear
Output:
After pressing the ENTER key, it will clear the terminal screen.
Linux Networking Commands
46. ip Command
Linux ip command is an updated version of the ipconfig
command. It is used to assign an IP address, initialize an interface,
disable an interface.
Syntax:
1. ip a or ip addr
Output:
47. ssh Command
Linux ssh command is used to create a remote connection through
the ssh protocol.
Syntax:
1. ssh user_name@host(IP/Domain_name)</p>
48. mail Command
The mail command is used to send emails from the command
line.
Syntax:
1. mail -s "Subject" <recipient address>
Output:
49. ping Command
The ping command is used to check the connectivity between two
nodes, that is whether the server is connected. It is a short form of
"Packet Internet Groper."
Syntax:
1. ping <destination>
Output:
50. host Command
The host command is used to display the IP address for a given
domain name and vice versa. It performs the DNS lookups for the
DNS Query.
Syntax:
1. host <domain name> or <ip address>
Output: