Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
9 views33 pages

Linux

Uploaded by

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

Linux

Uploaded by

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

LINUX

ADMINISTRATION
UNIT-1
OVERVIEW OF LINUX

LINUX
 The Linux operating system (or Linux OS) is an open source, freely available OS that can be
installed on a wide range of devices such as desktops, servers, smartphones and tablets,
supercomputers, video game consoles, and purpose-built devices from in-car entertainment systems,
to the Mars Rover, to medical wearables.
 Linux is a community of open-source Unix like operating systems that are based on the
Linux Kernel.
 It was initially released by Linus Torvalds on September 17, 1991.

• It is a free and open-source operating system and the source code can be modified and distributed to
anyone commercially or noncommercially under the GNU General Public License.
UNIX AND LINUX ARCHITECTURE
UNIX

 The kernel and shell are the heart and soul of the operating system.
 The kernel ingests user input via the shell and accesses the hardware to perform things like memory
allocation and file storage.
 The shell is an interface that interprets the command line input and calls the necessary programs to do the
work.
 The commands that you enter are programs themselves, so once the work is done, the command line will
return to a prompt and await further input.
 There are several different shells, and syntax and shortcuts vary between them.
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:
o Monolithic Kernel
o Micro kernels
o Exo kernels
o Hybrid kernels
Linux File System Structure
 Linux file system has a hierarchal file structure as it contains a root directory and its subdirectories.
 All other directories can be accessed from the root directory.
 A partition usually has only one file system, but it may have more than one file system
 He advanced data and the structures that it represents contain the information about the file system stored on
the drive; it is distinct and independent of the file system metadata.

 Linux file system contains two-part file system software implementation architecture. Consider the below
image:
Secondary storage
 Data storage device requirements vary, depending on the size of software installation, temporary files
created and maintained while installing or running the software, and possible use of swap space (if RAM ).
Commands for files and directories ls

In Linux, the command "ls" is one of the most commonly used. It's used to display a list of files and
sub-directories in the current directory. If you're new to using the command line, the first command
you should learn is probably ls.This command can be used by both regular users as well as system
administrators.
•INTRODUCTION TO PWD COMMAND:
•PWD stands for Print Working Directory. It writes the complete path name of the working directory to standard
output in UNIX-like and other operating systems.

•Implementations of pwd Command


 Multics had a command, i.e., pwd (which was an abbreviated name of the command, i.e., print_wdir), from
which the Unix pwd command was produced.
 The PWD command is a shell builtin into almost every Unix shell, like zsh, ksh, bash, ash, and Bourne shell.
 It can be easily implemented with the POSIX C functions getwd() or getcwd (). Also, it is available in many
operating systems, including KolibriOS, PANOS, and SpartaDOS X. The cd command, along with no
arguments, is equivalent on Microsoft Windows (cmd.exe) and DOS Windows (COMMAND.com).
 Windows PowerShell offers the same GET-LOCATION cmdlet with the pwd and gl standard aliases. On the
5.0 version of Windows CE, the command processor shell cmd.exe has the pwd command.
UNIT -2
Processes in linux

• A process is a task that your Linux machine is currently working on. For example, when you open a
browser, your machine creates a process for it.

• Let’s try to understand this by running a simple command such as ps. Here’s the syntax:

ps [options]

Process fundamentals
Redirecting input/output
• The process of using the input/output of a file or command to use it as an input for another file. It is similar
but different from pipes, as it allows reading/writing from files instead of only commands.
Background Processing
• A Linux background process is defined as being a process that is running independent of the shell or
Window Manager. You can leave the shell or exit your Window Manager and the process will keep
running with no user interaction.
Managing multiple processes
• A process means program in execution. It generally takes an input, processes it and gives us the
appropriate output. Check Introduction to Process Management for more details about a process. There
are basically 2 types of processes
• Foreground processes
• Background processes
Process scheduling

