0% found this document useful (0 votes)
19 views

Linux

Uploaded by

Nisha Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Linux

Uploaded by

Nisha Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 205

Introduction to LINUX

Unit 1
Definition

● Linux is a freely distributed multitasking, multiuser operating


system that behaves like Unix OS in terms of kernel behaviour
and peripheral support.

● Linux is, in simplest terms, an operating system. It is the


software on a computer that enables applications and the
computer operator to access the devices on the computer to
perform desired functions.
Linux Introduction
● Linux is basically a Kernel but the term Linux is used to
refer to the OS.
● Kernel is core of the OS and acts as intermediate
between the Shell of the OS and the hardware.
● Shell creates interface between the user and the kernel.
Linux Introduction (cont..)

● User gives commands to Shell which are then forwarded to the


Kernel. The Kernel executes these commands.

● The Shell which is used for Linux is both CLI (Command


Line Interface) and GUI (Graphical User Interface) based. CLI
based shell is Bash Shell and GUI based shell is X-Windows
with version XFree86.
History
Date Event
1984 January Richard Stallman quits his job at MIT and starts working on
the GNU Project.
1985 Free Software Foundation, an organization for creating and
promoting free software, is founded by Richard Stallman.

1991 Linux is introduced by Linus Torvalds, a student in Finland.

1994 Red Hat Linux 1.0

2001 Linus Torvalds releases version 2.4 of the Linux Kernel source
code on January 4th.
2003 Alias Shrike version 9
Minimum System Requirements

● Motherboard – Intel Pentium 3 or higher AMD


● RAM - 2 – 4 GB
● Floppy drive
● Hard drive - 3 – 4 GB
● Video card - CGA, VGA, SVGA
● Monitor
Floppy-based Installation
● A floppy-based installation requires you to produce
three floppies: one for the boot (kernel) image, and
two for the root or swap image
Floppy Less Installation

● If your hard disk already has an operating system like DOS, or


one that produces a DOS window, you can try installing
directly from the CD-ROM. Boot into your existing operating
system, change to the CD-ROM drive, and issue the command
REDHAT
at the DOS prompt.
Installation of REDHAT
● Use the VMware Workstation Configuration Editor
to verify the virtual machine's devices are set up as
you expect before starting the installation

● Insert the Red Hat Linux CD in the CD-ROM drive


and power on the virtual machine.
● CHOICE OF LANGUAGE:

● CHOICE OF INSTALLATION SUPPORT:


● CHOICE OF INSTALLATION STYLE: Means either
update of an existing system or full installation from
scratch

● TYPE OF INSTALLATION: The system allows you to


choose between workstation, server or customized.
Choosing customized installation will give you more
flexibility
● CHOOSING SCSI ADAPATORS: In case this automatic
search comes up empty, you just have to enter a line of
parameters to specify the type of SCSI adapter as well as IRQ
and memory address. A card "AHA1520" with the address
0x140 and IRQ 10 will be found by the command line:
aha152x=0x140,10
● PARTITIONING THE HARD DISK: this distribution will
allow you to partition your hard disk at this level of the
installation process choose fdisk.
● PARTITIONING THE HARD DISK: the software prompts
you to choose the hard disk from a list on which you want to
create the partitions
● If your host operating system supports DHCP and is
connected to a LAN, then in the Network Configuration
screen, select the Use bootp/dhcp option.
● In the Video Card Selection screen, choose the default
selection.
● CHOOSING THE TIME ZONE: choose the time zone that is
appropriate for your country (for France, Belgium, and
Switzerland, it depends...)
Setup The Password
● CHOOSING STARTUP SERVICES: you can choose the services to be
activated at each startup from a list. A priori apmd, netfs and sendmail will
not be very useful for you if your machine is not a server...
Linux is restarting….
● Linux is installed successfully and here’s
the Linux interface
Create Root And Boot Disk

● Root : Holds file system


● Boot : Holds kernel
● gzip –d <filename>
● Example
gzip –d scsi.gz
RAWRITE is a DOS program that writes the images to floppy
RAWRITE filename Destination Drive Letter
eg :
Installation routine

● After you have loaded successfully root and boot images, installation routine
starts.
● For most part you just have to read the screen and make logical choices.
● The steps encountered in installation routine will be now discussed :
Choosing text or graphic Installation
● Linux give you two choices:
▪ Text based
▪ X based
● In text mode for taking input from user keyboard is used, to move the cursor we
can use [left], [right], [up],[down] keys. To choose a button press enter or space

● x based is a graphical user interface, use your mouse to navigate the screen
Setting up your hard drive

● If you need to partition your hard disk, linux gives you two choices:
▪ fdisk
▪ cdisk
● Fdisk is used to configure computers fixed drives, with fdisk you will be able to
delete, create and partition the hard drive.
● Cdisk is similar to fdisk except full screen mode. It uses simple mnemonics
commands to perform functions such as delete to delete, create to create etc.
Cdisk over fdisk

● Using cdisk it is possible to enlarge extended partiton when there is free space after
the partition which can’t be done with fdisk.
● Cdisk Uses simple mnenonics to perform a function.
Formatting the partition

● The installation routine displays a window listing the device names of all your
partitions. To format the partitions :
▪ Choose one of the partitions listed.
▪ Choose yes from the menu to start the formatting.
Setting up Ethernet

● After that red hat asks whether you want to install ethernet now.
● If you have ethernet card you can do so.
● Then you are asked for a machine name and a domain name.
● Then you are prompted for the I.P. address of your machine.
● You can set default for the configuration.
Configuring X

● If you opted for x based installation, linux tries to determine your video system to
start x.
● You will see a message that whether you want installation routine to autoprobe.
● If you don’t choose autoprobing, you must supply the configuration manually.
● After auotoprobing, the installation routine displays the type of video chip set it
found.
● For most systems accept default unless you know exactly what type of chipset and
RAM you have.
● After this x strarts.
Selecting packages to install

● Then a screen appears that lists all the packages on linux CD-ROM.
● You select which packages you want to install
Using LILO

● Now, you are asked whether you want to run LILO to set up the boot system.
● Choose yes or no according to your need.
Partitioning the hard disk

● A hard disk mainly have four partitions.


● Linux really require two partitions:
▪ One for linux swap space.
▪ One for linux software file system.
● Partitioning is done with fdisk utility.
Linux swap space partition

● The more RAM you have the less swap space you required.
● You can calculate the amount of RAM linux uses by the formula:
Linux RAM = RAM + Swap Space
● Swap Space is much slower than RAM.
LINUX’s fdisk

● To specify a drive for partition use the following command:


fdisk /dev/ hdb
● If you don’t specify fdisk assumes first partition.
Commands you need for fdisk

● d := delete
● l := list known partitions
● n := create new
● p := display current partition table.
● q := quit fdisk without saving changes.
● v := verify partition table
● w := Write current partition to disk.
We must have swap space of at least 8 MB and preferably 16 MB if we have only 4
MB
or less of RAM in our system.

If we have a small amount of RAM and we are getting memory error messages,
then the swap space is needed and we should enable it to help the installation
process.

To enable the swap space issue the following command in which ‘partition’ is the
name of the partition where the swap space is located and ‘size’ is the size of the
partition in the block:
mkswap –c <partition> <size>

Example:
The command
After the swap space has been configured and is working, linux file system can be set up.
This step can be automated by some linux installation script or can be manually done.

To create a file system we use the mkfs command. The exact format of this command
depends on the type
Type of filesystem
of file system we are setting.Command
extended mkefs
basic mkfs
xiafs mkxfs

