$passwd $man Passwd $PWD $CD $mkdir $rmdir $ls $cat $head $tail

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 49

$Passwd

$man passwd
$pwd
$cd
$mkdir
$rmdir
$ls
$cat
$head
$tail
$cp
$mv
Wiled card character

We can perform an operation on a set of files


without specifying all the names of files on which
the operation is to be performed.

We can use special characters in the command
instead of actual file names.

The shell interprets these special characters also
known as wiled character as a special pattern of
character.

The shell then compares all the file names under
the directory specified in the command to locate
file names that match the pattern.

The command is executed on files whose name
match the pattern.

$cat c*

The ? Wildcard

$ls *.?

The above command displays all the files that
contain any character before a period followed
by a single character after the period.

The [ ]

$cat a[123]

The above command displays the contents of
files with two character file names starting with
a and with the next character as 1,2, or 3 such
as a1,a2, and a3.
Filters

A filter is a program that takes input from the
standard input file process it and sends the
output to the standard output files.

Linux provides various filters such as cat, grep ,
wc , tr , and cut to enable us to work effectively
with data.

$grep “root” /etc/passwd

The above example displays the lines containing
the expression root in the /etc/passwd file.

Options -n use this option with the grep filter to
display each line matching the specified pattern
along with the line number. The line number is
printed at the beginning of the line.

-c to display only a count of the lines that match
the specified pattern.

-v to display all the lines that do not match the
specified pattern.

$grep “new[abc]”

$grep “new[a-g]”

$grep “new[^a-g] other than a-g

$grep “new[abc]$”
Wc , cut

Wc used to count the no of lines , word and
character in a file.

$cut there might be situations where we need to
extract specific columns from files.

We can use the cut filter to extract specific
columns from files.

In addition we can use the cut filter to extract
the output of certain command such as ls and
who.

$cut -d ':' -f1 /etc/passwd

-f display the specified column .

-c display the specified characters.

-d specifies the column delimiter.

$cut -c1-5 /etc/passwd

$cut -d “:” -f1,6 /etc/passwd

$cut -d “:” -f1-4 /etc/passwd
tr

The tr filter is used to replace one set of
characters with another

$tr ':' ' ' < /etc/passwd

The above command replace each occurrence of
the : symbol in the /etc/passwd file with a space
and displays the output on the standard output file.

$tr -s “ “ < temp

$tr “[a-z] “ “ [A-Z]”
Pipes

In Linux we can combine filters with other linux
commands such as ls or more so that the
standard output of one filter or command can
be sent as standard input to another filter or
command.
tee

Save the out put of the another command .

Tee command to redirect the standard input
and write it to standard output or to files.

$cat temp | tee temp1 temp2

$sort numbers | tee sort-numbers |more
File Access Permission(FAP)

The file owner represented by u

The group owner represented by g

Other users represented by o

The command $chmod <mode> <filename>

Symbolic – the permission and the user types are
as a number

Absolute – the permission is specified as a number.

Symbolic

Ugo+-

Absolute

4 read 2 write 1 execute

the umask value

We create a file the umask value and the mode value
determine the initial file permission.

By default the mode value is 666 for files and 777 for
directories and executable files.

To derive file access permission the value of umask is
subtracted from the mode value.

By default the umask value is given as 002 for
user and 022 for root user which means that
each file that a user creates has the permission
666 – 002 = 664(rw-rw-r--).
Controlling process execution

The symbol used to request for background
processing is the ampersand(&) which is typed at
the end of the command line.

$wc tempfile &

$vi newfile

The user gives the wc command and begins editing the
file newfile without waiting for the completion of the
previous process.

The kernel assigns a process ID and returns the control
of the screen to the user.

$wc tempfile 1>counttemp 2>errtemp &

We will check the background process to
determine its current status.

$ps

$top used to display ongoing CPU activity .

Terminating a background process

An urgent job needs to be completed quickly.
Therefore all unimportant process need to be stopped
immediately.

A command/shell script does not terminate as required
and the only way to stop it from executing is to
terminate it.

The terminal stops responding or hangs because the
program being executed does not function as required.

$kill 278

We can stop process temporarily by using <Ctrl>
and z key. The process would still be present in
the memory. We can start it again in the
background by using the bg command and in the
foreground by using fg command.

$bg %1

$fg %1

Finding the time taken to complete a command

$time find /etc -name “passwd” 2> /dev/null
Scheduling tasks

Shell scripts are used to submit a set of
commands to the shell for execution.

Shell scripts are useful for batch processing.

They have to be explicitly invoked by the user.

We may require the shell to execute some shell
scripts or utilities at scheduled time with out
explicitly remembering to call the utility.

The shell provides two simple utilities to
schedule the utilities that we want to run at
specified times.

They are the cron and at utilities.

The crontab utility instructs cron to execute the
commands on a specified date and at a
specified time.

Minute hour day-of-month month-of-year day-
of-week command.
The need for making backups

Data is critical to an organization.

The loss of critical data can result in the loss of
both time and money.

The situations are

Accidental erasure of data from a disk

Corruption of data due to power failure or a hard disk
crash.

Virus attack on the files in the system.

Upgrade of the system to provide for a larger storage
capacity.
Qualities of a good backup

Reliability

This is a most important factor . To restore a backup we
need to make a reliable backup.

Speed

Crashing of the server the restoration of data must be
quick with out any delay.

Availability

The availability of a backup is of primary importance in
all situation.

Ease of use and documentation

We must ensure proper documentation of data.
Backup strategies

