Professional Documents
Culture Documents
RH033
Hardware Requirements
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?
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
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
ls displays a list of files in current
working directory
clear clears the screen
date display the system time and date
mkdir creating a new directory
cd directory change directories
touch creates a new file with 0KB sizeContd…
Basic Commands
rm remove files
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
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
There are two types of path names
Relative path
ls Lists the contents of the files
and directories
cd Changes and also opens the
directory.
cat It combines files and print on
the standard output
find Command The find command
Create and Remove
Directories
Creating directories
◦ 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
Introduction
“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
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 Contd…
◦ No. Of links to the File
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
Syntax
Removing files
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.
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 is owned by a particular user.
File
permissions specifies who has the access to file and
what type of access the user has.
Types of permissions
◦ 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
InLinux, every file or folder has access
permissions. There are three types of permissions.
◦ read access
◦ write access
◦ execute access
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.
Contd…
Types of Access
Contd…
Types of Access
Contd…
Access permission user(owner) group
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?
Thechmod 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
sticky bit
Contd…
Who has to Access a File?
SUID or setuid
Contd…
Who has to Access a File?
SGID or setgid
◦ 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
Syntax
#chmod o+t <directory name>
where,
o – others
t - sticky bit
Contd…
Access Control Lists (ACLs)
ACLis an object associated with a file and contains entries
specifying the access that individual users or groups of
users have to the file.
Contd…
Access Control Lists (ACLs)
Contd…
Access Control Lists (ACLs)
◦ 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
Topic
◦ What is a Shell?
◦ Aliasing
◦ File Name Completion
◦ Command History
◦ User profiles
◦ What Happens At Login
◦ Variables
What is a Shell?
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.
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.
Creating Aliases
◦ To create aliases, use the alias command. The format of the alias
command is:
◦ Syntax
◦ alias aliasname=command
◦ 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.
# vi user123.filnename.txt
Command History
The command history buffer [root@localhost root]# history 10
stores the commands you enter 1 ls *.xml
and let you display them at any 2 mv Getting\ Help\ HOWTO.xml linux-help-how-to/
3 cls
time. 4 ls
5 cd linux-help-how-to/
6 ls
◦ As a result, you can select a 7 history
previous command, or parts of 8 history
previous commands, and then 9 ls
reexecute them. 10 history 10
◦ 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
Example
◦ A new variable is defined as follows:
◦ $ MYVARIABLE=hello
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.
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.
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
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.
◦ 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.
Contd…
Shell Substitution Capabilities
Command substitution
◦ Command substitution is the mechanism used to
replace a command with its output, within the
same command line.
Contd…
Shell Substitution Capabilities
Tilde Substitution
Contd…
Setting Shell Variables
Backslash (\)
Backslash removes the special meaning of the
character immediately following the backslash.
Contd…
Quoting Characters
Single quotes ( ‘ ’)
Contd…
Quoting Characters
Double quotes ( “ ” )
Contd…
File Name Generation
Topics
◦ Input Redirection
◦ Output Redirection
◦ Error Redirection
◦ Filter
◦ Pipes
Input Redirection
Thestandard input (stdin) by default is any text
entered from the keyboard.
Contd…
Input Redirection
Standard
output can be redirected through the use of
command line argument and redirection operators (like
>).
Contd…
Output Redirection
◦ 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.
Contd…
Error Redirection
◦ Syntax
command (filename) 2> (filename)
Common Redirection
Operators
There are two common redirection operators
◦ >
◦ >>
Contd…
Common Redirection
Operators
Usage of > operator
◦ Syntax
# cat > (filename)
Contd…
Common Redirection
Operators
Usage of the >> operator
Contd…
Filters
Filters take standard input and perform an operation upon it and
send the results to standard output.
◦ The grep command is used to filter the root user from the /etc/passwd
file.
Pipes
A pipe is a mechanism for interprocess communication.
Contd…
Pipes
The tee command
◦ This is useful when you want not only to send some data down a
pipe, but also to save a copy.
Contd…
Pipes
◦ Syntax
◦ tee <option> <file name>
Lab Exercise
Filter
and display the word blue from the file
my_sortfile
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.
The LAN services (telnet, SSH - Secure Shell, FTP – File transfer
protocol) enables the file transfer and remote login to the system.
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.
◦ Example:
◦ 10.10.1.240
◦ 130.130.1.10
◦ 192.168.1.200
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.
◦ netconfig
◦ service network restart
◦ ifconfig
◦ ping
IP Address
◦ 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
◦ Syntax
# netconfig (Press Enter key)
IP Address
DHCP 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.
Contd…
IP Address
etc/hostsis 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.
DNS (Domain name service) will resolve the host names into
IP addresses in a large network.
◦ 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.
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.
Contd…
Transferring files
◦ Syntax
# scp <filename> <destination IP> :
<destination path>
Contd…
Internet configuration
Contd…
Internet configuration
Contd…
Internet configuration
Modem
Topics
◦ Identifying Process
◦ Managing Process
◦ Background Processing
◦ Putting Jobs in Background
Identifying Process
Theoperating system will execute the processes by
default and the user can also create a process.
Process creation
◦ Example: vi
Contd…
Identifying Process
Contd…
Identifying Process
Contd…
Managing Process
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:
Contd…
Managing Process
Contd…
Managing Process
Contd…
Managing Process
Contd…
Managing Process
Contd…
Managing Process
killall
command will perform an orderly
shutdown of the process.
Contd…
Managing Process
killing a process
Background Processing
A background process is the child of the 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.
Topic
◦ Storing files to Media
Storage files to Media
Backingup of a system is the most major task to be
performed by a system administrator.
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
◦ Syntax
# dd if=<source name> of=<destination name>
◦ Example
dd if=bootdisk.img of=/dev/fd0
Contd…
Storage files to Media
◦ 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
where,
-i is interactive restoration
-f is read backup from file
Contd…
Storage files to Media
Backup using cpio command
Contd…
Storage files to Media
cpio has three operating modes.
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
◦ cat <source file name> | cpio –(options)
◦ Example:
◦ 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