The most popular file system is the second extended file system, so the command we will be
using is
Using LILO

LILO (LInux LOader) is a boot loader for Linux.

LILO does not depend on a specific file system, and can boot an operating system (e.g., Linux
kernel images) from floppy disks and hard disks. One of up to sixteen different images can be
selected at boot time.

LILO is installed with a command like this one:


lilo -C /etc/lilo.conf
The -C option specifies the location of LILO's configuration file.

The lilo.conf file specifies LILO's behavior for certain aspects of the boot process and also
defines the kernels and operating systems that it can boot.
The LILO configuration file contains a ``stanza'' for each operating system that you want to
boot. The best way to demonstrate this is with an example LILO config file.
# Tell LILO to modify the boot record on /dev/hda (the first non-SCSI hard drive). If you boot from a drive
other than /dev/hda, change the following line.

boot = /dev/hda

# Name of the boot loader. No reason to modify this unless you're doing some serious hacking on LILO.

install = /boot/boot.b

The first operating system stanza in the config file will be the default OS for LILO to boot. You
can select another OS to boot at the LILO boot prompt
When LILO loads itself it displays the word “LILO”. Each letter is printed before or
after some specific action. If LILO fails at some point, the letters printed so far can
be used to identify the problem.

(nothing)
No part of LILO has been loaded. LILO either isn't installed or the partition on
which its boot sector is located isn't active. The boot media is incorrect or
faulty.
L
The first stage boot loader has been loaded and started, but it can't load the
second stage boot loader. The two-digit error codes indicate the type of
problem. This condition usually indicates a media failure or bad disk
parameters in the BIOS.
LI
The first stage boot loader was able to load the second stage boot loader, but
has failed to execute it. This can be caused by bad disk parameters in the BIOS.
When LILO loads itself it displays the word “LILO”. Each letter is printed before or
after some specific action. If LILO fails at some point, the letters printed so far can
be used to identify the problem.

LIL
The second stage boot loader has been started, but it can't load the descriptor
table from the map file. This is typically caused by a media failure or by bad disk
parameters in the BIOS.
LIL?
The second stage boot loader has been loaded at an incorrect address. This is
typically caused by bad disk parameters in the BIOS.
LIL-
The descriptor table is corrupt. This can be caused by bad disk parameters in
the BIOS.
LILO
All parts of LILO have been successfully loaded.
STARTING AND STOPPING
LINUX SYSTEM:
STARTING:

▪Linux starts automatically from your hard drive or from a boot floppy disk.
▪When you start Linux system, you see few Linux initialization messages
scroll across the screen.
▪When Linux completes its startup sequence, you should see a login prompt.
STOPPING

▪You already know how to start Linux, but it is even more important to know
how to shut down the system properly.
▪The easiest way to ensure a proper shut down is to press the ctrl+alt+del
keys simultaneously.
LINUX SHUTDOWN COMMANDS
▪ There are several other ways to shut down the system, but ctrl+alt+del is
the easiest way .
▪ Depending upon the different version of Linux, the shut down commands
can vary.
▪ Commonly used commands are “shutdown, haltsys and fasthalt”.
▪ The second most commonly used method to shutting down the Linux is
“shutdown” command.
▪ Example: shutdown –t45
shutdown now
▪ The “fasthalt” and “haltsys” commands do as their names imply and
OPTIONS

▪ -t sec
It waits for specified number of seconds.

▪ -k
Don't really shutdown; only send the warning messages to everybody.
▪ -r
Reboot after shutdown.
▪ -h
Halt after shutdown.
LOGGING IN
▪ After you boot the system, Linux waits for the login.
▪ Its simply a name that you supply to Linux to identify yourself to the
operating system.
▪ Allows only valid users to have access.
▪ Every login name on the system is unique and password is assigned to
them.
▪ The login’s privileges are controlled by Linux.
ROOT LOGIN
▪ Most likely, the only valid login on your Linux system after system
installation is “root”.
▪ Linux prompt you to create a user login during the installation procedure,
so you have two logins that you can use.

Why not to use root login:


▪ You will have to use root login as some things cannot be done on the Linux
system without logging in as root but you should not use it as your regular
user login.
▪ It can damage to your operating system installation and have to reinstall
from scratch.
YOUR FIRST LOGIN
▪ Root is the only authorized login on a newly installed Linux system with
permission to create other accounts.
▪ To login
At the login prompt:
login:
type root and press the enter key.
▪ When you installed Linux, you may have been asked for a password for the root
or the subject simply may not have come up.
▪ After you logged in as root, the system starts up a user session for you. At this
point you will something like
login: root
last login: sun Dec 6 12:22:11 on tty1
Linux 1.2.13
darkstar:~#
PASSWORDS
▪ To prevent unauthorized access, the root login should always have a
password that should be secure.
▪ If the root password is set to null string at the time of installation then root
does not ask for password.
▪ Past users often chose passwords that they could easily remember but these
were easy to break.
▪ We should chose password that are difficult to break. For example, by
mixing numbers and characters.
▪ To change the root password at the system prompt, login as root and type
the command “passwd” .
▪ Example: darkstar:~# passwd
Enter old password:
Enter new password:
CREATING A NEW LOGIN
▪ Linux has a utility called “adduser” to add a new user to the system.
▪ To create a user, at the shell prompt type the command “adduser”
darkstar:~# adduser
Adding a new user. The username should not exceed 8 characters in length.
Enter login name for new account:
▪ With some versions, you have to specify the login name on the same line
adduser abc
▪ Enter login name for new account: abc
Editing information for new user
Full name:
GID[100]:
UID[100]:
▪ It then asks for the password
LOGGING OUT
▪ To finish with your session as a root, logout of the system by typing
“logout”.
▪ Ex: darkstar:~# logout
welcome to Linux 1.2.13
darkstar login:
▪ Some systems allow you to logout with “ctrl+d” sequence.
▪ If the shell you are using supports “ctrl+d” as a logout command, the login
prompt reappears otherwise you may see a message.
TRYING OUT YOUR NEW LOGIN
▪ At the login prompt, type the login name that you have created.
darkstar login: abc
password: *******
Last login: Sun Dec 3 12:34:12 on tty1
Linux 1.2.13
darkstar:~$
▪ The $ prompt indicates that you are a regular user.
▪ Too see the difference between root login and a regular user login,type
adduser at the prompt
darkstar:~$ adduser
SHADOW PASSWORD FILE
▪ In Linux system, shadow password file is a system file in which passwords
are stored in encrypted form.
▪ The shadow password file is not world readable.
▪ No regular user has permission to see the encrypted password fields.
▪ /etc/shadow file format
user name
password
last password change
minimum
LINUX ERROR MESSAGES
▪ An error message is information displayed when an unexpected condition
occurs, usually on a Linux.
▪ On modern operating systems with graphical user interfaces error
messages are often displayed using dialog boxes.
▪ Error messages are used, to indicate that a desired operation has failed, or
to relay important warnings (such as warning a computer user that they are
almost out of hard disk space).
▪ Error messages are seen widely throughout computing, and are part of
every operating system or computer hardware device.
▪ Some of Linux error messages are : “server not found”, “booting
SEARCH PATHS
▪ Search path is a predefined set of directories in which the system looks for
the program you type in from the command line .
▪ You can explicitly tell Linux where the file is located, then it does not
have to look through its search path. You can use relative or absolute paths.
▪ One very important environment variable is the PATH variable. Its an
ordered, colon-separated list of directories that are searched, left to right,
for every command that you execute.
▪ For example:
$ echo $PATH /bin:/usr/bin:/usr/X11R6/bin:/home/username/bin:.
▪ Typically, the search path begins with a small number of standard system
directories such as /bin, /usr/bin and /usr/X11R6/bin,
WHO COMMAND
▪ Displays who is on the system.
▪ Basically displays the information about all the users who have been
logged into the system currently.