Full backup

We make a complete backup of all the required files.

Incremental backup

We backup only the files that have been modified
since the last backup was made.

We can use the backup levels to keep a track of
all the backups.

The level of backups indicates the type of
backup being performed.

Level 0 backups are performed immediately
after the OS is installed and configured.

Two types of files backup 1. users files 2.
system and software.

/home and /etc directories are generally the
most important files that we need to backup.

/tmp, /proc, /var not important.
Selecting a backup medium

The portability of the backup

Support for unattended or automated backups

The user interface for the backups

Support for remote backups

The media types supported by the backup utility

The cost of the backup utility.
Mounting and Unmounting a file
system

Mount <type options> <device>

When we specify the mount command without a
parameter a list of the file systems/devices
mounted on the system is displayed.

In the syntax for the command -t type is optional
and is used to specify the type of the system.

Linux uses the ext2 file system as the native file
system.

Do not specify -t type then the file system is
assured to be a linux file system.

Each device attached to a linux system is consider
a file.

Every hardware device contains an associated
driver.

The driver enables a user to communicate with the
device.

/dev the file fd0 represent the 3.5 inch FD.

$mount -t vfat /dev/fd0 /mnt/floppy

$unmount [device] [directory]
tar

Linux provides various commands and utilities to
back up data such as tar , cpio and dump.

Tar command is used to store, back up, transport,
and archive files. When we use the tar command
to back up data it creates an archive file called a
tar file also commonly known as a tarball.

A tar file have extension of .tar.

A tar file is a single file contains multiple files.

It can also store file attributes such as the file
access permissions user and group owners sizes
in bytes and time of the last modification.

TAR(TapeARchiver).

Is commonly used to perform full and incremental
backups of data because tar files can preserve
both file information and directory structure.

By default tar does not compress files.

$tar [options ] [file names] [directory names]

Options – A,c,d,r,t,u, or x

$tar -cvf trial.tar /root/test/*

C – to create a new tar file.

V – verbose which means that detailed
comments are displayed as the operation
proceeds.

F – to specify the name of the tar file or the
location at which the archive needs to be
created.

The tar file does not store the absolute file
name.
Restoring files

$tar -xvf trial.tar

Listing

$tar -tf trial.tar

Comparing the files of an archiev with disk files

$tar -dvf trial.tar

Adding files

$tar -rvf trial.tar /root/test/tmp

Updating

$tar -uvf trial.tar /root/test/m.c /root/test/a.out

Deleting

$tar -tvf trial.tar

Concatenating tar archive

$tar -Af trial.tar script.tar

Compressing files

$tar -zcvf trial.tar.gz /root/test/*

View the content of the compressed

$tar -ztvf trial.tar.gz
cpio

Utility to copy files to or from a cpio or tar archive.

We can use the cpio utility to store an archive on any type
of backup media.

Can also be used to store and retrieve large amount of
data.

Can use to compress data efficiently.

Is designed to make backups that span several tapes.

In addition cpio skips the bad sections on a tape and
continues to make backup, where as the tar utility crashes
and corrupts the tape.

This archive contains files and information
about the files such as the owner , date and
time of modification and access permissions
Dump and restore

Dump utility to back up files from a file system.

Is used for backing up data and not for
archiving.

Back up files to be stored on tapes, floppy
drives, or any other back up medium.

If the size of the file is large it automatically
spans multiple volumes.

It support remote back up.

This performs the inverse function of the dump
utility.

Restore files into the file system from a backup
created by using the dump utility.

Use to restore a full backup and then restore the
incremental backup.

$dump -0 -f full_dump /home

$dump <backup-level> [options] filesystem

$restore <operation> [option] [file/s]
Compressing files

The compress utility to compact a disk file into a
file of smaller size.

Replace the file with .Z extension.

Is reduces the size of the text file by
approximately 50 to 60 percent.

$compress

$uncompress
gzip&gunzip

With extension of .gz

$gzip <file name>

$gunzip <ziped file name>

Options are c,d,h,L,-n,-N,-r,-l,-q,-f,-t,-v,-V
Communicating with other users

$mesg

$talk

$write

$wall
$mesg

To control other users can send messages to
us.

We can set a terminal mode such that other
users can initiate a chat session with us.

Mesg y and mesg n.

Set $mesg n other user cannot send messages
to us.

Type $mesg this will display the current
message permission setting for our system.

We can talk or chat with other user.

Is an interactive messaging system that copies
lines from our terminal to that of another user.

$talk person [ttyname]

Other person does not accept the message talk
will send the same message every 30 seconds
until person accept it.

Person can cancel the call by using the <ctrl> c.

$write user_name [terminal_name]

$wall <mesg>
finger

To display the status of all the users currently
logged on to the system.

Displays information such as the user's login
name,full name,terminal name,write status,idle
time, login time,machine address.

The write permission is displayed with the
terminal name as an asterisk (*).

It indicates that the write permission is denied.
chfn

We can use the chfn utility to change the
information that is displayed when the finger
command is executed.

The chfn utility checks for the user's information
from the /etc/passwd file and allows the user to
change the information.

$chfn [options] [username]
ping

To verify whether or not a particular IP address
exists and can accept requests.

$ping 172.17.68.143
traceroute

When we execute the traceroute command it
displays the sequence of hops the packet has
traversed.

The sequence of hops is determined by the
specific gateway computers at each hop over
the internet.

We can also use this to calculate and display
the time taken by each hop.

$traceroute 172.17.68.120
ssh

You might also like