Welcome to RedHat Linux

 RH033

Hardware Requirements
Pentium Pro or better with 256 MB RAM Or 64-bit Intel/AMD with 512 MB RAM 2-6 GB disk space Bootable CD Other processor architectures supported Itanium 2, IBM Power, IBM Mainframe

Lesson 1 Linux
Introduction

Fundamentals of

Linux is an open source operating system with highly advanced features. Topics Brief History of Linux Why is Linux? Linux Distributions

Brief History of Linux

Linux was originally developed by Linus Torvald in 1991. Linux is distributed under the GNU licenses. GNU stands for Gnu Not UNIX, it is an open source movement started by Richard Stallman in the year 1984. The main aim of GNU is to provide the O.S and its source code freely.

Why Linux?
Linux is an Open Source Software Multi-user and multi-tasking Supports most of modern PC hardware Fully supported distribution

Linux Distributions

To install Linux, choose a Linux Distribution A distribution is the Linux kernel, plus an installation program, plus some set of applications There are four general distributions
◦ ◦ ◦ ◦

RedHat SuSE Mandriva Linux Debian

Linux Distributions
The Red Hat and SuSE distributions are produced by companies by the same names. They aim at providing an easy installation procedure, and for a pleasant desktop experience. They are also good as servers, sold in boxes, with an installation CD and printed manual. Both can also be downloaded via the network. Mandriva Linux (also known as Mandrake Linux) was originated by Gael Duval. Mandriva Linux is also notable for compiling its packages with optimizations for Pentium-class and more advanced processors which are incompatible with older CPU versions such as 386 and 486.

Linux Distributions

The Debian distribution is produced by a volunteer organization. Its installation is less easy: You have to answer questions during the installation the other distributions deduce automatically. Nothing complicated as such, but requiring understanding of and information about hardware most PC users don't want to worry about. On the other hand, after installation, Debian

Logging In and General Orientation

Module 2 Logging In and General Orientation

Introduction In Linux, a terminal session starts by logging in through the terminal. When the user logs in for the first time, the user account is set and provided with a password. Topics
◦ ◦ ◦ ◦ ◦ ◦

Typical terminal session Concept of Login and Logout Opening of Shell Prompt Command Line Format Basic commands vi Editor

A Typical Terminal Session
Provides login prompt to the user Linux has two modes of terminals Graphical User Interface Character User Interface Linux has seven terminals by default (F1 – F6)

Logging In and Out

A Graphical login screen

Graphical Logout Session

Opening a Shell Prompt
Snapshot

Command Line Format

Pattern of issuing the command The commands are separated with options using spaces and symbols. The options are usually prefixed with the hyphen ( - ) Command line has three basic parts
◦ ◦ ◦

Command Options Arguments

Shell Interpretation
Shell prompt accepts commands to perform various functions like: Execute commands Variable assignment Variable substitution Filename generation I/O redirection Pipelines Command substitution Interpretive Programming language

Basic Commands

ls displays a list of files in current working directory clear date mkdir clears the screen display the system time and date creating a new directory change directories

cd directory touch

Contd… creates a new file with 0KB size

Basic Commands
vi rm mv cp opens a text editor remove files move or rename the files copy the files

rmdir removes the directory pwd display present working

exit or logout leave the session man command Read man pages on command

vi Editor

vi (visual) editor was written in 1976 by Bill Joy at the University of California, Berkeley. vi uses a small amount of memory, which allows efficient operation when the network is busy. vi is the only editor which provides basic text editing capabilities. There are three modes of operation for vi. They are:

Command mode

Usage of vi Editor
A text editor is a program used to edit files that are composed of text which can be a Simple regular text The source code of a program or Configuration file The vi text editor

Lab Exercises
Type vi editor and get the vi session

Navigating the File Systems

Introduction

Module 4 Navigating the File Systems

A file system is the methods and the data structures that an operating system uses to keep track of files. Topics The Tree Structure The File System Hierarchy Path Names Basic File System Commands Create and Remove Directories

The Tree Structure

Linux File Structure

Example: /home/condron/source/xntp

The File System Hierarchy
File System Hierarchy Standard (FHS) The directories and files noted here are small subsets of those specified by the FHS document. The /dev/ Directory The /etc/ Directory The /lib/ Directory The /mnt/ Directory The /opt/ Directory The /proc/ Directory The /sbin/ Directory

Path Names

A PATH is an environment variable that is a list of directories that the operating system looks in to find commands issued by the user. Example 1: # whereis ls ls: /bin/ls /usr/share/man/man1/ls.1.gz

There are two types of path names
◦ ◦

Relative Path Absolute Path

Contd…

Path Names

Absolute path

Accessing a particular directory or file from the other location, by typing the full details of path. Absolute path starts with the root (/) directory. It includes all directories and sub-directories. A relative path starts in your present working directory.

Relative path

Accessing a particular directory or file from same location, by typing the file or directory name. In the case of relative path, the path does not start with a slash.

Basic File System Commands

pwd It displays the user’s present working directory. ls Lists the contents of the files and directories cd directory. Changes and also opens the

cat It combines files and print on the standard output find Command The find command

Creating directories

Create and Remove Directories

Use mkdir command to create a new directory

Syntax # mkdir <new directory name> Example: mkdir dir1

Removing directories

There are two commands you can use for removing directories. ◦ rmdir