▪ Syntax :
who [-a] [-b] [-d] [-H] [-l] [-m] [-p] [-q] [-r] [-s] [-t]
OPTIONS
▪ -a: Process /var/adm/utmp or the named file with -b, -d, -l, -p, -r, -t, -T, and
-u options turned on.
▪ -b: Indicate the time and date of the last reboot.
▪ -d: Display all processes that have expired and not been respawned by init .
-H:Output column headings above the regular output.
▪ -l:List only those lines on which the system is waiting for someone to
login. The name field is LOGIN in such cases. Other fields are the same as
for user entries except that the state field does not exist.
▪ -m:Output only information about the current terminal.
▪ -r:Indicate the current run-level of the init process.
▪ -s:(default) List only the name, line, and time fields.
▪ -t:Indicate the last change to the system clock (using the date utility) by
root. See su and date.
COMMANDS AND PROGRAMS
▪ The command is what you type, and the program is what performs your
command.
▪ However, very simple programs with straightforward results such as
“who”, are often referred to as commands, although there is actually a
“who”, program on your hard disk.
▪ More complicated programs usually interactive ones such as “adduser” or
open-ended ones such as a text-editor, are called programs in more
traditional sense.
BASIC LINUX COMMANDS
HOW LINUX COMMAND WORKS
•When you enter a Linux command, there are several ways to tailor
the basic commands to your specific needs.
•There are two ways to modify the effect of a command:

• Specifying or redirecting a command’s input/output


• Using command options.

•A simple way to picture what a Linux command does is to imagine


that it’s a black box. Items come down the conveyor belt, enter the
black box, get processed in some way, come out and are taken away
on another conveyor belt.
•Command redirection lets you specify the direction of input/output.
•Command options lets you fine-tune the basic process happening
COMMAND OPTIONS
•Linux lets you modify the basic, or default actions of the command by
using options.
•For example: when you want to sort a list of names into order. Then you
have to use “sort” command.
•But in command options, instead of having backward sort command, a
single letter option reverse the sorting order.
•Example: $ls –a
•This command will show the files whose names begin with a dot(.). These
files are hidden files.
•Example : $ls –l
•This command will list the contents in long format including file
permission, size and date information.
•Example : $ls -la
OTHER PARAMETERS
•Linux commands often use parameters that are not actual command
options.
•For instance, by default “ls” list the files in your current directory. But
you can tell the “ls” to list the files in any other directory.
•Example: $ls /bin
•This command list everything in the bin directory.
•This can be combined with command options and it will give the detail
listing of the files in “bin”.
•Example: $ls -1 /bin
•You can also specify “ls” to list information about any particular file.
•Example: $ls –l scramble.sh
•It will display the information about the “scramble.sh” file.
INPUT AND OUTPUT REDIRECTION
•We can “pipe( | ) ” the output from a command so that it becomes another
command’s input.
•The “ | ” symbol means, “Use the output from the previous command as
the input for the next command”.
•To send output to a file, use the “ > ” symbol.
•For example: $ls -1 /bin > output
•This command will store the output of “ls -1 /bin” in a file named as
“output”.
•To view the contents of a file, use more command.
•Example: $ls output
•We can specify that we want to add our output to the end of the file, rather
than replace the file’s contents, by using “ >> ”.
NATIONAL CONVENTIONS USED TO
DESCRIBE LINUX COMMANDS
•There is a set of accepted national conventions used to describe the
correct syntax for any Linux command.
•This specifies what options or parameters you must use, and so on.
•Sometimes it is used to make particular example more general.
•If you remember the following 6 basic rules, you will understand the
syntax of any Linux commands.

•Six Basic Rules of Linux:

• Any text standing by itself, and not within [ ],< > or { } must be typed
exactly as shown.
• Any text within square brackets [ ] is optional. Example: type “ls [-1]”
• Angle brackets < >. Do not use the angle bracket when you actually
type the command. If you want to look at the file “output”, type:
$ls more output
• Curly braces { } indicate that you must choose one of the values given
within the braces. The values are separated by “ | “. The syntax:
command {a | b}
• An ellipse (….) means “and so on”. They are normally used with
parameters such as file names.
• The sixth basic rule states that the you can type more than one file
with one command.
• Example: $more output output1 output2
Online Help Available In Linux

There are Three main commands for Online help in Linux.

•Man
• Info
• help
MAN
•Man command provide online help about every Linux command, with all
the option that command supports.
Syntax:
$man command-name
Example:
•Man clear
Man command display the brief information about clear command.
$man cat
•man command will display the brief information about the cat command.
Man command Using Option
$man –k mkdir
•It searches a summary database and displays online description of the
•Info: The purpose of info command provide online help to each and every
linux command.
Syntax:
$info command-name
Example:
$info ls
•This command display all information about ls command.
Help:This command also provide online help about every linux command.
Syntax:
$command name --help
Example:
$date --help

THE LINUX MAN PAGES

•The man command provide Standard online help facility is available in


the form of electronic reference manuals, known as man pages

•For Example
$man man

•Man command display electronic reference manuals about man


command.
THE BASH SHELL HELP FACILITY

•The command we type at the prompt, the shell program takes what
you’ve written interprets it as necessary and passes result to the Linux
operating system.
• Linux then perform the action requested to it.
• Editing and completion.
History and command Re-entry: The history list may be of unlimited size.
The history list may be saved across shell sessions.
•Array: Bash support indexes arrays of unlimited size.
Command Timing :Bash allows external commands, shell builtin
commands and shell functions to be timed. The format used to display the
timing information may be changed by the user.
•Tilde Expansion: Users' home directories may be expanded using
this feature. Words beginning with a tilde may also be expanded to
the current or previous working directory.
• Help: Bash includes a built-in help factility.
Directory Stack: Bash provides a `directory stack', to which
directories may be added and removed. The current directory may
be changed to any directory in the stack.
• Security:Bash provides a restricted shell environment. It is also
possible to control the execution of setuid/setgid scripts.
Arithmetic: Bash allows user to perform integer arithmetic, in any
base from 2 to 64.
WILDCARDS
•Wildcard are used as a convenient and powerful shortcut when specifying
files(or directories) that a command is to operate on.
•Star(*):The most frequently employed and usually the most useful is the
star wildcard, which is the same as an asterisk (*).
•The star wildcard has the broadest meaning of any of the wildcards, as it
can represent zero characters, all single characters or any string.
$file *
•This would display information about every object in the
current directory (i.e., the directory in which the user is currently
working):
•If there are no matches, an error message is returned, such as *: can't stat
`*' (No such file or directory).
$ls *.html *.txt
QUESTION MARK WILDCARD
•The question mark (?) is used as a wildcard character in shell commands
to represent exactly one character.
Example:
$file ???
•This would return data on all objects in the current directory whose
names, inclusive of any extensions, are exactly three characters in length:
$file ? ?? ???
•This would provide data on all objects whose names are one, two or three
characters in length.
$file a????
•This would provide information about all objects in the current directory
that begin with the letter a and are five characters in length:
ENVIRONMENT VARIABLE

•An environment variable is a named object that contains information used