• The process scheduling is the activity of the process manager that handles the removal of the running
process from the CPU and the selection of another process on the basis of a particular strategy.

• Process scheduling is an essential part of a Multiprogramming operating systems. Such operating systems
allow more than one process to be loaded into the executable memory at a time and the loaded process
shares the CPU using time multiplexing.
Sort
The sort command is a tool for sorting file contents and printing the result in standard output. Reordering a file's
contents numerically or alphabetically and arranging information in ascending or descending order improves
readability

Touch
•The touch command is a standard command used in UNIX/Linux operating system which is used to create,
change and modify timestamps of a file. Basically, there are two different commands to create a file in the Linux
system which is as follows:
 cat command: It is used to create the file with content.
 touch command: It is used to create a file without any content. The file created using touch command is
empty. This command can be used when the user doesn’t have data to store at the time of file creation.
File
In Linux system, everything is a file and if it is not a file, it is a process. A file doesn't include only text
files, images and compiled programs but also include partitions, hardware device drivers and directories.
Linux consider everything as as file.

Files are always case sensitive. Let's understand it through an example.


UNIT 3
Shell programming:
• The shell is the Linux command line interpreter. It provides an interface between the user and the kernel
and executes programs called commands. For example, if a user enters is then the shell executes the is
command.
• In computing, a shell is a computer program that exposes an operating system's services to a human
user or other programs. In general, operating system shells use either a command-line interface (CLI) or
graphical user interface (GUI), depending on a computer's role and particular operation.
•In computing, a shell is a computer program that exposes an operating system's services to a human user
or other programs. In general, operating system shells use either a command-line interface (CLI) or graphical
user interface (GUI), depending on a computer's role and particular operation.
•More popularly known as the Bash shell, the GNU Bourne-Again shell was designed to be compatible with
the Bourne shell. It incorporates useful features from different types of shells in Linux such as Koran shell
and C shell.
 What we see here is that, generally, the syntax of all these shells is 95% similar. In this book, we are going to
follow Bash shell programming.

Shell programming in bash:

• To create a bash script, you place #! /bin/bash at the top of the file. To execute the script from the current
directory, you can run. /script name and pass any parameters you wish. When the shell executes a script, it finds
the #! /path/to/interpreter.

• Bash (Bourne Again Shell) is a shell program. It was written by Brian Fox as an enhanced version of the
Bourne Shell program 'sh'. It is an open source GNU project. It provides functional improvements over Bourne
Shell for both programming and interactive use.
•Our Bash Shell tutorial includes all the Bash topics such as Bash Scripting, variables, loops, conditional
statements, positional parameters, arithmetics, functions, strings, etc.
Prerequisite:
•Before learning Bash Shell, you must have the basic knowledge of the Linux Operating System and any
programming language
Audience:
•Our Bash Scripting tutorial is designed to help beginners and professionals.

Problems:
•We assure you that you will not find any problem in this tutorial. But if you find any mistake, please post the problem in the contact
form.
Conditional and Looping statements:
Looping statements:
The three keywords to loop in Unix/Linux shell are as follows:
1.until
The statements in the until loop are executed until the command in the condition becomes true.
Syntax
The following is the syntax of the until loop :
until command
do
Statement(s) to be executed
done
2.While
The statements in the while loop are executed until the command in the condition becomes false.
Syntax
The following is the syntax of the while loop:
while command
do
Statement(s) to be executed
done

