Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

UNIT_1_SUDHIR

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 77

INTRODUCTION TO

LINUX AND LINUX


UTILITIES
By
Dr. Sudhir Bhardwaj
History
 Linux began in 1991 as a personal project
by Finnish student Linus Torvalds: to create a
new free operating system kernel. The
resulting Linux kernel has been marked by
constant growth throughout its history. Since
the initial release of its source code in 1991, it
has grown from a small number of C files
under a license prohibiting commercial
distribution to the 4.15 version in 2018 with
more than 23.3 million lines of source code,
not counting comments, [1] under the
GNU General Public License v2
architecture

The Linux operating system's architecture mainly contains some of


the components: the Kernel, System Library, Hardware layer,
System, and Shell utility.
Kernel
The kernel is one of the core section of an operating
system. It is responsible for each of the major
actions of the Linux OS. This operating system
contains distinct types of modules and cooperates
with underlying hardware directly. The kernel
facilitates required abstraction for hiding details of
low-level hardware or application programs to the
system. There are some of the important kernel
types which are mentioned below:
 Monolithic Kernel
 Micro kernels
 Exo kernels
 Hybrid kernels
System Libraries
 These libraries can be specified as some
special functions. These are applied for
implementing the operating system's
functionality and don't need code access
rights of the modules of kernel.
System Utility Programs
 It is responsible for doing specialized
level and individual activities
Hardware layer
 Linux operating system contains a
hardware layer that consists of several
peripheral devices like CPU, HDD, and
RAM.
Shell
 It is an interface among the kernel and user. It can
afford the services of kernel. It can take commands
through the user and runs the functions of the
kernel. The shell is available in distinct types of
OSes. These operating systems are categorized
into two different types, which are the graphical
shells and command-line shells.
 The graphical line shells facilitate the graphical
user interface, while the command line shells
facilitate the command line interface. Thus, both of
these shells implement operations. However, the
graphical user interface shells work slower as
compared to the command-line interface shells.
types of shells
 Korn shell
 Bourne shell
 C shell
 POSIX shell
Linux Operating System Features
 Portable: Linux OS can perform different types of
hardware and the kernel of Linux supports the
installation of any type of hardware environment.
 Open source: Linux operating system source
code is available freely and for enhancing the
capability of the Linux OS, several teams are
performing in collaboration.
 Multiprogramming: Linux OS can be defined as
a multiprogramming system. It means more than
one application can be executed at the same time.
 Multi-user: Linux OS can also be defined as a
multi-user system. It means more than one user
can use the resources of the system such
as application programs, memory, or RAM at
the same time.
 Hierarchical file system: Linux OS affords a
typical file structure where user files or system
files are arranged.
 Security: Linux OS facilitates user security
systems with the help of various features of
authentication such as controlled access to specific
files, password protection, or data encryption.
 Shell: Linux operating system facilitates a unique
interpreter program. This type of program can be
applied for executing commands of the operating
system. It can be applied to perform various types
of tasks such as call application programs and
others.
Drawbacks of Linux
 Hardware drivers: Most of the users of Linux face an
issue while using Linux. Various companies of hardware
prefer to build drivers for Mac or Windows due to they
contain several users than Linux. Linux has small drivers
for peripheral hardware than windows.
 Software alternative: Let's take the Photoshop example
which is a famous tool for graphic editing. Photoshop exists
for Windows; however, it is not available in Linux. Also,
there are some other tools for photo editing but the
Photoshop tool is more powerful as compare to others.
Another example is MS office which is not present for Linux
users.
 Learning curve: Linux isn't a very user-friendly operating
system. Hence, it might be confusing for many beginners.
Getting begun with Windows is efficient and easy for many
beginners; however, understanding Linux working is
complex.
We have to understand the command line interface and
finding for newer software is a little bit complex as well.
When we face any issue in the OS, the searching solution is
very problematic. Also, there are various experts for Mac
and Windows as compare to Linux.
 Games: Several games are developed for Windows but
unfortunately not for Linux. Because the platform of
Windows is used widely. So, the developers of the games
are more interested in windows.
Linux commands
sudo date mv

man stty rm

echo pwd cat

printf cd more

script mkdir wc

passwd rmdir lp

uname ls od

who cp tar & gzip


sudo
 sudo (Super User DO) command in Linux is
generally used as a prefix of some command
that only superuser are allowed to run. If you
prefix “sudo” with any command, it will run
that command with elevated privileges or in
other words allow a user with proper
permissions to execute a command as
another user, such as the superuser. This is
the equivalent of “run as administrator”
option in Windows. The option of sudo lets
us have multiple administrators.
man
 man command in Linux is used to display the user manual of any