by one or more applications.
By using environment variables one can easily change a configuration
setting for one or more applications.
•PATH:This variable contains a colon-separated list of directories in
which your system looks for executable files.
•MANPATH:This variable contains a colon-separated list of directories in
which the man command searches for the man pages.
•ROOTPATH:This variable has the same function as PATH, but this one
only lists the directories that should be checked when the root-user enters a
command.
PROCESS AND HOW TO TERMINATE
THEM

•$ps(which process is in backend. It shows all id).


•If you get information about individual process then use
$ps <pid>
•Kill command is use to kill process.
•Processes are the individual task involved and run under Linux.
Everytime when user enters the command i.e a process and whenever the
system does any thing it is a process.
•Ps:- To see the status of the processes.
•Kill:- For premature termination of the process.
THE PROCESS STATUS COMMANDS
•Ps: It stands for process status command.
•It is a Linux command to see the status of various processes currently
running.
•The command will be like:
$ps
•This command will describes whole information in columns and they are:
• pid
• tty
• STAT
• TIME
• Name
OPTIONS

•-a : Displays all processes/users.


•-e: Displays every process running at the moment.
• -f : Displays full listing of processes.
• -u: Displays the processes of the mentioned single user.
• -t: Displays the processes running on the mentioned terminal.
• -l: It shows parent as well as child processes.
PROCESS TERMINATION COMMAND
•Kill: This command is used to terminate a particular process or multiple
processes at a time. This command uses the PID as an argument.
• Syntax:- $kill process-id
$kill 125
Steps as follows:
i) Switch to another virtual console and login as root.
ii) Run $ps –u and identify the offending process.
iii)Use the kill program by typing kill process id. This is a process that
you want to kill.
iv)Now verify the process that you have killed with the command ps –
u
Sometimes the offending process reappears with new process id. In this
case go to step (vi).
v) If the process still alive and has the same process id then use “q” option
type
$kill –q<pid>
And check it again with ps command and if it does not kill the process
then go to step (vii) and if it is dead then go to step (viii).
vi) IF the offending process is reappear with a new process id now the
only solution is to kill the parent process.
vii) Now kill the specific parent process and make sure that parent process
has been killed.
viii) The process is killed and remember to log off from root.
SU COMMAND

•SU stands for super user.


• This command is also helpful for becoming someone else.
• Syntax:- $su username
• These commands work when user wants to temporarily becoming a
different user.
• Su command grants you all the privileges you would get if you logged as
that user but would not inherit exact environment.
GREP

•Grep stands for Global Regular Expression.


• There are two basic ways to use grep in Linux:

• Grep can be used as a filter on the output of other command.

• The general syntax is:


$ps –a | grep R

•Use of grep is to search for lines that contain a specified pattern in a


specified file.
UNIX FILE SYSTEM
UNIX/LINUX file system hierarchy

root

bin dev etc home lib sbin stand temp usr var

rdsk dsk sharma kumar


cat who unix
date bin include sbin

f0q18dt login.sql progs safe


Role of various files

⮚ Bin
❑ Commonly used UNIX commands
❑ Binary files, hence the name bin
❑ Binary file – contains all printable and unprintable
characters

⮚ Etc
❑ Contains configuration files
⮚ Lib
❑ Contains all library files in binary form
❑ C programs need to be linked with them

⮚ tmp
❑ Contains temporary files
❑ These files are wiped away regularly by the system

⮚ dev
❑ Contains all device files
Commands for managing files
and directories
⮚ chmod
❑ You can use this command to change the access
permissions of any file for which you are the owner.
⮚ du and df
❑ The du command displays the sizes in kilobytes of all
files in the specified directory.
❑ The total of all those sizes; if no directory is specified,
the current directory is assumed.
File manipulative commands

⮚ cat
❑ Reads one or more files
❑ Prints them to standard output
❑ Operator
a) > used to combine multiple files into one
b) >> used to append to an existing file

❑ Syntax
cat [options] [file]
❑ Options
i. -e $ is printed at the end of each line
ii. -v display control characters and non printing
characters
iii. -n numbering lines

❑ Eg.
cat file1
cat file1 file2 > all
cat file1 >> file2
cat > file3.txt
⮚ ls
❑ Display list of files in current directory
❑ Syntax
❑ ls [options] [names]

❑ Options
i. -a show hidden files also
ii. -x output in multiple columns
iii. -r display file in reverse order
iv. -t sorts the files by time modified
v. -l list the files of current directory in long
format , including file permissions, size and date

❑ Eg.
ls –a note
⮚ cp
❑ Make copy of a file or directory
❑ Syntax
❑ cp [options] <filename> <newfilename>

❑ Options
i. -i warns before overwriting destination file
ii. -R copy entire directories along with content

❑ Eg.
cp –i chap1 unit2
⮚ mv
❑ move file from one place to another
❑ original file is removed
❑ used to rename file/directory
❑ Syntax
$ mv <old file> <new file>

❑ Eg
$mv data.txt target.txt
⮚ Rm
❑ Removes or delete one or more files
❑ Syntax
$ rm <file name>
❑ Options
-r Recursive deletion
-f forcing removal
-d directory deletion
❑ Eg
$ rm *
⮚ sort :
❑ Sort is an utility program that can used to sort
the text files in numeric or alphabetical order.
❑ Attributes : -n (ascending order, by default)
-r (descending order)
❑ Syntax :
$ sort [options] filename
❑ Example: if we have file named ‘colors’ then
⮚ File :
❑ Used to find the type of the data in the file
❑ Analyze the contents of the file.
❑ Example :
$ file first.c second.txt info.html
⮚ Find :
❑ Used to locate the file from the entire file
system.
❑ After locating, we can perform various
⮚ Head :
❑Used to display first n lines of the given file.
❑By default it takes 10 lines.
❑Example :
$ head -5 list.txt
⮚ Tail :
❑It is a counterpart of head command.
❑Used to display last n lines
❑By default it takes 10 lines.
❑Example :
⮚ Grep : (global regular expression printer)
❑It is one of the useful filters.
❑Used to search the specified text from
mentioned files and to display the lines on
screen which consist the supplied text.
❑Options :
❖ -c displays a count of
number of lines that
match
❖ -v displays the lines that
⮚ wc : word count

❑Used to count the words, characters and lines in


the specified file.
❑Syntax :
$ wc [-options] filename(s)
❑Example :
$ wc -l list.txt
$ wc -w list.txt
Directory manipulative commands

⮚ pwd
❑Display the path of current working directory
❑Syntax :
$ pwd
❑Example :
$ pwd
/usr/kumar
⮚ mkdir
❑Used to create a new directory/subdirectory in
the current directory
❑Multiple directories can be created with this
single command
❑Name of the directory must be less than 14
characters
❑Syntax :
$mkdir directoryname
❑Example :
⮚ rmdir
❑Used to remove the directory
❑Before deleting, make sure it is empty
❑If it contains sub-directories or files, then it
must be removed first using rm command
❑Syntax :
$rmdir [path] directoryname
❑Example :
$ rmdir usr/kumar/progs
❑Changes the present working directory to the
new directory
❑When used with arguments, it changes the
current directory to the directory specified as
arguments
❑Syntax :
$cd
❑Example :
$cd progs
$pwd
$/home/kumar/ progs
alias command

❑ Used to create a 'shortcut' to a command