rm -r

Lab Exercise
How will you create a new directory?

Use rm –r to remove the existing directory.

Managing Files

Module 5
Introduction

Managing Files

“On a Linux system, everything is a file; if something is not a file, it is a process.” Topics What is a File? File Characteristics What can we do with Files?

What is a File?

A file is a container for data or link to a device. Every file has a name and may hold data that resides on a disk. A file is a name and the associated data is stored on a mass storage device. It is a stream of data bytes. The different types of files are:
◦ ◦ ◦

Regular files Can be text, data and drawings. Executable programs.

File Characteristics
A file has several characteristics associated with it. They can be displayed using the ls –l command as shown below:
[root@localhost total 1872 -rw-r--r-1 drwxr-xr-x 3 drwx-----8 -rw-r--r-1 -rw-r--r-1 drwxr-xr-x 3 -rw------1 drwx-----7 -rw-r--r-1 [root@localhost root]# ls -l root root root root root root root root root root]# root root root root root root root root root 1134 4096 4096 47186 3436 4096 1832960 4096 51 Sep Oct Oct Sep Sep Oct Oct Oct Oct 28 12:31 anaconda-ks.cfg 3 15:29 Desktop 3 15:15 evolution 28 12:30 install.log 28 12:30 install.log.syslog 1 12:48 intro-linux 1 12:42 intro-linux.html.tar 1 14:45 Mail 3 12:44 new.txt

Contd…

File Characteristics
Example: -rw-r--r-- 1 root root 1134 Sep 28 12:31 anaconda-ks.cfg 0 1 2 3 4 5 6 7  The explanation of output is as follows:

◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦

File Type – regular file d directory l link file c character special file b block special file p pseudo special file Permissions No. Of links to the File

Contd…

File Characteristics
Owner Group File Size Bytes Time Stamp File Name

What can we do with Files?

A file is a collection of data, stored on disk and that can be manipulated by listing the contents in the directory, changing the locations of files and directories, viewing files, creating and editing files, moving, copying and deleting files. The user can also create directories, change directories, delete directories and view PDF files. A directory is also a file that acts as a folder for other files.

Manipulating files and directories Copying files
Copying files and directories is done using the cp command. The cp command is used to copy the files and directories from the specified source to the specified destination. The user can copy a file into the directory, but under a different name. Syntax cp <file name> <directory name> Example: # cp file1 dir1 Removing files The rm command is used to remove single files, rmdir to remove empty directories (Use ls -a to check whether a directory is empty or not). The rm command also has options for removing nonempty directories with all their subdirectories, read the Info pages for different options of rm command. Contd…

Moving and Renaming files

Manipulating files and directories
Example of moving a file: # mv file1 /iiht/file1

The mv command is used to move a file from its source to any location within the file structure.
Example of moving a file: # mv file1 /iiht/file1 The above example says, the file file1 is moved to a different directory iiht.

The mv command is also used to rename a file or a directory Example of renaming a directory: # mv iiht dir1

Contd…

Manipulating files and directories Linking files
A link is nothing more than a way of matching two or more file names to the same set of file data. There are two ways to achieve this: Hard link Soft link

Hard link Associates two or more file names with the same inode. Hard links share the same data blocks on the hard disk, while they continue to behave as independent files.

Soft link or symbolic link (or symlink) Soft link is a small file that is a pointer to another file. A symbolic link contains the path to the target file instead of a physical location on the hard disk. Since inodes are not used in this system, soft links can span across partitions.

Lab Exercise
Create a directory by name test and create the files file1 file2 and file3, create hardlink for file1 to new file data. Differentiate deleting hard link files and soft link files.

File Permission and Access

 Introduction

Module 6 File Permission and Access

Linux is a multi-user system where users can assign different access permission to their files. Access permissions can be set per file for owner, group and others on the basis of read (r), write (w) and execute permissions (x).
Topics

◦ ◦ ◦ ◦

File Permissions and Access Types of Access Who has to Access to a File? Access Control Lists

Contd…

File Permissions and Access
 Every File

file is owned by a particular user.

permissions specifies who has the access to file and what type of access the user has. a Linux system, there is typically more than one user that provides a mechanism known as file permissions (rwx), which protect user files from accessing by other users. of permissions

On

Types

◦ r – read ◦ w –write ◦ x –execute
Contd…

File Permissions and Access
 read

permission

The read permission lets a user read the contents of the file. For directories, read permission lets the user list the contents of the directory (using ls).
write

permisison

The write permission lets the user write and modify the file. For directories, write permission lets the user create new files or delete files within the directory.
execute

permission

The execute permission lets the user run the file as a program or shell script (if the file is a program or shell script). For directories, execute permission lets the user open the directory.

Types of Access
 In

Linux, every file or folder has access permissions. There are three types of permissions.
◦ read access ◦ write access ◦ execute access

 Permissions

are defined for three types of users:

◦ owner of the file ◦ group that the owner belongs to ◦ other users

Contd…

Types of Access
 Default

file permissions

By default, the Linux system assigns certain permissions to a newly created file. The maximum permissions that we can set for an ordinary file is 666 and for directories and an executable files is 777. ◦ The default file permission for an ordinary user is 664 and for root it is 644.
Displaying

the umask

◦ The default umask file permissions for ordinary users are 002 and for root it is 022.
◦ where, ◦ 002 imply masking write permission for others and ◦ 022 implies masking write permission for the group and others.

Contd…

Types of Access
 Displaying

the umask

◦ To display the default mask use the umask command.
◦ ◦ Example # umask

Displaying

the default umask value

Contd…

Types of Access
Changing

the umask

◦ To change the default umask use the command
◦ ◦ ◦ Syntax # umask <umask value> Example: umask 004

Who has to Access a File?
The

owner and the root have the main access rights over a file. Example
◦ First column gives the access permissions to the user, group and others. ◦ Second column shows the user or owner of the file. ◦ Third column shows the group to which the file belongs.

Access permission

user(owner) group

Contd…

Who has to Access a File?
Changing

permissions

◦ chmod command ◦ chmod changes the access permissions according to the options for directories and files. Syntax # chmod o+w <filename>

Contd…

Who has to Access a File?
 The

chmod command can be used with alphanumeric or numeric options.
◦ Example of symbolic method ◦ chmod u+rw,g-rwx,o-rwx file1
◦ The above example, adds the read and write permission to the user (owner) removes the read, write and execute permission from the group to which the file belongs and removes the read, write and execute permissions for others.

◦ Example of numeric method ◦ # chmod 600 file1

◦ 6 indicates user (owner), 0 indicates group and the last number 0 indicates others.

Contd…

Who has to Access a File?
 Changing

ownership

◦ chown command

◦ chown changes the owner and group of the file and directory.

◦ Syntax

◦ # chown <username> <filename>

◦ Example

◦ # chown user1 file1.txt
Contd…

Who has to Access a File?
Special

File Permissions

◦ There are three types of special file permissions
set user identity (SUID) set group identity (SGID) sticky bit

Contd…

Who has to Access a File?
 SUID

or setuid

◦ It is represented by the character ‘s’ in the user permission field. ◦ When this mode is set on an executable file, the other users can login and run the executable file. ◦ The root’s id is set to the process.
◦ ◦ Syntax #chmod u+s <program name>
where, u – user s - suid

Contd…

Who has to Access a File?
 SGID

or setgid

◦ It is also represented by the character ‘s’ in the group permission field. ◦ The sgid permission for the user’s own directory is set by the user. ◦ When any other user creates a new file, the file gets the group membership to which the directory belongs to and not to the primary group of the user.
◦ ◦ Syntax chmod g+s <directory name>
where, g – group s – suid

Example:

$ chmod g+s test
Contd…

Who has to Access a File?
 Sticky

bit

◦ If the sticky bit is set on directory, even others can read and write the data to the file, but can not delete the file except the owner. Syntax #chmod o+t <directory name>
where, o – others t - sticky bit

Example:

# chmod o+t /tmp
Contd…

Access Control Lists (ACLs)
 ACL

is an object associated with a file and contains entries specifying the access that individual users or groups of users have to the file. provides a simple way of granting or denying access for a specified user or groups of users on single file at the same time. the chmod command the user can set permissions to owner, group or others. ACL, the owner can set the different permissions on a single file for different users.
Contd…

It

Using

Using

Access Control Lists (ACLs)
 Setting

ACL using Setfacl

◦ setfacl - set file access control lists ◦ Syntax
◦ setfacl – <option> u:<username>:<permissions> <filename>

Contd…

Access Control Lists (ACLs)
Getting

ACL using getfacl

◦ The getfacl displays the file name, owner, the group, and the Access Control List (ACL). ◦ Syntax

◦ # getfacl <filename>

Contd…

Access Control Lists (ACLs)
Copying

ACL

◦ The acl’s can be copied to any files, for which the files get the same acl permissions from its source file. ◦ Syntax getfacl <acl filename> | setfacl --set-file= <filename>
where, --set-file options set the acl of a file or a directory

Contd…

Lab Exercise
Change

the permission of the following file using chmod command.
-rwx-rw-r-file2.txt

From

the following example change the permissions to
◦ User – read, write, execute ◦ Group – read and execute ◦ Others - only execute

Shell Basics

Module 7
 Introduction

Shell Basics

The use of a program that serves as an interface between user and operating system is called the shell. The shell is a kind of interpreter on the text console after the login session. This is called the login shell.
Topic

◦ ◦ ◦ ◦ ◦ ◦ ◦

What is a Shell? Aliasing File Name Completion Command History User profiles What Happens At Login Variables

What is a Shell?
A

shell manages the interaction between the system and its users. A shell is a program which takes user input (e.g. commands which you type) and translates them into instructions that the operating system can understand. The shell allows the user to handle a system in a very flexible way.

Contd…

What is a Shell?
 Shell

Features

◦ Command history

◦ The command history buffer stores the commands you enter and let you display them at any time.

◦ Command aliases

◦ The command aliases feature lets you abbreviate long command lines or rename commands.

◦ File name completion

◦ The file name completion feature saves typing by allowing you to enter a portion of the file name. When you press the tab/esc key, the shell will complete the file name for you.

◦ Command line editing

◦ This allows you to retrieve a previously entered command and edit Contd… it.

What is a Shell?
 Types

of shells

◦ sh or Bourne Shell

◦ This is the basic shell, a small program with few features. This shell does not support any of the shell features such as history, command line completion, command line editing.

◦ bash or Bourne Again shell

◦ The standard GNU shell, intuitive and flexible. bash is the standard shell for common users. This shell is a so-called superset of the Bourne shell. This means that the Bourne Again shell is compatible with the Bourne shell: commands that work in sh, also work in bash.

Contd…

What is a Shell?
 Types

of shells

◦ csh or C shell:

◦ This shell has a syntax that resembles that of the highly popular C programming language and thus preferred by programmers.

◦ tcsh or Turbo C shell

◦ This shell is based on csh but also has programmable filename completion, command-line editing, a history mechanism and other features lacking in csh.

◦ ksh or the Korn shell:

◦ This shell is a superset of sh. It also features built-in arithmetic evaluation and advanced scripting capabilities similar to those found in powerful programming languages such as awk, sed and perl.

Aliasing
 The

command aliases allow the user to abbreviate long command lines with small names easy to use and type. Aliases

Creating

◦ To create aliases, use the alias command. The format of the alias command is:
◦ ◦ Syntax alias aliasname=command

◦ The aliasname entry specifies the name you want to use. ◦ The alias helps for alternate names for complicated commands. ◦ Example:
◦ [root@localhost root]# alias cls=clear ◦ [root@localhost root]# cls

Contd…

Aliasing
 Display

Aliases

◦ To display alias definitions, enter the following command:
◦ # alias

Remove

Aliases

◦ To remove an alias for the current login session, use the unalias command. ◦ The general format of the unalias command is the following:
◦ unalias <aliasname>

File Name Completion
 File

name completion is one of the most useful features of the Linux command line. shell lets you enter a portion of a file name or pathname at the shell prompt and the shell automatically will match and complete the name.
◦ Example
◦ # vi us<tab> Press Enter

The

Then

the entire file name will be completed as follows if it is unique name,
# vi user123.filnename.txt

Command History

The command history buffer stores the commands you enter and let you display them at any time.
◦ As a result, you can select a previous command, or parts of previous commands, and then reexecute them. ◦ This feature may save time because it lets you reuse long commands instead of reentering them. ◦ To see the contents of the history buffer, use the history command.

[root@localhost root]# history 10 1 ls *.xml 2 mv Getting\ Help\ HOWTO.xml linux-help-how-to/ 3 cls 4 ls 5 cd linux-help-how-to/ 6 ls 7 history 8 history 9 ls 10 history 10

User profiles
 The

user profile is a personalized settings of the user and the shell script and gets executed whenever the user logins. profile can be classified into:

The

◦ System wide

The changes to system wide profile will effect the work environment of all users. These files are available in /etc.

◦ User Specific

User specific profiles effect the work environment of only that particular user and it stores in the home directory of each user.

What Happens At Login
 When

a user logs into a system it executes the start up scripts in the following sequence:
◦ /etc/profile – sets the environmental variables and settings for all users. ◦ /etc/profile.d. – runs the login script for all users. ◦ ~/.bash_profile - sets the environmental variables and settings for particular user. ◦ ~/.bashrc - runs the login script for particular user. ◦ /etc/bashrc - sets the environmental variables for bash shell.

Variables
A

variable is a label that has a value. are used to configure the shell.

Variables To

set a variable in the shell, use an equal sign to assign it a value. If the variable does not already exist, it is created.
◦ A new variable is defined as follows:
◦ $ MYVARIABLE=hello

Example

To

display the value of a variable, prefix the variables name with a ‘$’ symbol.
Contd…

Variables
Types

of Variables

◦ There are two types of variables
◦ Shell variables or local variables ◦ Environment variables
Shell variables or local variables are available only to the current shell which is used to configure shell.  Environment variables are available to all shells and used to configure other commands. e keyboard arrows. To move up and down in the history command shell. It helps to change the main variables like prompt settings, color settings by changing within the profile to make effect for the entire settings.

Contd…

Variables
 Display

variable

◦ set command is used to display the local and environment variables in a system. ◦ env command is used to display only environmental variable. ◦ There are two commonly used Variables
◦ Local variables ◦ Environment variables

Contd…

Variables
 Local

variables

◦ HISTFILESIZE - specifies the number of commands of history to be saved when the shell exit. ◦ COLUMNS- sets the width of the terminal. ◦ LINES- sets the height of the terminal.
Environment

variables

◦ ◦ ◦ ◦ ◦

HOME- path to the user home directory. LANG- sets default language. PWD- present working directory. PATH- the path for the command locations. These variables are stored in the profile file (.bashrc).

Lab Exercise
Create

an alias for date command as d. Check and remove the alias. the history command and get back some command and check the history file.

Check

Shell Advanced Features

Introduction

Module 8 Features

Shell Advanced

In Linux systems, the shells are often referred to as command line interfaces. The shell capabilities provide a configurable environment allowing the users to modify commands and prompts.
Topics

◦ ◦ ◦ ◦

Shell Substitution Capabilities Setting Shell Variables Quoting Characters File Name Generationss

Shell Substitution Capabilities
Substitution

capabilities are used to speed up command line typing and execution. shell substitutions are of three types:

The

◦ Variable Substitution ◦ Command substitution ◦ Tilde Substitution

Contd…

Shell Substitution Capabilities
Variable

Substitution

◦ Variable substitution is assigning the absolute path of a file or directory to any variable. This allows the user to access the directory or file from anywhere in the file hierarchy. Syntax: <new variable>=$<system variable> <arguments> Example: myfile=$HOME/file1

Contd…

Shell Substitution Capabilities
Command

substitution

◦ Command substitution is the mechanism used to replace a command with its output, within the same command line. Syntax: <new variable>=$(command) Example: mydir=$ (pwd)

Contd…

Shell Substitution Capabilities
Tilde

Substitution

A tilde is replaced for the quick reference of home directory. Syntax: <command> ~ Example: ls ~

Setting Shell Variables
 The

new variable can be created and assigned to an existing environmental variable such as path. new value replaces the old value in the environment and the same can be displayed by using the display value commands.
Syntax <variable name>=<arguments>
Example myfile_name=/root/file1

The

Contd…

Setting Shell Variables
Displaying

variable values

◦ The variables can be displayed by using $ <variable>. ◦ It can be local variable (assigned by the user) or environmental variable (default variable). ◦ All setting variables can be displayed by using the command set.

Quoting Characters
 There

are some characters in the Unix system and each has the meaning for the shell and is called as special characters. The special characters are:
◦ ◦ ◦ ◦ ◦ $ # * <>

Quoting

removes the special meaning of the above characters. The quoting characters are:
◦ \ Backslash ◦ ‘ ’ Single quotes “ ” Double quotes ◦

Contd…

Quoting Characters
Backslash

(\)

Backslash removes the special meaning of the character immediately following the backslash.

Contd…

Quoting Characters
Single

quotes ( ‘ ’)

The single quote is used to preserve the literal value of special character enclosed within the quotes.

Contd…

Quoting Characters
Double

quotes ( “ ” )

Double quotes removes the special meaning of all the characters except \ , $ (variable name), $ (command).

File Name Generation
 The

file name generation has the timesaving feature for typing the filenames. This feature is called file name generation or filename expansion.
◦ Advantages of file name generation
◦ File name generating characters are interpreted by the shell. ◦ The command operates on the generated file names. ◦ The shell will generate file names that satisfy the requested pattern. ◦ File name generation is done before the command is executed.

The
◦? ◦*

special characters that are interpreted by the shell for file name generation are:
Matches any single character except a leading dot Matches zero or more characters except a leading dot

Contd…

File Name Generation
Usage

of the special character ‘?’

Contd…

File Name Generation
Usage

of the special character ‘*’

Lab Exercise
Give

one example on usage of single quotes command with the variable substitution the files which has 9 characters and with the extension .jpg

Display

Input and Output Redirection

 Introduction

Module 9 Input and Output Redirection

One important thing you have to know to understand I/O redirection is file descriptors. There are three types of I/O, called a file descriptor. They are standard input, standard output, standard error.
Topics

◦ ◦ ◦ ◦ ◦

Input Redirection Output Redirection Error Redirection Filter Pipes

Input Redirection
 The

standard input (stdin) by default is any text entered from the keyboard. input can be redirected through the use of command line argument and redirection operators (like <) so that it becomes a source other than the keyboard argument. input redirection is generally useful if you have a data file and a command that expects input from standard input.

Standard

The

Contd…

Input Redirection
 Example

of input redirection

Output Redirection
The

default standard output (stdout) is the display screen. command line programs automatically send their output to the screen. output can be redirected through the use of command line argument and redirection operators (like >). standard output can be redirected from the screen to any file or to the printer.
Contd…

The

Standard

The

Output Redirection
Example

of output redirection

# ls > list.file ◦ Syntax # command > (file name

Error Redirection
 By

default the standard error (stderr) displays on the terminal and can be redirected into a file, printer and any other program. Standard error can be redirected with the standard error redirection operator (i.e 2>, 2>>). error messages can be redirected to any file, so that the error messages will not appear on the screen and it is written to the file.

The

Contd…

Error Redirection
Example

of error redirection

# ll myfile 2>error_message ◦ Syntax command (filename) 2> (filename)

 There

Common Redirection Operators
> >>

are two common redirection operators

◦ ◦

◦ > operator sends the input of command or file to the other file as standard input, overwriting the existing file. ◦ > > operator sends the input of command or file to the other file as standard input, appending text to an existing file, instead of overwriting the file.
Contd…

Usage

Common Redirection Operators
of > operator

◦ Syntax # cat > (filename)

Contd…

Usage

Common Redirection Operators
of the >> operator

Contd…

Filters

Filters take standard input and perform an operation upon it and send the results to standard output.
◦ Example for filters: grep root /etc/passwd ◦ The grep command is used to filter the root user from the /etc/passwd file.

Pipes
A

pipe is a mechanism for interprocess communication.

The

data written to the pipe by one process can be read by another process. It is handled in a first-in, first-out (FIFO) order. ( | ) let you redirected output from one command to become input to another command.
◦ Example: simple pipe with “more” ls -l | more

Pipes

Contd…

Pipes
 The

tee command

◦ The tee command copies the standard input to standard output and also to any files given with an argument. ◦ This is useful when you want not only to send some data down a pipe, but also to save a copy. ◦ If a file being written which does not already exist, it is created. ◦ If a file being written which already exists, the data contained is overwritten unless the -a option (appends the standard input to the given files rather than overwriting)

Contd…

Pipes
 Example

of tee command

◦ Syntax ◦ tee <option> <file name>

Lab Exercise
Filter

and display the word blue from the file my_sortfile and redirect the data from one file to another

Sort

Networking in Linux

Networking in Linux
 Introduction

A computer network is defined as a number of systems that are connected to each other and exchange information across the network connection. The system network is configured by setting the IP address which is assigned by the system administrator. The IP address provides base services for transmitting data between networks in TCP/IP (Transmission control protocol/Internet protocol).
Topics

◦ ◦ ◦ ◦ ◦

Network Connectivity IP address Accessing Remote system Transferring files Internet configuration

Networking in Linux
 The

Linux system can be connected to the network with the help of network hardware. hardware can be LAN (Local area network) card, cables, hub/switch or router. To configure the network for the system, TCP/IP (Transmission Control Protocol/Internet Protocol) address is required from the system administrator. IP address can also be obtained from the DHCP (Dynamic host configuration protocol) server configured by the system administrator. the system is connected to the network, the resources can be shared and data can be transferred among the systems. LAN services (telnet, SSH - Secure Shell, FTP – File transfer protocol) enables the file transfer and remote login to the system.

Network

The

When

The

IP Address
 An

IP address is a 32 bit binary number usually represented as 4 decimal values, each representing 8 bits, in the range 0 to 255 (known as octets) separated by decimal points. system in network is assigned a unique identifying number called IP address. is used in order to identify and communicate with different systems present in the network. data is sent across the network and contains a source and destination IP address.
◦ ◦ ◦ ◦ Example: 10.10.1.240 130.130.1.10 192.168.1.200

Every

It

The

IP Address
Configuring

IP address

The system can be a part of network by configuring the IP address. The IP address can be set by two options in CUI mode and GUI mode. ◦ Static IP ◦ Dynamic IP (DHCP)

IP Address
 Static

IP: A static IP address is configured manually by physically entering the IP address in configuration dialog box and it does not change until altered manually. The static IP is assigned by the system administrator. IP: In a large computer network, the process of assigning IP address is simplified using a DHCP server. A DHCP server is used to automatically assign the IP address to the computers that are configured as a DHCP client. following commands are used to configure and verify the IP address from the command line prompt.
◦ ◦ ◦ ◦ netconfig service network restart ifconfig ping

Dynamic

The

IP Address
Static

IP address in CUI mode of the static IP address

Configuration

◦ Syntax Type the command # netconfig (Press Enter key) at the command prompt in the terminal window.

IP Address
network

service

◦ Syntax # service network restart

IP Address
#

ifconfig

IP Address
#

ping <IP address>

IP Address
Dynamic

IP address in CUI mode of the dynamic IP address

Configuration

◦ Syntax # netconfig (Press Enter key)

IP Address
Static

IP address in GUI mode configuration in static IP

Network

IP Address
Dynamic DHCP

IP address in GUI mode

settings

IP Address
 Host

Name

A hostname is the unique name assigned to each host on the network. The hostname is used to identify a particular IP address. Hostnames are used by various naming systems like telnet, ssh, FTP, GFTP, NIS and DNS. ◦ There are three ways to resolve host names to IP addresses on a Linux system:
◦ /etc/hosts ◦ DNS (Domain name service) ◦ NIS (Network information service)

Contd…

IP Address
 etc/hosts

is a configuration file maintained locally on each host to resolve hostnames to IP addresses. On a small network, it is easy to maintain the name resolution of hostnames to addresses. When adding or removing hosts, or reassigning IP addresses, the user have to update the /etc/hosts file. (Domain name service) will resolve the host names into IP addresses in a large network. (Network information service) provides a central point of administration for common configuration files like /etc/passwd, /etc/hosts. It preserves the consistency of the configuration files across all the systems on the network. It simplifies configuration file updates considerably.

DNS

NIS

Accessing Remote System
 Systems

in the network can be accessed remotely with help of network connectivity and using IP addresses in two ways:
◦ Telnet ◦ SSH ◦ Telnet
◦ Telnet is a terminal program for TCP/IP networks such as the Internet. ◦ The telnet program runs on your computer and connects your system to the other system present in the network. ◦ To start a telnet session, you must log in to other system by entering a valid username and password of the other system.

Contd…

Accessing Remote System
 telnet

session

◦ Syntax # telnet <destination IP address>

Contd…

Accessing Remote System
 SSH

SSH is a program for logging into a remote machine and for executing commands on a remote machine ◦ The root user can login through SSH and execute the system administrative command. ssh command ◦ Syntax ssh <destination IP address>

Transferring files
 Files

can be transferred among various systems in the network by using FTP, GFTP and SCP (secure copy).
◦ FTP
◦ FTP (File transfer protocol) is a program that allows you to transfer the files between computers present in the network. It can also transfer the files among different operating systems. ◦ Example: Linux to Linux, Linux to Windows, Windows to Linux. ◦ Syntax
 # lftp <destination IP address>

Transferring files
GFTP

GFTP (Graphical file transfer protocol) is the tool used for uploading and downloading the files in a graphical mode.
GFTP

(Graphical file transfer protocol) session

Contd…

Transferring files
SCP

(secure copy)

◦ The scp command is used to copy the files from other system present in network. ◦ Syntax # scp <filename> <destination IP> : <destination path> ◦ Example: scp file1 192.168.1.171:/root

Internet configuration
In

Linux, internet can be browsed both in GUI mode as well as CUI mode. The internet can be configured after the network connectivity.
◦ Configuring internet in GUI mode ◦ Step 1: Web browser (Mozilla)

Internet configuration
Step

2: Proxy configuration

Contd…

Internet configuration
Step

3: Setting the proxy IP and the port number

Contd…

Internet configuration
Step

4: Verifying the Internet connectivity

Contd…

Internet configuration
Modem

◦ Modem (stands for modulator-demodulator) is a device that enables a system to transmit data over telephone lines for internet connectivity. ◦ It converts digital computer signals into analog format for transmission of data.

Internet configuration
Connection

to internet through modem

Lab Exercise
How

to configure the IP address in CUI mode? Assume that your system administrator or lab in-charge has given you the IP Address as 192.168.1.60? your system to be a part of network and communicate with other systems present in the work your system with Dynamic IP Address using

Check

Configure

DHCP
Name

the command to copy the files among the system in the network with out using ftp? the command to copy the files among the system in the network with out using ftp?

Name

Process Control

Module 11
 Introduction

Process Control

◦ A process is a running occurrence of a program, including all variables and other conditions. It is an executing program. ◦ Each process contains a system wide unique process number (PID- Process Identification).
Topics

◦ ◦ ◦ ◦

Identifying Process Managing Process Background Processing Putting Jobs in Background

Identifying Process
 The

operating system will execute the processes by default and the user can also create a process. process can be identified which is in execution along with its PID (process identification number). creation

The

Process

Processes

are created with the fork system call (the operation of creating a new process is called forking).
◦ Example: vi
Contd…

Identifying Process
 Viewing

the process origin

◦ The pstree command is used to display the process origin.

Contd…

Identifying Process
Viewing

the current process

The ps command is one of the tools for visualizing processes. It displays the current working shell. Since ps command does not give detailed information about the process, the grep command in a pipe is used to select a particular process out of the list of all processes.

Managing Process

The bg command is used to check and move a job to background

Contd…

Managing Process
Example

for foreground

Contd…

Managing Process
 Process

Scheduling

◦ The Linux kernel uses a process scheduler to decide which process has to be executed first. It is done by using process priority.
Scheduling

Priorities

◦ Every process has a scheduling priority. The operating system determines the priority of a process based on nice value method. To calculate this priority is difficult, but users can affect the priority by setting the nice value. The niceness value is the number ranging from -20 (highest priority) to 19 (lowest priority) It has a default value of zero. Process with a high priority gets to run more often, while the low priority background tasks, run less frequently.

Contd…

Managing Process
 Priorities

for programs

◦ The nice values of active processes can be viewed using the ps command with the –l or –f option for long output.
Example

for nice command:

◦ The nice command is used to modify the default niceness value. To set the niceness value to a different value, use the –n option:
Example:

Contd…

Managing Process
Showing

priorities of different process

Contd…

Managing Process
Usage

of top command

◦ The top program displays all the system and user’s process priorities running in all the terminals.
◦ The process running on your system is updated once in every five seconds. ◦ A process in the running state is highlighted.

Contd…

Managing Process
Altering

priorities of running programs

◦ The users can reduce the priority of currently running jobs using the renice command. Only the superuser is permitted to move up the priority of currently running processes. ◦ Example of renice command

Contd…

Managing Process
Terminating

the process

◦ The process is terminated when it receives a signal. ◦ There are multiple signals that the user can send to a process. ◦ The kill command is used to send a signal to a process. ◦ The command kill -l shows a list of signals which the user wants to terminate.

Contd…

Managing Process
killall

command will perform an orderly shutdown of the process.

Contd…

Managing Process

killing a process

Background Processing
A It

background process is the child of the process.

refers to processes that are run with a relatively low priority, require little or no input, and produce a minimum of output. background is also used for long tasks that require massive amount of computation and thus CPU time. (Disk and execution Monitor)

The

Daemon A

daemon is a background process that is considered to run independently, with little or no user interference. Apache web server http daemon (httpd)

Example:

Putting Jobs in Background
 The

shell offers a feature called job control which allows easy handling of multiple processes. This mechanism switches processes between the foreground and the background. Using this system, programs can also be started in the background immediately. jobs in background

putting jobs

command is used to verify the background process

Contd…

Putting Jobs in Background
Suspending

a process

◦ A process can be suspended temporarily without being killed. Suppose that ‘&’ symbol is missed out by mistake, use ^z and the process will be suspended. ◦ The process still exists but is idling. To resume the process in the background type the bg command (background).

Lab Exercise
 Create

a process vi with filename and send the process to background and check background process the background running process and bring it to the foreground

Check How

to send running process to the background and bring it back to the foreground? a Process using find command with the priority of -18 and manage the priorities with the single command

Start

Display

Offline File Storage

Introduction

Module 12 Storage

Offline File

Backup is usually done by first collecting all the data in a single archive file, which can be compressed using the compression tools.
Topic

◦ Storing files to Media

Storage files to Media
 Backing

up of a system is the most major task to be performed by a system administrator. have the major advantage of storing the data, which makes it significant. are important because of the possibility of loss of data. possibility of data loss can be by:

Computers

Backups

The

◦ ◦ ◦ ◦

File system corruption Accidental removal of files Hardware failures System crash

Contd…

Storage files to Media
 Backup

Media

◦ The following are some of the methods of back up through media
◦ floppy disks ◦ Tapes ◦ removable hard disks ◦ rewritable CD-ROMs

Backup

tools

◦ tar ◦ dd ◦ Dump ◦ cpio
Contd…

Storage files to Media
 Backup

using tar command

An archiving program designed to store and extract files from an archive file known as a tarfile. The tar is the most commonly used command for the backup. ◦ tar options

◦ tar –cvf (creating the tar file) ◦ tar –tvf (listing the contents of tar file) ◦ tar –xvf (extracting the contents of tar file)
where,      c – create t – list x – extract v – verbose f – file

Contd…

Storage files to Media
Backup

using dd command

dd copies a file from source to destination. It copies an input file (if) file and sends the result to the output file (of) which converts and formats according to the options. ◦ Syntax # dd if=<source name> of=<destination name> ◦ Example dd if=bootdisk.img of=/dev/fd0

Contd…

Storage files to Media
 Backup

using dump/restore command

◦ dump and restore commands are the two different programs that are included in the dump package. ◦ These files are copied to the given disk, tape or other storage medium for protection. ◦ Syntax dump - <dump levels> - <options> <destination name> <source name>

Contd…

Storage files to Media
Example:

dump -0 –f /home_dumps/mydumps /home ◦ where, -0 - dump level (full backup) -f - write a backup to file

Contd…

Storage files to Media
Backup

using restore command

The restore command is used to view and restore the dump

file. ◦ Syntax: # restore - <options> <file name> ◦ Example: restore –if mydumps
where, -i is interactive restoration -f is read backup from file

Contd…

Storage files to Media
 Backup

using cpio command

◦ The cpio command is a tool for creating and extracting archives, or copying files from one place to another, which contains other files and information about them, such as their file name, owner, timestamps, and access permissions. ◦ It handles a number of cpio formats as well as reading and writing tar files. The archive can be another file on the disk, a magnetic tape, or a pipe.

Contd…

Storage files to Media
 cpio

has three operating modes.

◦ copy-out mode, cpio copies files into an archive. ◦ copy-in mode, cpio copies files out of an archive or lists the archive contents. ◦ copy-pass mode, cpio copies files from one directory tree to another, combining the copy-out and copy-in steps without actually using an archive.

Contd…

Storage files to Media
 Syntax

for creating the cpio file

◦ find (source file name) | cpio –(options) > (target file name) ◦ Example:
◦ find file1 | cpio -o > file1_back.cpio

◦ Syntax for extracting the cpio file ◦ Example:

◦ cat <source file name> | cpio –(options) ◦ cat file1_back.cpio | cpio –idvm ◦ where, ◦ ◦ ◦ ◦ ◦ d – make directories i – extract m – modification time o – create v – verbose

Contd…

Storage files to Media
 Compression

tools

◦ Zip zip is a compression and file packaging utility. The program is useful for packaging a set of files for distribution, archiving files and saving disk space by temporarily compressing unused files or directories. The zip program puts one or more compressed files into a single zip archive, along with information about the files. An entire directory structure can be packed into a zip archive with a single command. ◦ ◦ Syntax zip <new file> <source file> Example: zip install install.log
Contd…

Storage files to Media
 unzip

◦ unzip will list, test, or extract files from a zip archive, commonly found on MS-DOS systems. The default behavior (with no options) is to extract into the current directory and subdirectories all files from the specified zip archive. ◦ Syntax unzip <zipfile> ◦ Example: unzip install.zip

Contd…

Storage files to Media
 Gzip

By default, gzip keeps the original file name and timestamp in the compressed file. These are used when decompressing the file with the –N option. The main advantage of gzip over compress is it has a better compression capacity than other compression tools. ◦ Syntax gzip <filename> ◦ Example gzip install.log
Contd…

Storage files to Media
 Gunzip

gunzip decompress the files created by gzip. It takes a list of files on its command line and replaces each file ending with .gz, -gz, .z, -z, _z or .Z and which begins with the correct number with an uncompressed file without the original extension. gunzip also recognizes the special extensions .tgz and .taz as shortcuts for .tar.gz and .tar.Z respectively.
Syntax

◦ gunzip <filename.gz>
Example:

◦ gunzip install.log.gz
Contd…

Storage files to Media
 Bzip2

bzip2 is a block-sorting file compressor. It expects a list of file names to accompany the command-line tools. Each file is replaced by a compressed version of itself, with the name ‘original_name.bz2’. Each compressed file has the same modification date, permissions and when possible ownership as the corresponding original, so that these properties can be correctly restored at decompression time. ◦ Syntax bzip2 <filename> ◦ Example: bzip2 install.log
Contd…

Storage files to Media
Bunzip2

bunzip2 (or bzip2 -d) decompresses all specified files. bzip2 attempts to guess the filename for the decompressed file from that of the compressed file. If the file does not end in one of the recognized endings, .bz2, .bz, .tbz2 or .tbz, bzip2 gives an error message that it cannot guess the name of the original file, and uses the original name with .out. ◦ Syntax bunzip <filename.bz2> ◦ Example: bunzip install.log.bz2

Lab Exercise
 Backup

any desired directory using tar command

Compress

the file mydata from the data directory and uncompress into a new directory by name backup using zip and unzip commands the /tmp directory into a new directory by name tmp_backup using dump command

Backup

Sign up to vote on this title
UsefulNot useful