command that we can run on the terminal. It provides a detailed
view of the command which includes NAME, SYNOPSIS,
DESCRIPTION, OPTIONS, EXIT STATUS, RETURN VALUES, ERRORS,
FILES, VERSIONS, EXAMPLES, AUTHORS and SEE ALSO.
 Every manual is divided into the following sections:
 Executable programs or shell commands
 System calls (functions provided by the kernel)
 Library calls (functions within program libraries
 Games
 Special files (usually found in /dev)
 File formats and conventions eg /etc/passwd
 Miscellaneous (including macro packages and conventions), e.g.
groff(7)
 System administration commands (usually only for root)
 Kernel routines [Non standard]
echo
 echo command in linux is used to
display line of text/string that are passed
as an argument . This is a built in
command that is mostly used in shell
scripts and batch files to output status
text to the screen or a file.
 Syntax :

echo [option] [string]


 Displaying a text/string : Syntax :

echo [string]
printf
 “printf” command in Linux is used to
display the given string, number or any
other format specifier on the terminal
window. It works the same way as
“printf” works in programming
languages like C.
 Syntax:

$printf [-v var] format [arguments]


script
 script command in Linux is used to make typescript or
record all the terminal activities. After executing
the script command it starts recording everything
printed on the screen including the inputs and outputs
until exit. By default, all the terminal information is
saved in the file typescript , if no argument is
given. script is mostly used when we want to capture
the output of a command or a set of command while
installing a program or the logs generated on the
terminal while compiling an open source codes,
etc. script command uses two files i.e. one for the
terminal output and other for the timing information.
 Syntax:
script [options] [file]
passwd
 passwd command in Linux is used to
change the user account passwords. The
root user reserves the privilege to
change the password for any user on the
system, while a normal user can only
change the account password for his or
her own account.
 Syntax:

passwd [options] [username]


uname
 The command ‘uname‘ displays the
information about the system.
 Syntax:

uname [OPTION]
who
 who command is used to find out the
following information :
1. Time of last system boot
2. Current run level of the system
3. List of logged in users and more.
 Description : The who command is
used to get information about currently
logged in user on to system.
 Syntax : $who [options] [filename]
date
 date command is used to display the
system date and time. date command is
also used to set date and time of the
system. By default the date command
displays the date in the time zone on which
unix/linux operating system is
configured.You must be the super-user
(root) to change the date and time.
 date [OPTION]... [+FORMAT]
 date [-u|--utc|--universal]
MMDDhhmm[[CC]YY][.ss]]
stty
 stty command in Linux is used to
change and print terminal line settings.
Basically, this command shows or
changes terminal characteristics.
 stty –all: This option print all current
settings in human-readable form.stty --
all
pwd
 pwd stands for Print Working Directory.
It prints the path of the working
directory, starting from the root.
pwd is shell built-in command(pwd) or an
actual binary(/bin/pwd).
$PWD is an environment variable which
stores the path of the current directory.
This command has two flags.
cd
 cd command in linux known as change
directory command. It is used to change
current working directory.
Syntax:
 $ cd [directory]
mkdir
 mkdir command in Linux allows the user
to create directories (also referred to as
folders in some operating systems ). This
command can create multiple directories
at once as well as set the permissions for
the directories. It is important to note
that the user executing this command
must have enough permissions to create
a directory in the parent directory, or
he/she may receive a ‘permission
denied’ error.
rmdir
 rmdir command is used remove empty
directories from the filesystem in Linux.
The rmdir command removes each and
every directory specified in the
command line only if these directories
are empty. So if the specified directory
has some directories or files in it then
this cannot be removed
by rmdir command.
ls
 ls is a Linux shell command that lists
directory contents of files and
directories.Some practical examples of ls
command are shown below.
 1. Open Last Edited File Using ls –t
 2. Display One File Per Line Using ls
-1
 3. Display All Information About
Files/Directories Using ls -l
cp
 cp stands for copy. This command is
used to copy files or group of files or
directory. It creates an exact image of a
file on a disk with different file
name. cp command require at least two
filenames in its arguments
 cp Src_file Dest_file
mv
 mv stands for move. mv is used to move
one or more files or directories from one
place to another in a file system like UNIX.
It has two distinct functions:
(i) It renames a file or folder.
(ii) It moves a group of files to a different
directory.
No additional space is consumed on a disk
during renaming. This command
normally works silently means no prompt
for confirmation.
rm
 rm stands for remove here. rm command is used