❑ Syntax:
$alias name='command‘
❑ Eg:
$alias home='cd /home/dave/public_html'
This will create an alias called home which will put you in
the /home/dave/public_html directory whenever you type
home at the command prompt
File & directory
⮚ File :
❑ The file is a container for storing information.
❑ We can simply treat it as sequence of characters.
❑ For example: If you name a file foo and write a,b,c into it , then foo will contain only
the string abc in it nothing else.
❑ The file size and its name is not stored with in a file.
⮚ Directory :
❑ A directory contains no data, but keeps some details of the files and subdirectories that it
contains.
❑ The LINUX file system is organized with a number of directories and subdirectories.
❑ A directory contains the filename and not the file’s contents.

KEY DIFFERENCE BETWEEN FILE AND DIRECTORY

The name of a file can only be found in its directory; the file
itself doesn’t contain its own name or any of its attributes, like
its size or access rights.
File & inode

⮚ Every file is associated with table that you could possibly


need to know about a file –except its name and contents.
⮚ This table is called the inode. This inode contains the
following attributes:
❑ File type (regular, directory, device , etc.)
❑ File permissions
❑ Number of links
❑ UID of the owner
Key difference between file and inode

The inode contain all attributes of the file except the


file name. The file name is stored in the directory
housing the file. The inode no. is also not stored in
the inode, but kernel can locate any inode by its
positions.
Important directories used in
Linux
/bin & /usr/bin Directories where all the commonly used LINUX
commands (binaries hence the name bin) are found.

/sbin &/usr/bin If there is a command that we can’t execute but the system
administrator can, then it would be in one of these
directories.
/etc This directory contains the configuration files of the
systemYour login name and password are stored in files
/etc/passwd and /etc/shadow.
/tmp The directory where users are allowed to create temporary
files. These files are wiped away by the system regularly.
This directory contains all device files.
/dev These files don’t occupy space on the hard disk

Contain all library files in binary form. You will need


/lib & /usr/lib to link your c programs with files in these
directories.

Contains the standard header files used by the c


/usr/include program. #include<stdio.h> in C refers to file stdio.h
in this directory.

/usr/share/man This is a directory where man pages are stored.


More & less vs cat

More & Less Cat

⮚ Also called paging output. ⮚This command is used to create a


⮚This command is used to read new file.
text files one ⮚Display the contents of the file.
screen at a time. ⮚If files you want to view are very
⮚More uses the spacebar to scroll long , the cat command will scroll the
forward a page at a time and b for text very quickly. Ctrl+s & Ctrl+q can
backward. control the flow.
⮚The search capability in more is not ⮚For eg : $ >cat hello.txt
restricted to simple strings.
⮚For eg : $ ls | more
More & less

“Less” is just like a “more” except that it has few extra features
such as allowing users to scroll backwards and forwards through
a displayed file. “less” is its standard pager.
But “less” does have one serious limitation. Unlike more (which
uses .) , it can not repeat the last command.
ln : link
❑Used to make a link between two files
❑A link allow a one directory to point to a file in
another directory.
❑Utilize less memory.
❑Two types of link :
❖Soft link (more flexible and reliable)
❖hard link
❑Syntax : ln [-options] {source} {link}
❑Options:-
Soft links

⮚ Symbolic link, often called symlink or softlink, is very


similar to what we know from Windows - a shortcut.

⮚ They are kind of shortcuts in the Linux/Unix world.

⮚ Symbolic link contains information about the destination of


the target file.
Hard link

⮚ Hard link is a directory reference or pointer to a file.

⮚ Hardlink is a label stored in a directory structure that refers


the operating system to the file data when it is accessed.

⮚ The important part is that hard link is closely tied together


with its originating file. If you make changes to a hard
link, you automatically make changes to the
Difference

Hard links Soft links

⮚ Hard Link is a mirror copy of the original ⮚Soft Link is a symbolic link to the original
file. file.

⮚Hardlink or hardlinks cannot be created ⮚Symbolic links or symlinks can link to a


for directories (folders). directory (folder).

⮚Hard link can only be created for a file.


Hard links Soft links

⮚Hard links share the same inode. ⮚Soft Links will have a different Inode
value.
⮚Any changes made to the original or Hard
linked file will reflect the other. ⮚A soft link points to the original file.
Even if you delete any one of the files,
nothing will happen to the other. ⮚ If you delete the original file, the soft link
fails. If you delete the soft link, nothing will
⮚Hard links can't cross file systems. happen.

⮚Soft links can cross file systems.


Count number of files in a
directory
⮚ Use the tree command
❑ list the amount of files and directories in the current
directory and all subdirectories as well.
❑ list only the contents of the current directory
❑ Syntax:
$tree
⮚ Use echo in combination with wc
❑ Used to display how many files or folders are in a
❑ Eg:
echo * | wc
Count all files and directories in the current
directory

echo */ | wc
Count only the directories in the current directory

echo *.* | wc
Unit 5

File and Directory Permissions


Outline

▪ File Directory Ownership


▪ User ownership,Groups.
▪ Changing Group Ownership.
▪ File permission,Umask setting
▪ Changing directory permission
▪ Bash: what is shell?
▪ The most common shells,
▪ Bourne shell,korn shell & wildcards
▪ Alias, input output redirection
▪ Pipelines,prompts,job control
▪ Bash commands
File & Directory Ownership

OWNERSHIP:
When you create a file , you automatically become its owner. The Third
column shows owner of all these files. Whatever GROUP you are in
when the file is created is placed in 4th columns . Being the files owner
gives the privilege of changing the file permission and ownership.
Users and Ownerships:
Files owner are set up by the system during installation.
Linux files are owned by ID’s such as root,bin.
We can use chown command(change ownership) command to change
the ownership of a file.
Syntax:
Continue..
Ex:
~$ ls –l myfile
-rwxrwxrw- 1 fido user 114 dec 7 14:31 myfile

Note:
changing ownership require SU permission, so first change our status to that of super user
with su
$ su
Password:*******

~$ ls –l myfile
-rwxrwxrw- 1 fido user 114 dec 7 14:31 myfile

#chown bill myfile


~$ ls –l myfile
-rwxrwxrw- 1 bill user 114 dec 7 14:31 myfile
Group
⮚ File and users also belong to a grop. Group are normally used in
larger installation.
⮚ Group are convenient way of providing access to a file for more
than one user but not to every user.
⮚ For Example: users work on a group of project could all belong to
a group project.
⮚ You are a member of one group by default.you can belong to
many different groups but you can logged to only one group at a
time.
⮚ To change the group you a member of use this command:-
New grp programme
Changing Group Ownership

Chgrp command is used to change the group the file belong to:
Chgrp <group> <filename>
No super user permission is required to change the group ownership.

Ex:
~$ ls –l myfile
-rwxrwxrw- 1 fido user 114 dec 7 14:31 myfile

#chgrp bill myfile


~$ ls –l myfile
-rwxrwxrw- 1 fido payment 114 dec 7 14:31 myfile
Using Chown to do both

⮚ Linux allow administrator to use chown to change both owner and


group.
⮚ The syntax require two arguments to be separated by colon :

Chown <ownership>:<group> filename


Ex:
chown gupta:dba filename
This command change ownership to gupta and group to dba.
File Permission
⮚ LINUX provide three different type of access permission that you may have
on a file or a directory.
⮚ These are read , write , and executable permission.
⮚ User separates all users on the system into 3 categories based on the
ownership of the file or a directory.
⮚ There is First for owner, second for Group, and third for Others. The first
character is special which indicate whether the entry is a file or directory.

Ex:
-rw-rw-rwx
UMASK Setting
⮚ The system administrator UMASK( users file creation mask)
setting for any users or the entire set of users on the system.
⮚ You can change you’re your UMASK setting But not that of others.
⮚ The system have default permission for all file and directories.