3.For
The for loop operates on a list of items. The statements in the for loop are executed for all
items in the list.
Syntax
The following is the syntax of the for loop:
for var in word1 word2 ... wordN
do
Statement(s) to be executed
done
Conditional Statements:
There are total 5 conditional statements which can be used in bash programming
if statement
if-else statement
if..elif..else..fi statement (Else If ladder)
if..then..else..if..then..fi..fi..(Nested if)
switch statement
Their description with syntax is as follows:
if statement
This block will process if specified condition is true.
Syntax:
if [ expression ]
then
statement
Fi
if..elif..else..fi statement (Else If ladder)
To use multiple conditions in one if-else block, then elif keyword is used in shell. If expression1 is true then it
executes statement 1 and 2, and this process continues. If none of the condition is true then it processes else part.
Syntax
if [ expression1 ]
then
statement1
statement2
.
.
elif [ expression2 ]
then
statement3
statement4
.
.
else
statement5
Fi
if..then..else..if..then..fi..fi..(Nested if)
Nested if-else block can be used when, one condition is satisfies then it again checks another condition. In the
syntax, if expression1 is false then it processes else part, and again expression2 will be check.
Syntax:
if [ expression1 ]
then
statement1
statement2
.
else
if [ expression2 ]
then
statement3
.
fi
fi
switch statement
case statement works as a switch statement if specified value match with the pattern then it will execute a
block of that particular pattern
When a match is found all of the associated statements until the double semicolon (;;) is executed.
A case will be terminated when the last command is executed.
If there is no match, the exit status of the case is zero.
Syntax:
case in
Pattern 1) Statement 1;;
Pattern n) Statement n;;
Esac
Example Programs
Example 1:
Implementing if statement
#Initializing two variables
a=10
b=20

#Check whether they are equal


if [ $a == $b ]
then
echo "a is equal to b"
fi

#Check whether they are not equal


if [ $a != $b ]
then
echo "a is not equal to b"
fi
Example:

Look at the above snapshot, this is the script we have written to show the different parameters

Look at the above snapshot; we have passed arguments 1, 5, 90. All the parameters show their value when script is run.

.
UNIT-4
SYSTEM ADMINISTRATION

Linux System Administration

• It is a process of setting up, configuring, and managing a computer system in a Linux environment. System administration involves
creating a user account, taking reports, performing backup, updating configuration files, documentation, and performing recovery actions.
The user who manages the server, fixes configuration issues, recommends new software updates, and updates document is the system
administrator.

Linux Operating System

•The Linux operating system was developed by Linus Torvalds in 1991. The Linux operating system is an open-sourced system software
that manages the computer hardware resources and computing devices. The operating system manages the communication between your
application software and hardware resources. Because it is an open source software, it allows the user to have access to its source code,
give room for further modification, and allow for further distribution as received.The Linux family is called distribution (distro),
whereas the Windows operating system is called version.
Basic Administration Of Linux
Linux system administration is a process of setting up, configuring, and managing a computer system in a
Linux environment. System administration involves creating a user account, taking reports, performing backup,
updating configuration files, documentation, and performing recovery actions.

Components Of Linux Operating System


 Bootloader: This is a software that manages the boot process of your computer.
 Kernel: The kernel is also called the Linux kernel and is the system traffic controller that allocates system
resources to the running application. Software applications request the kernel for hardware resources such as
disc space, RAM, and CPU. Software applications use the API to work with the kernel on a high level of
abstraction.
Administrative log files
One of the things that Linux does well is keep track of itself. This is a good thing, when you consider
how much can go wrong with a complex operating system. Other times you want to monitor your system to see
if people are trying to access your computer illegally. In any of those cases, you can use log files to help track
down the problem.
Red Hat Linux includes a System Logs window (System Tools System Logs) you can use to view
and search system log files from the desktop. See Chapter 14 for a description of that window and of the log files
you can view with it.
Using other administrative logins
You don't hear much about other administrative logins (besides root) being used with Red Hat Linux.
It was a fairly common practice in UNIX systems to have several different administrative logins that allowed
administrative tasks to be split among several users.
The Three Kinds Of File Permissions In Linux

• Read (r): Allows a user or group to view a file.

• Write (w): Permits the user to write or modify a file or directory.

• Execute (x): A user or grup with execute permissions can execute a file or view a directory.

More ways to manage permissions

Here's a more comprehensive list of ways you can manage file permissions, groups, and ownership beyond the basic
commands listed at the top of this guide.