to remove objects such as files, directories,
symbolic links and so on from the file system like
UNIX. To be more precise, rm removes references
to objects from the filesystem, where those objects
might have had multiple references (for example, a
file with two different names). By default, it does
not remove directories. This command normally
works silently and you should be very careful while
running rm command because once you delete the
files then you are not able to recover the contents
of files and directories. Syntax:
 rm [OPTION]... FILE...
cat
 Cat(concatenate) command is very
frequently used in Linux. It reads data
from the file and gives their content as
output. It helps us to create, view,
concatenate files.
 $cat filename
more
 more command is used to view the text
files in the command prompt, displaying
one screen at a time in case the file is large
(For example log files). The more command
also allows the user do scroll up and down
through the page. The syntax along with
options and command is as follows. Another
application of more is to use it with some
other command after a pipe. When the
output is large, we can use more command
to see output one by one.
wc
 wc stands for word count. As the name
implies, it is mainly used for counting purpose.
 It is used to find out number of lines, word
count, byte and characters count in the
files specified in the file arguments.
 By default it displays four-columnar output.
 First column shows number of lines present in a
file specified, second column shows number of
words present in the file, third column shows
number of characters present in file and fourth
column itself is the file name which are given
as argument.
lp
 lp command arranges for the files specified by the
Files parameter and their associated information
(called a request) to be printed by a line printer. If
you do not specify a value for the Files parameter,
the lp command accepts standard input. The file
name - (dash) represents standard input and can
be specified on the command line in addition to
files. The lp command sends the requests in the
order specified. If the job is submitted to a local
print queue, the lp command displays the
following to standard output: Job number is: nnn
where nnn is the assigned job number. To suppress
the job number use the -s flag.
od
 od command in Linux is used to convert the
content of input in different formats with octal
format as the default format.This command is
especially useful when debugging Linux scripts
for unwanted changes or characters. If more
than one file is specified, od command
concatenates them in the listed order to form
the input.It can display output in a variety of
other formats, including hexadecimal, decimal,
and ASCII. It is useful for visualizing data that
is not in a human-readable format, like the
executable code of a program.
tar
 The Linux ‘tar’ stands for tape archive, is
used to create Archive and extract the
Archive files. tar command in Linux is
one of the important command which
provides archiving functionality in Linux.
We can use Linux tar command to create
compressed or uncompressed Archive
files and also maintain and modify
them.
gzip
 gzip command compresses files. Each
single file is compressed into a single
file. The compressed file consists of a
GNU zip header and deflated data.
If given a file as an argument, gzip
compresses the file, adds a “.gz” suffix,
and deletes the original file. With no
arguments, gzip compresses the
standard input and writes the
compressed file to standard output.
Networking Commands
unlink ps

du w

df finger

mount arp

unmount ftp

find telnet

umask rlogin
unlink
 unlink is a command-line utility for
removing a single file
du
 du command-line utility helps you to find
out the disk usage of set of files or a
directory.
 //syntax of du command du [OPTION]...
[FILE]... or du [OPTION]... --files0-
from=F
df
 The df command (short for disk free), is
used to display information related to file
systems about total space and available
space.
 Syntax :

df [OPTION]... [FILE]...
mount
 mount command is used to mount the
filesystem found on a device to big tree
structure(Linux filesystem) rooted at ‘/‘.
 Syntax:

mount -t type device dir


unmount
 command umount can be used to
detach these devices from the Tree.
find
 The find command in UNIX is a command line
utility for walking a file hierarchy. It can be
used to find files and directories and perform
subsequent operations on them. It supports
searching by file, folder, name, creation date,
modification date, owner and permissions. By
using the ‘-exec’ other UNIX commands can be
executed on files or folders found.
 Syntax :
$ find [where to start searching from] [expression
determines what to find] [-options] [what to
find]
umask
 The umask command in Linux is used to set default
permissions for files or directories the user creates.
How does the umask command work?
 The umask command specifies the permissions that
the user does not want to be given out to the newly
created file or directory.
 umask works by doing a Bitwise AND with the
bitwise complement(where the bits are inverted, i.e.
1 becomes 0 and 0 becomes 1) of the umask.
 The bits which are set in the umask value, refer to
the permissions, which are not assigned by default,
as these values are subtracted from the maximum
permission for files/directories.
ulimit
 ulimit is admin access required Linux
shell command which is used to see, set,
or limit the resource usage of the current
user. It is used to return the number of
open file descriptors for each process. It
is also used to set restrictions on the
resources used by a process.
To check the ulimit value use the
following command:
 ulimit -a
ps
 Linux provides us a utility called ps for