REGULAR FILE: rw-rw-rw-


DIRECTORIES: rwxrwxrwx
The value of UMASK can be shown by typing:
$UMASK
022
Changing File Permission
⮚ To change the File permission , Linux uses chmod( change mode)
command.
SYNTAX:
chmod <specification> filename
⮚ There are two way of writing specification:
1) Absolute
2) Relative

Relative:
When changing pemission in a relative manner chmod
Only changes the permission specified in the command line and leave the
other permission unchanged.
What is Shell ???
❑ Computer understand the language of 0's and 1's called binary language, In early
days of computing, instruction are provided using binary language, which is difficult
for all of us, to read and write. So in O/s there is special program called Shell. Shell
accepts your instruction or commands in English and translate it into computers
native binary language.
❑ Shell is a programme used to interface between the user and the Linux Kernel.
❑ Every command the user type at the programme on the screen is interpreted by the
Shell and then passed to the Linux Kernel .
❑ It has its own set of built –in –shell commands.
Working of Shell
✔ The shell can also make use of all the linux utility and application programs that are
available on the system.
✔ All the commands which a user enters at the command prompt are first interpreted
by the linux shell which is currently being used
✔ As a user, one does not know if the command is built-in to the shell or is a separate
programme .The shell interprets the command and forwards it for the further
execution.
✔ The shell fist check to see weather the command is one of its own built in
commands or it is an application programme.
✔ Application programme can be utility programs that are part of linux such as ls and
rm or they can be application programs that are either purchase commercially or
are available as public domain soft wares.
Working of Shell Programming

USER

Shell
command(cd,pwd,
kill )etc

Linux Kernel
How to start the Shell

⮚ Shell is a main method through which a user interacts with the Linux kernel

⮚ The shell is started after we successfully login to the system and it continues to
be the main method of interaction between the user and the kernel until we
logout

⮚ Each user on the system has a default shell .The default for each user is specified
on the system password file called /etc / passwd. The system password file
contain each persons user id, an encrypted copy of each users password and the
name of the program to run immediately after a user logs into the system.
Bash Shell
⮚ Linux has a variety of different shells:
Bourne shell (sh), C shell (csh), Korn shell (ksh), TC shell (tcsh), Bourne Again shell (bash).
⮚ Certainly the most popular shell is “bash”. Bash is the shell that will appear in the GNU
operating system. Bash is an sh-compatible shell that incorporates useful features from the
Korn shell (ksh) and C shell (csh).
⮚ Bash is not only an excellent command line shell, but a scripting language in itself. Shell
scripting allows us to use the shell's abilities and to automate a lot of tasks that would
otherwise require a lot of commands.
Diff B/w Programming & Scripting
Lang.
⮚ A Programming languages are generally a lot more powerful and a lot
faster than scripting languages. Programming languages generally start
from source code and are compiled into an executable. This executable is
not easily ported into different operating systems.

⮚ A scripting language also starts from source code, but is not compiled
into an executable. Rather, an interpreter reads the instructions in the
source file and executes each instruction. Interpreted programs are
generally slower than compiled programs. The main advantage is that
you can easily port the source file to any operating system. bash is a
scripting language. Other examples of scripting languages are Perl, Lisp,
Diff B/w Bourne Shell & CShell
Diff B/w Bourne Again & Korn
Shell
Command Line Completion
❑ When we enter commands into bash , the complete text of the command is not necessary in
order for the Shell to be able to determine What we want it to do.
❑ For example if we have following files and sub-directories:
news/.bin/,games/,mail/,simplefile test
❑ If we want change the current working directory to test sub-directory, we have enter the
command as:
cd test
but in bash we can just simply type t as follows:
cd t <tab key>

After typing the command press tab key is that bash can complete the command because test
is the only directory that begin with t.
Command mode actually execute until we press Enter Key.
Command History
⮚ Bash also support command history that means it keeps track of certain number
of previous commands that have been entered to the shell.
⮚ The number of command is given by the shell variable called HISTSIZE.
⮚ Bash stores the text of previous command in the history list .when we logged into
the account the history s initialized from a history file whose file name is set
using HISTFILE bash variable. The default file name of history file is .bash-
history and it is located in our home directory. since it is beginning with (.period)
that signifies into hidden file that appear into only with (-a) option with ls
command.
⮚ The simplest way of using the history list is with the up and down arrows
keys .which scroll through the commands that that have been previously entered
.
Wildcards

In the Linux CLI that task is just as simple to perform as moving only one
HTML file, and it's so easy because of the shell wildcards.

Wildcards are special characters that allow you to select filenames that match
certain patterns of characters. This helps you to select even a big group of
files with typing just a few characters, and in most cases it's easier than
selecting the files with a mouse.
Continue..
Redirection in linux
⮚ Most Linux commands read input, such as a file or another attribute for the
command, and write output.
⮚ By default, input is being given with the keyboard, and output is displayed
on your screen.
⮚ Your keyboard is your standard input (stdin) device, and the screen or a
particular terminal window is the standard output (stdout) device.
In Linux there are many redirecting operators
(File descriptors) some are shown below :

> --Output redirecting operator


< --Input redirecting operator
>> --Output appending operator.
| --Pipe operator, redirects output of a
command to next command
Output Redirection

Suppose if u want to redirect the output of ls to a text file, then > redirection
operator is used.
Ex 1
$ ls - l myfile.txt > test.txt

Ex: 2
nancy:~> cat test1
some words
nancy:~> cat test2
some other words
nancy:~> cat test1 test2 > test3
Continue..
Ex 3:
$ who > user
To see the contents of file, we use Cat command
$cat user
Merry pts/1 May 13 08:20
John pts/2 May 14 09:10

Redirecting output to append to a file


This will appends the contents of file2 to file 1 at the end.
To append the file2 to file 1, we use

$ cat file2 >> file 1


Continue..

File concatenation
To concatenate more then one file into single file we use
$ cat f1 f2 f3> f4

To redirect standard output to a file


$ echo "hello world" > test.txt
Input Redirection
The < operator is usually used to direct input into a process or command.
Ex : To see the first ten lines of the /etc/passwd file, the command:
head /etc/passwd Or
head < /etc/passwd

Ex : cat < myfile


It would take input from the file designated as myfile rather than from standard input.

Ex $cat > sname


vivek
ashish
babu
Press CTRL + D to save.
Now issue following command.
Pipelines and Grep Command
Unix allows you to connect processes, by letting the standard output of one process feed
into the standard input of another process. That mechanism is called a pipe. It is
followed by (|) symbol.

Ex. $ cat apple.txt | wc – l


It will displays the number of lines in apple.txt.

Grep Command :
The grep utility is one of the most useful filters in Unix. Grep searches line-by-line for a
specified pattern, and outputs any line that matches the pattern.

Syntax : grep [options] PATTERN [FILE...]

Ex : $ grep '^jon' /etc/passwd

Here the caret (^) matches the beginning of a line.


Prompts available in Bash
There are several variables that can be set to control the appearance of the bash
command prompt: PS1, PS2, PS3 and PS4

⮚ PS1 – Default interactive prompt (this is the variable most often customized).

⮚ PS2 – Continuation interactive prompt (when a long command is broken up


with \ at the end of the line) default=">“.

⮚ PS3 – Prompt used by “select” loop inside a shell script.

⮚ PS4 – Prompt used when a shell script is executed in debug mode (“set -x” will
turn this on) default ="++"
Example :
Set a prompt like: [username@hostname:~/CurrentWorkingDirectory]$
PS1="[\u@\h:\w]\$ "
Continue…
Example :
PS3="Choose an option: “
select i in yes maybe no