How to Change Directory Permissions in Linux for the Group Owners and Others

The command for changing directory permissions for group owners is similar, but add a “g” for group or “o” for
users:

• chmod g+w filename

• chmod g-wx filename

• chmod o+w filename

• chmod o-rwx foldername


UNIT – 5
SIMPLE FILTER COMMANDS
Filters are programs that take plain text(either stored in a file or produced by
another program) as standard input, transforms it into a meaningful format, and
then returns it as standard output. Linux has a number of filters. Some of the most
commonly used filters are
head
• Displays the first n lines of the specified text files.
• If the number of lines is not specified then by default prints first 10 lines.
• Syntax:
head [-number_of_lines_to_print] [path]
SQUID
•Squid is a widely-used caching proxy server for Linux and Unix platforms. This means that it stores requested
Internet objects, such as data on a Web or FTP server, on a machine that is closer to the requesting workstation
than the server. It can be set up in multiple hierarchies to assure optimal response times and low bandwidth usage,

even in modes that are transparent to end users.


•Squid acts as a caching proxy server. It redirects object requests from clients (in this case, from Web browsers) to
the server. When the requested objects arrive from the server, it delivers the objects to the client and keeps a copy
of them in the hard disk cache. An advantage of caching is that several clients requesting the same object can be
served from the hard disk cache. This enables clients to receive the data much faster than from the Internet. This
procedure also reduces the network traffic.
APACHE
•Apache is a remarkable piece of application software. It is the most widely used Web Server application in the
world with more than 50% share in the commercial web server market. Apache is the most widely used Web
Server application in Unix-like operating systems but can be used on almost all platforms such as Windows, OS

X, OS/2, etc. The word, Apache, has been taken from the name of the Native American tribe ‘Apache’, famous
for its skills in warfare and strategy making.
•It is a modular, process-based web server application that creates a new thread with each simultaneous
connection. It supports a number of features; many of them are compiled as separate modules and extend its
core functionality, and can provide everything from server side programming language support to
authentication mechanism. Virtual hosting is one such feature that allows a single Apache Web Server to serve a
number of different websites.
TELNET
•In Linux, the telnet command is used to create a remote connection with a system over a TCP/IP network. It
allows us to administrate other systems by the terminal. We can run a program to conduct administration.
•It uses a TELNET protocol. However, this protocol has some security defects, but it is one of the most used
networking protocols due to its simplicity. It is not a secure protocol because it transfers data in unencrypted
form. Often Linux user prefers ssh over telnet because ssh transfers data in encrypted form. This utility is similar
to the Remote Desktop feature in Windows.
•The syntax for the telnet is as Follows:

• telnet hostname/IP address


FTP
•The FTP server uses a Client-Server Architecture to transfer files. FTP Server is a Software Application, that
uses the File Transfer Protocol to share files over the Internet between Client and Host machine. Here we have
two machines, the end-user, which is a local host machine and a Destination, which is a remote host. Both

machines have the same FTP Server Application Software running.

•FTP server Type Files Transmission has many of its Advantages like

 It allows you to transfer multiple amounts of Files and Directories/Folders.


 In the case of Interrupted Connection, your file will not be lost, instead, you’ll be able to resume the
transfer where it dropped.
 FTP is faster than HTTP
SAMBA
 The Samba server can be defined as one of the most powerful servers in Linux that enables us to connect
various resources like printers and files with several operating systems.
 It is the open-source software that is considered as the implementation of the crucial protocol: server
message block or common internet file system. It is the system that is based on Linux but makes the
communication possible with the Windows operating system.
 The main purpose of this server is to share the files or the printers so that they could be used efficiently. The
reason it is considered as a powerful system is due to its capability to perform resource sharing.
 The samba server in Linux may also be considered as the open-source software that facilitates the file and
printer like resource sharing very easy and simple. It is ample powerful to establish communication with the
window-based systems in order to share the resources.

You might also like