viewing information related with the
processes on a system which stands as
abbreviation for “Process Status”. ps
command is used to list the currently
running processes and their PIDs along
with some other information depends on
different options. It reads the process
information from the virtual files
in /proc file-system. /proc contains
virtual files, this is the reason it’s
w
 w command in Linux is used to show who is logged on
and what they are doing. This command shows the
information about the users currently on the machine
and their processes. The header shows, in this order, the
current time, how long the system has been running,
how many users are currently logged on, and the system
load averages for the past 1, 5, and 15 minutes. The
following entries are displayed for each user: login
name, the tty name, the remote host, login time, idle
time, JCPU, PCPU, and the command line of their current
process. The JCPU time is the time used by all processes
attached to the tty. It does not include past background
jobs but does include currently running background jobs.
The PCPU time is the time used by the current process,
named in the “what” field.
finger
 Finger command is a user information
lookup command which gives details of
all the users logged in. This tool is
generally used by system
administrators. It provides details like
login name, user name, idle time, login
time, and in some cases their email
address even. This tool is similar to the
Pinky tool but the Pinky tool is just the
lightweight version of this tool.
arp
 arp command manipulates the
System’s ARP cache. It also allows a
complete dump of the ARP cache. ARP
stands for Address Resolution Protocol.
The primary function of this protocol is to
resolve the IP address of a system to its
mac address, and hence it works
between level 2(Data link layer) and
level 3(Network layer).
Syntax:
 arp [-v] [-i if] [-H type] -a [hostname]
ftp
 File transfer protocol (FTP) is an Internet
tool provided by TCP/IP. The first feature of
FTP is developed by Abhay Bhushan in
1971. It helps to transfer files from one
computer to another by providing access to
directories or folders on remote computers
and allows software, data, text file to be
transferred between different kinds of
computers. The end-user in the connection
is known as localhost and the server which
provides data is known as the remote host.
telnet
 TELNET stands for Teletype Network. It
is a type of protocol that enables one
computer to connect to local computer.
It is a used as a standard
TCP/IP protocol for virtual terminal
service which is given by ISO. Computer
which starts connection known as
the local computer.
rlogin
 Remote Login is a process in which
user can login into remote site i.e.
computer and use services that are
available on the remote computer. With
the help of remote login a user is able to
understand result of transferring result
of processing from the remote computer
to the local computer.
Text Processing commands

tail nl egrep paste pg diff

head uniq fgrep join comm tr

sort grep cut tee cmp cpio


tail
 It is the complementary of head
command.The tail command, as the
name implies, print the last N number of
data of the given input. By default it
prints the last 10 lines of the specified
files. If more than one file name is
provided then data from each file is
precedes by its file name.
Syntax:
 tail [OPTION]... [FILE]...
head
 It is the complementary of Tail
command. The head command, as the
name implies, print the top N number of
data of the given input. By default, it
prints the first 10 lines of the specified
files. If more than one file name is
provided then data from each file is
preceded by its file name.
Syntax:
 head [OPTION]... [FILE]...
sort
 SORT command is used to sort a file, arranging the records in a
particular order. By default, the sort command sorts file assuming
the contents are ASCII. Using options in the sort command can
also be used to sort numerically.
 SORT command sorts the contents of a text file, line by line.
 sort is a standard command-line program that prints the lines of
its input or concatenation of all files listed in its argument list in
sorted order.
 The sort command is a command-line utility for sorting lines of
text files. It supports sorting alphabetically, in reverse order, by
number, by month, and can also remove duplicates.
 The sort command can also sort by items not at the beginning of
the line, ignore case sensitivity, and return whether a file is
sorted or not. Sorting is done based on one or more sort keys
extracted from each line of input.
 By default, the entire input is taken as the sort key. Blank space is
the default field separator.
nl
 Linux offers a wide range of commands for text
formatting and editing. While editing a text file,
you might want to display the lines with line
numbers appended before them, and here
comes the role-play of the nl command in
Linux. nl command is a Unix/Linux utility that
is used for numbering lines, accepting input
either from a file or from STDIN. It copies each
specified file to STDOUT, with line numbers
appended before the lines.
Syntax:
 nl [OPTION]... [FILE]...
uniq
 The uniq command in Linux is a
command-line utility that reports or
filters out the repeated lines in a file.
In simple words, uniq is the tool that
helps to detect the adjacent duplicate
lines and also deletes the duplicate
lines. uniq filters out the adjacent
matching lines from the input file(that is
required as an argument) and writes the
filtered data to the output file.
grep
 The grep filter searches a file for a
particular pattern of characters, and
displays all lines that contain that
pattern. The pattern that is searched in
the file is referred to as the regular
expression (grep stands for global search
for regular expression and print out).
Syntax:

 grep [options] pattern [files]