do
# code to handle reply
done
which will output:
1) yes
2) maybe
3) no Choose an option:
Job Controls
Job control refers to the ability to control the execution behavior of a
currently running process. job is refer to move process b/w bg & fg.
There are various commands that can be used to control
processes.

⮚ ps list the processes running on system.


⮚ Kill sends signal to one or more processes.(ctrl+Z)
⮚ Jobs an alternative way to list of ur own process.
⮚ Bg put process in background(&)
⮚ Fg put process in foreground.
Continue…
Managing jobs
$ sleep 150&
Listing the running processes
$ jobs
Bring job to foreground:
$fg %job—id
$fg %2
To suspend the job:
$stop %job-id
$stop 2
List of suspended jobs:
Customizing Bash
Until now, the changes that you made affected only the current bash
session. As soon as you quit, all of the customizations that you made will
be lost. You can make the customizations more permanent by storing them
in bash initialization file

You can put any commands each time bash is started into this initialization
file. Commands that are typically found in this file are alias commands and
variable initializations . The bash initialization file is named profile. Each
user who uses bash has a profile file in his home directory. This file is read
by bash each time it starts, and all of the commands contained within it are
executed..
Bash Commands
⮚ alias
The alias command can be useful if you want to create a 'shortcut' to a
command.
The format is alias name='command‘
Ex. > alias home='cd /home/dave/public_html‘
> alias chdir='cd'
> alias copy='cp'
⮚ bg
To move job to the background
⮚ cd
It allows you to browse the directory tree.
> cd directory_name
Continue..
⮚ fc :
The 'fc' utility lists or edits and re-executes, commands previously entered to
an interactive sh.
fc -l - Would list the history of commands on the computer similar to the
following:
2 grep –help
3 bg
4 fg
5 cd public_html
6 rm index.html
7 chmod 755 index.htm
⮚ fg:
VI EDITOR
● Vi text editor is default text editor of linux system.
● Type vi on the prompt to start vi.
● A blank screen appears
● In every line ~ (tilde) sign appears telling that line is empty of text.
● We can open file or list of files to edit with vi
vi file1 file2…..
Alternatively
vi +n filename

● Where n represents the line number where vi


will place its cursor in filename.
● Vi has two modes command mode and text mode.
● In command mode any character that you entered are interpreted as vi
command
● In text mode every character you entered is placed in the buffer and
displayed as text on screen
Inserting text
● To enter text in your file press i or a .
● i command insert text to the left of the cursor.
● a command is used to the append right of the cursor.
● Insert capital I at the beginning of the file.
● Insert capital A to append at the end of the current line.
Quitting vi
For example
vi asong
Type an i and enter the following
Down I walk<Enter>
by the bay ,<Enter>
Where I can<Enter>
hear the water. <Enter>
To exit from input mode press esc
● After pressing : vi recognized that you are about to enter an ex command .
● Type wq and press return then vi exits.
● You can also save and exit using ZZ command.
● ZZ writes the file to the disk only if it has been modified since the last save.
● If you do not made any change to the file you can use :q command to quit.
● If you dont want to save what you have done
enter :q!.
● You can use the cat command to see the file
contents.

$ cat asong
Down I walk
by the bay ,
Where I can
hear the water.
Moving The Cursor
● Moving the cursor around in vi essentially involves the following four keys :

h Moves the cursor one space to the left.


j Moves the cursor down one line.
K Moves the cursor up one line.
l Moves the cursor one space to the right.
Commands To Move In Bigger
● Ctrl+u
Leaps
Scrolls up a half-screen.

● Ctrl+d Scrolls down a half screen.

● Ctrl+f Scrolls down one full screen.

● Ctrl+b Scrolls up one full screen.


● It is also possible to move the cursor to a specific line in a file .
● To move to fifth line type 10G or:10 in command mode.
● G moves the cursor to the end of the file.
● To move to the beginning of the next word on the current line press w.
● Press b to move the cursor to the beginning of the current or previous word.
Deleting text
● Type dw to delete a word.
● To delete several words at a type press 4dw.
● Type dd to delete a line.
● To delete several lines at a type press 4dd.
● d^ deletes backward to the beginning of the line.
● D$ (or D) deletes forward to the end of the line.
● x deletes the individual character underneath the cursor.
● X deletes the character to the left of the cursor.
● These commands also accept a number modifier.
● 4x deletes the current character and the 4 characters to the right.
● Changes can be undone by ‘u’ command.
Copying and moving text

● Moving the text required three steps-:

⮚ “yank” the text into the buffer.

⮚ Move the cursor where you want to insert the


text.
● Commmand ‘yy’ is used to yank the current line into the unnamed buffer.
● 3yy command copies the three lines of below text into the unnamed or
temporary buffer.
Down I walk
By the bay,
Where I can
Hear the water.
● Command “a3yy copies the three lines into named buffer”.

● (“) tells the yank command to overwrite the contents of the named buffer a.

● If u type capital A the three lines are appended to the buffer.


Moving the text
● If you move the cursor to the end of the file using the ‘$’ command , then
you can paste the content of the unnamed buffer to the end of the file.
● This is done using the p command, which pastes the contents of the buffer
to the right of the cursor (P pastes to the left of the cursor).
Searching and replacing text
● Searching can be performed in either direction forward or backward.
● To search forward through a file ‘/’ is used.
● For eg. To search word ‘by’ in the file type
/by then press return .
● Cursor is moved to the first occurance of ‘by’ it finds in the forward
direction .
● To search backward through a file ‘?’ is used.
● For eg. To search word ‘I’ in the file type
?I then press return .
● Cursor is moved to the first occurance of ‘I’ it finds in the backward direction .
● Searches can also be made through use of regular expression .
● For eg. To search forward through a file from the first line for all strings
containing the sub-string ‘er’ type :-
/[*]er[*]
/[a-z]y
/[Mm]y
● To search and replace one word with another type -: :%s/Down/up/g
● ‘s’ indicates that this is a search operation .

● ‘%’ means entire file is to be search.

● “Down” is the pattern to be found.

● “up” is the new pattern.

● ‘g’ tells vi that the search should continue until


there are no more pattern matches.
● Vi is configurable which means you can control your editing environment.
● Vi is configured using set command.
● The set command must be preceded by colon and entered by pressing
return.
For example to display line numbers in the editor enter
:set number
● Few more set commands
all display a list of all available set
option
ignorecase searches are case-insensitive
errorbells sounds terminal bell when an error
occurs
showmode an indicator appears at the
bottom of screen showing mode
● The setting that you use in vi session are lost
each time you exit vi.
● You can retain these setting in .excr file, vi
searches this file in home directory each time
it is invoked
For example .excr file looks like this
set number
set errorbells
set showmode
Linux For
System
Administrators
Contents
● System Administrator Basics
● The root account
● Starting and Stopping the system
● Using LILO to boot
● Shutting down Linux
● Mounting File system
● Mounting a floppy
● Creating a new File System
● Unmounting file system
● Checking file system
● Using file as swap space
● Compressing files with gzip and compress
● Using Tar
● Backups
● Setting up your system
System Administrator Basics
● System Administrator also known as the super user or root user.
● System Administrator maintains the entire system.
● System Administrator has a special login name and special prompt.
● He can create files or delete any files or directories.
● Includes the management of entire system such as:
⮚ Adding and Removing new users .
⮚ Providing security.
⮚ Monitoring the network.
⮚ Installing printers and backups
The Root Account
▪ Root is the only authorized login on a newly installed Linux system with
permission to create other accounts.
● It can do anything anywhere. Access any files it wants and control any
processes.
● Its password is generally set at the time of installation of the system.
● The root account should be employed only for limited system use and then
only when its power is necessary.
● As a general rule, we should not use the root account for routine tasks.
▪ To login
At the login prompt:
login:
type root and press the enter key.
● The prompt of the root is #.
Starting and Stopping the system
● Booting from a floppy:
● A boot Floppy as its name implies, is a floppy disk that
boots the Linux kernel.
● A boot floppy has the root partitions installed on the floppy
itself instead of hard drive.
● A boot floppy is used only in emergencies, when our
system won’t start up normally.
● We can create a boot floppy from scratch by copying over
the kernel image from the hard drive.
Booting from a floppy:

● The root partition is set with rdev command.


● Syntax— rdev kernelname device
● Kernelname is the name of the kernelimage and device is the name
of the Linux root partition
● As a final step in creating the boot floppy,copy the kernel image to
first floppy drive:
● Cp vmlinuz /dev/fd0
Using LILO to Boot
● LILO stands for LInux LOader. It is a boot loader for Linux.
● LILO is a program the resides in the boot sector of our hard drive and
allows Linux to be booted from the hard disk.
● If we have LILO to set auto boot Linux we must interrupt the process by
pressing the Ctrl+Alt+Shift when the bootup started.
● Linux distribution have a configuration file in the directory /etc/lilo that
can be edited to provide boot information, while other versions of Linux
configure LILO during the installation process.
● Some versions of Linux use the configuration file /etc/lilo.conf instead
of /etc/lilo.
Shutting Down Linux
● We can’t just turn off the power switch! This can cause damage to the file
system.
● The formal method is to use the shutdown command. Syntax:
● shutdown [minutes] [warnings].
● Minutes is the number of minutes wait before shutting the system down.
● Warning is an optional message displayed for all users currently logged in.
● If we can’t wait and want to shut the system down immediately, use the
halt command or Ctrl+Alt+Delete. Then the power can be shut off.
● We can also give specific time for shutdown by using –h switch.
● example.: -h time(4:30)- at 4:30 our system will be shutdown.
Mounting the file system
● File system are not available until they are mounted onto Linux main file
system.
● During the boot process, the mount command is used from the startup files
to mount all the file systems.
● We can add a new file system from hard disk using mount command.
● syntax:- mount filesystem mountpoint .
● Filesystem is the name of the device and mountpoint is where in the Linux
file system it should be mounted.
● For example: if we want to mount SCST CD-ROM to the file system as
/usr/cdrom, issue following command.
● mount /dev/cd0 /usr/cdrom
Mounting a Floppy
● To mount a floppy follow these steps
● 1. Go to your home directory. Imagine your name is “muk”. Type the
following command:
• cd /usr/muk
o 2. Create a new sub-directory to mount the device. To create a subdirectory
type the following command:
• mkdir devicedata
3. Now to link the flpppy drive to your created sub-directory using
‘mount’ type the following command:
• mount /etc/dev/fd0 usr/muk/devicedata
Creating a new File System
● To create a file system on a floppy, we should use the utility mke2fs or the
command mkdev fs depending on the version of linux.
● To use mke2fs, for example issue following command to create a floppy
file system on a 1.44MB 3.5-inch disk.
● mke2fs /dev/fd0 1440.
Unmounting a File System
● To detach a mounted file system from our linux file system, use the
“umount” command with the name of the device.
● For eg: to unmount a floppy in /dev/fd0, issue the following command:
● 1. Go out from the device directory, type
cd \
● 2. Now to un-mount the drive , type the following command
umount /etc/dev/fd0
Checking the file System
● The utility fsck is available for some system, while the utility e2fsck is
designed for linux ext2fs file system.
● To use e2fsck to check a file system, issue the command with the device
name and the options a(automatically correct errors) and v(verbose
output).
● e2fsck -av /dev/hda1
● This command checks and repair any problems on the /dev/hda1 partition.
Using a file as a Swap Space
● When we installed Linux, our setup program probably setup a partition
specifically for the swap space.
● To create a file used as swap space,issuethe command:
● dd if=/dev/zero of=/swap bs=1024 count=16416
● This creates a file for swap space that is about 16MB. If we want a
different size, replace the number after count with the correct value in
bytes.
● Physically create the file swap file with command:
● mkswap /swap 16416
● If we want to remove the swap file ,use the command with rm:
● swapoff /swap
Compressing files with gzip and

compress
Instead of deleting files, an alternative is to compress them so that they take up
less space.
● When run on a file, compress creates a smaller file with the extension .Z which
immediately identifies the file as being compressed
● syntax: compress <filename>
● To uncompress a file use command:
● uncompress <filename>
● The gzip utility is new compression tool that uses different algorithms than
compress.
● syntax: gzip -9 <filename>
● Example gzip -9 datalist
● The -9 option, which tells gzip to use the highest compression factor.
● A gzip compressed file has the extension .gz.
● To decompress the file which we compressed with gzip utility use the following
command:
gzip –d datalist.gz
Using tar
● The tar program is designed to create a single achieved file.
● With tar we can combine many files into single larger files which makes it
easier to move the collection or back it up to tape.
● Generally, the tar command is used to backup and restore files to and from
an archieve medium like a tape or flppy disk.
● Syntax is:
tar [options] directories
OPTIONS
● c- used for creates new achieves.
● u-used to append new file to an existing archieve.
Using tar
● -f<dev>- used to specify the device name.
● -u-used to append only the new files, older files are
overwritten.
● -t- used to list the backup files.

● Simple example is:


tar -cf archieve1.tar /usr/muk
● This command combines all the files in /usr/muk into a tar
archieve called archieve1.tar.
● To extract all the files in the archieve command is:
tar -xf archieve1.tar
Backups
● The three rules of system administrator are backup, backup, back up. This
might sound silly, but a backup can save us whenever we do something
silly to the file system.
● Backups are made with tar utility. To backup the entire system on floppy
the command is :
● tar cvfbk /dev/fd0 1440 4/
● To backup to a higher capacity tape device larger than the file system
called /dev/rct 0, command is:
● tar cvfk /dev/rct0 20/
● To restore a backup, we use the tar command:
● tar xvf /dev/rct0
Setting up your System
● You can perform several little task to optimize your Linux system,although
in many cases they are dependent on the version you are running and other
applications coexisting.

● Setting the System name:


● The system name is contained in a file called /etc/hostname.
● It is simply the name the system calls itself for identification, which is
especially useful if we are networking our Linux machine with others.
● To set our system name, we can either edit the system file or use the
hostname command:
● Hostname hellfire
Using the maintenance Disk
● Every system should have a maintenance disk that enables us to check the
root file system.
● Recover from certain disk problems.
● solve simple problems such as forgetting our root password.
● We can usually create an emergency boot disk from the CD-ROM that the
system came on, as well as obtain the necessary files from ftp sites.
Forgetting the root password
● One can easily fixed this problem with Linux.
● To recover from a problem with the root password, use a boot floppy and
boot the system.
● Mount the root partition and edit the /etc/passwd file to remove any
password for root, then reboot from the hard disk.
● After the system has booted, we can set a password again.
Setting the Login message
● If we have more then one user on the system, we can display information
about the system, its maintenance or changes in a file called /etc/motd.
● The contents of this file are displayed whenever someone logs in.
● The /etc/motd file is useful for informing users of downtime, backups or
new addition.

You might also like