egrep
 egrep is a pattern searching command
which belongs to the family of grep
functions. It works the same way
as grep -E does. It treats the pattern as
an extended regular expression and
prints out the lines that match the
pattern. If there are several files with the
matching pattern, it also displays the file
names for each line. Syntax:
 egrep [ options ] 'PATTERN' files
fgrep
 The fgrep filter is used to search for the
fixed-character strings in a file. There
can be multiple files also to be searched.
This command is useful when you need
to search for strings which contain lots of
regular expression meta characters,
such as “^”, “$”, etc.
Syntax:
 fgrep [options] [ -e pattern_list] [pattern]

[file]
cut
 The cut command in UNIX is a command for
cutting out the sections from each line of files
and writing the result to standard output. It can
be used to cut parts of a line by byte position,
character and field. Basically the cut
command slices a line and extracts the text. It is
necessary to specify option with command
otherwise it gives error. If more than one file
name is provided then data from each file is not
precedes by its file name.
Syntax:
 cut OPTION... [FILE]...
paste
 Paste command is one of the useful commands
in Unix or Linux operating system. It is used to
join files horizontally (parallel merging) by
outputting lines consisting of lines from each
file specified, separated by tab as delimiter, to
the standard output. When no file is specified,
or put dash (“-“) instead of file name, paste
reads from standard input and gives output as
it is until a interrupt command [Ctrl-c] is
given.
Syntax:
 paste [OPTION]... [FILES]...
join
 The join command in UNIX is a command line utility for
joining lines of two files on a common field.
 Suppose you have two files and there is a need to
combine these two files in a way that the output makes
even more sense.For example, there could be a file
containing names and the other containing ID’s and the
requirement is to combine both files in such a way that
the names and corresponding ID’s appear in the same
line. join command is the tool for it. join command is
used to join the two files based on a key field present
in both the files. The input file can be separated by
white space or any delimiter.
Syntax:
 $join [OPTION] FILE1 FILE2
tee
 tee command reads the standard input
and writes it to both the standard output
and one or more files. The command is
named after the T-splitter used in
plumbing. It basically breaks the output
of a program so that it can be both
displayed and saved in a file. It does
both the tasks simultaneously, copies
the result into the specified files or
variables and also display the result.
pg
 pg displays a text file, pausing after each
"page" (the height of the terminal screen).
After each page, a prompt is displayed. The
user may then either press the newline key
to view the next page or one of the keys
described below.
 If no file name is given on the command line
, pg reads from standard input. If standard
output is not a terminal, pg acts like cat but
precedes each file with its name if there is
more than one.
comm
 comm compare two sorted files line by line and
write to standard output; the lines that are
common and the lines that are unique.
 Suppose you have two lists of people and you
are asked to find out the names available in one
and not in the other, or even those common to
both. comm is the command that will help you
to achieve this. It requires two sorted files which
it compares line by line.
the syntax of comm command:
Syntax :
 $comm [OPTION]... FILE1 FILE2
cmp
 cmp command in Linux/UNIX is used to compare
the two files byte by byte and helps you to find out
whether the two files are identical or not.
 When cmp is used for comparison between two
files, it reports the location of the first mismatch to
the screen if difference is found and if no difference
is found i.e the files compared are identical.
 cmp displays no message and simply returns the
prompt if the files compared are identical.
 Syntax: cmp [OPTION]... FILE1 [FILE2 [SKIP1
[SKIP2]]] SKIP1 ,SKIP2 & OPTION are optional and
FILE1 & FILE2 refer to the filenames .
diff
 diff stands for difference. This command is used
to display the differences in the files by comparing
the files line by line. Unlike its fellow members,
cmp and comm, it tells us which lines in one file
have is to be changed to make the two files
identical.
 The important thing to remember is that diff uses
certain special symbols and instructions that
are required to make two files identical. It tells you
the instructions on how to change the first file to
make it match the second file.
 Special symbols are:
 a : add c : change d : delete
tr
 The tr command is a UNIX command-
line utility for translating or deleting
characters. It supports a range of
transformations including uppercase to
lowercase, squeezing repeating
characters, deleting specific characters,
and basic find and replace. It can be
used with UNIX pipes to support more
complex translation. tr stands for
translate.
 Syntax :
cpio
 cpio stands for “copy in, copy out“. It
is used for processing the archive files
like *.cpio or *.tar. This command can
copy files to and from archives.
 Synopsis:
 Copy-out Mode: Copy files named in
name-list to the archive Syntax: cpio -o
< name-list > archive
 Copy-in Mode: Extract files from the
archive Syntax: cpio -i < archive

You might also like