100% found this document useful (3 votes)
3K views355 pages

Rh033 - RedHat Linux Essentials

Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
3K views355 pages

Rh033 - RedHat Linux Essentials

Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 355

I ntroduction RHI'O,3,3,

Red Hat Linux Esse,nti,als



redret '

Copyright

The oontents ,of this course and ,aU Its modules and related mate-r'ial's~ilf101.ud,ing handouts to audience m embers, are G,opytiight: © 200.3 IRed Hat, line.

rNJ 0 part of th'i s P ubl i 0 ati on may' be, 8tO Ifed ;i na Ifet~ eva I: sy8t:e 111' ~ tra ns m:it.t:ed 0 Ii reproduoed In Hlny way, ,irmludirlg, but: not Ii rnltsd to! phetooopy, p:notograp:n,

rn ag n eti c, el; e otro rlii cor oth e I'" record, wH:h out thl e' p,rio If 'IN titte 11 p e rtlil ,i s sio Il of Bed Hat, lne,

T'hi s eu rdculi urn C onta i 11 S pre p~ eta: rjI' :i nfc rm at:i 0 n 'W hi on is fo r tha exel usive use G~: oustomers of IR 00 Hat, lno., and is not to be shared with! ,p-ersonli1lel, other than those, inattertdance at this OOUlfSe,.

lrhi sin st:ru ct:i 0 If:I a II prog ra m ~ :i 110 I udi I1g all rna 1e ria I' pl'"cnJid ed he'Fe'i n ~i 5 8 LIp pl'i ed wit:nout: an~!' gU8!ffil:1tees from Hed Hat! 11110" IRed Hat, lne, assumes ,HO IJahiUty for damages or I~egal! action al'is,ing from the use, 01'" m:isuse of contents or de,1:aHs eorrtainee harein.

Ilf: ""1''''' b el"'le'''',e li1Ied IHI' I ",f' ~''''''''''II1'11¥1I materials are b e'I""iAI :UI!"e-AI .... op led -"'''" -"'t'if-e"'·J"'I!"e

_,'Ii.iI!;_.I,' 1~·.1i1I U I_'~~,~,II'~, I "i'Ckl II,f:I,;, I' .:;]:~'~I .: . lill~ ,_~,!WI~ vU:", ·u~ ..... 11 ul,I"1 lIi'IIT,~.

lim properly distribLlt:ed please email t:ra:ill.i t":@@ ~edhatoom or phone t:olll~h:ee ( +~ 806'0 '02'02'99'4 or +~ (9H~) 75437.0.0. redret

Red Hat Enterprise Linux

.' Enterprise-tarqeted operating system

., Fo ...• cu s •.... 9.· > d 0.·' ...• n··' rn a ... t u· r·-'B, > 0.··· ...• p' e, > n'·· 8···-0,··· ··.'U, r-,C-B, > t'e· > ch no ,.10··'''9·.', .··.Y'·.··,'

.. ' .. ' ... " .. ' ... ,... ,- '.. . .. - '.. ,'. ... ..... ,'. .. . .... ' _'. ,:

.' t 2 -1: a mo nth re 1 ease cyel e

• Certified with leading OEM and ISV' products

.' Purchased with one year Red Hat Network subscription and support contract

• Support available for seven years after release

• Up to 24)(:7 coveraqe plans available

redret .

R d H N k

ec at etwor ...•..•...

II! A comprehensive software delivery, system management, and monitoring framework

• Update Modulell included with Red Hat Enterprise! l.lnux, provides software! updates

• Management Module adds more scalable' manaqement capabilities for large

d epl oyrn ents

• Monitoring Module provides aqentless infrastructure! health monitorinq of networks, . systems I' applications, etc. redret .

Red Hat Applications

.! Optional layered products which enhance the

standard Red Hat Enterprise l.inux system

• Red Hat Cluster Suite

• Red Hat Content Manage!me!nt System

• Red Hat Developer Suite

• Red Hat Portal Server

redret '

The Fedora Project

.' Hed Hat-sponsored open source, project

• Focused on latest open source technology

• Hapid four to six. month release cycle

• Available as frelel download from the Internet

·!An open, community-supported proving ground for technclcqies which may be used in upcoming enterprise products

• Red Hat does not provide formal support

redret .

Objectives of RH033

• ,A Red Hat Enterprise Llnux userwho can be, productive, in using and customizing his or her own Hed Hat Enterprise' l.inux system for common command-line processes and desktop productivity roles

redret .

• Audience: Users new to Linux and UINIIX; users and adm in istrato rs trans ition i ng fro m another operatinq system

.' Prerequisites: User-level experience with any computer system; use of: m-OUSB, menus, and any graphical user interface

redret .

Names liP' Ad dresses

Our Ne,twork Our Se'rver Our Station s

Evil Outside, Ns,twork Evil Outside, Server

Evil Outside, Stations

Trusted

example.com 192,'68,0.0/24 server1 ,e;xampie' .corn '192,'168,0,254

stationx.example.com 192.'168.0.,X

cracker,org '92.168.' ,0/24 s erver1 .cracker .orq '1 92.1 68.'1 ,254

st atio nX.crac kef .org '1 92.'1 68 .'1 .,X

tru sted .craeksr .0 rg 1 92.1 68.'1 .2'1

redret '

UNI'T 1

redh.:::t

U- - N'" I'T l' · ·0/ <·b··-····,• '.'_.'. ·_····tl• .'. : .... '_.'

..... . ...•.... ··.·.·J8IC lives:

• Lea r n about U N IX/L ii n UI.X hi isto ry

• Understand basic UNI.X principles

• Und Ie' rst a n d J Op en S - o u roe II 'II Ice n se s

.... ·l~ •• ·•· :~ I--j!' . . ..... ' .••• _ ...• -.'1 ,; ---'-:-;-1 :~-:-

• Learn about Red Hat Enterprise l.inux

• Learn about glraphilcall environments

redh.:::t

UNIT 1 : Agenda

• UN IX/Linuix history

• UN I,X desiqn principles

• Open Source licenses

• Red Hat Enterprise l.inux

• Hesources tor gettiing help

• l.inux gralphtc:all environments

redh.:::t

UNIX History

• First version creatediin Ben Labs - '1969

• A···· 'T&>'T II~IIC- e'" n s"e' ' S'" '. s "0'" UI rc e' c '0" de fo r lo W c '0' s ,t'

. ,._, . .;. ",';' '. ' ',' . " .,1 .. ,",' III II '. '.' ..•.. ,1,-1,

.' Trademarks U:NIIX name,III'U:NIIX"" name clo 88' Iy held

• Licensees must create new name for their opera.ting systems

.' :Man'y U'NII,X "flavors" emerqe

redh.:::t

UNIX Principles

• Eve rythi ngl is a file

.' lncludinq hardware

• Confiquration data stored iin text

• Small sinqle-purpose programs

• Avoid captive user interfaces

• Abliiliity' to chain proqrarns together to perform compllex tasks

redh.:::t

GNU Project / FSF

• GNU Project started in '1984 .' Goal: Create "free" U,NIIX clone

.' By 119'90, nearly all required userspace applications created

• gee" emaca etc:

• Free Software Foundation

.' Non-profit organization that rnanaqes the GNU project

redh.:::t

G,Pl, ,- G,NU General Public

L 'II C" ',' e':'" n s e····

I ',', ~~' I ~ .. '.: _,' I I _,,_.:', '"" } '. :.' ". I

• Primary license 'for Open Source software

• Encourages 'free software

-Alii enhancements and changes to GPL software must aliso [be GPL

• Often called "copyleft" .' !I"AII rights reversed"

redh.:::t

• Linus Tcrvalds

• Finnish colleqe student in l' 99'1'

• Created l.inux kernel

-When l.inux kernel combined w~th GNU applications, complete free UN I.X-Ilillke as possible

redh.:::t

Why Linux?

• Fresh impleme ntation ot UN IX AP Is

• Open Source development mode!

• Supports wiide variety ot hardware

• Supports many networkinq protocols and C,O n'ft9 IU ratio ns

• F1uUy'slupported

redh.:::t

• A distrjbution of Linux

• Custom version of a recent l.lnux kernel

• Utilities and applications

.' Installation and configuration software • Support available'

redhst

R'8ICQ'lml mended H ard wa 'rei Specifications

• Pentium Pro or better with 256 MB RAM

Dr

• 64-lbiit Inte~lA,MD wiith 5'12 MB R,A,M

• 2-6 GB disk space

• Bcotable CD

• Other processor architectures supported .' ltanlurn ,2:, IIB'M Power, IIB'M Malnframe

redh.:::t

11"11

Local l.oqins

• Text-rnodeloqin at virtual console

• Graphical loqin

redh.:::t

112

• MUI~tilIP,le non-GUI loqins are possible throuqh the use of virtual consoles

• There are by default 6 available virtual consoles

• Available throuqh CT:RLI ·'ALT· ,F1 [i·, 6]

• lf ,X is running, it iis available 9:S

CT'-R'L A,', ~LT 'FI7'

- ,,:-- I·' - ,-- I, ,.' ",'

redh.:::t

• Modern, tree implementation o'fXFree86

• Hiigh~y 'fllexiilb~e framework for displaying 9 raph ical aIP'IP'~ icatio ns and e nviiron rne nts

• Co m P letely n etwa rlk -tra nl spare nt clliie nt/:se rye r arch itecture

• System can lbe configured to present a

9 raph leal loq ii n scree n on CT:RL·, ALT ., :FI7'

redh.:::t

114

Xorg Graphical Environments

• Collections of applications that provide a gralphica~ working environment wiith a consistent look-and-fee II

• G:NO,IME -The default desktop environment

• KD'E - Environment based on the Qt toolkit

redh.:::t

11!5

S· '. t rf 'X···, ....

•. ' . ~ I •.. ..... '. I •. ". ". '. . . ...•. ,., .... ' ....•..

" :a,· ling ., .. · IQ1rg

• Nothing needed ii" system boots to a gralphica~ ~ogiin. dust authenticate.

• lf system boots to a vii rtu all console loqin, Xorq must Ibe started manually

• Run s t.az t.x to manually start Xorq

redh.:::t

116

Chanqinq Your Password

• Passwords should be changed after first Ilo,gl~n

• From Gnome's App li.cat.i.on s menu, choose P r'9'f ereric es / 'p as swo rd

• From a, terminal, IUlse passwd

redh.:::t

117

• Ouestions and answers

• Summary

.' UNllXlLinuxHistory

• The G'NU General Publi-c License .. Red Hat Enterprise l.lnux

redh.:::t

UNI'T 2

Hunninq Commands .. td

a,n·.·· •. •··

Getting Help

redh.:::t

U' 'N'" I'T 2··'······· ·0/ <·b··,····,· '.',.'. ·,····tl• .'. : .... ',.'

..... . ..... ,... . ..•.... ··.·.·J8IC lives:

• Learn how execute commands at: the prompt

• Become familiar with some simple commands

• Become familiar wiith the many help resources in Red Hat Enterprise l.inux

redh.:::t

U- - N- I'T 2- A- d

I z: --_-.----------- 9,81 nc a

• Hunninq commands

• Some simple commands

• Gett~ngl helllP wiith --he~IP

• Gett~ngl he~IPI w~th whatiis

• Gettingl hela wiith man

• G-ett~ng hejp with info

• Gettingl hejp w~th Reid Hat Documentation

::1

redh.:::t

• Commands have the foillowiing syntax:

command [ op t ions J [a.rgU1l1·,en t s 1

• Each 'I"t'e' rn '~'S' s 'e' parated I b "Y' a space

- . - . --' . -. '.' . "1 . '-'" ',~' '1":' :--, .... , I " '. :": .' .. ': ... ' , .- .": .,-, - ......

- ",._ . '",_. I .. , ,' ':'_, , '" ", __ ",_' :.','.' , __ . ',_', :-",_ '_', ",_'

. -'

• Options modity the command's behavior

.. 'word options usually preceded by U' __ ""

.. slnqle-letter options usually preceded by ,;,;_""

• Can be passed as ii a b 'C:'" or U abc

.' ,": _',-' ,,".,' ' .. .' : ~ ~"-. j;j: ',.'_ ~' ... - - -,:~ ,-":.~., - .. -' .. ' ',:. - -, I' . :-.:

• Arquments are filenames or other data

needed by .. · · the command

_ redh.:::t

SO" 1m' .. e" S'" :'. 'II 'm' .. ple Corn 1m' .. a···· n' 'd: S··'

I' "1 .... II'" '.' ." '''1 . ". I' .", I····· II'" .. I ,_.' '. . .... , ' .. ' '

, ... ' I '. '. ' '.,- . I . . ". .' '. . . . , , ' "'_' . I·.··· r

. I . -. - - . . -. . , , . - I

• da't,e, _ display date and tiime

• cal ,_ display calendar

redh.:::t

Getting Help

• Don't try to memorize everythiing!!

• Man'y'lev'e~s ot he11lp! .' w'hat,is

• <oommand> ...... he Lp

• man and Ln.f o

• /usr'/shar,e/do1c/

• Red Hat docurnentatlon

redh.:::t

Th · c·' ". d

II' ....': ' .•.•• ......,' ·····1::

" e wna t is Oornrnanc

• Displays short descriptions ot commands

• Uses a database that is updated niiglhtl'y

• Often not available immediately after ,ii nstal II

$ whatis cal

cal {I} - displays a calend.ar

redh.:::t

The-- help Option

• Displays usaqe summary and argument llst

• Used [by most, but not all, commands

$ date - - help

Usage.: da te [OPTION]... [+FOHMA,T]

or: da te. [- u I - - ut;c I - - un.i ve.r sa 1] [MMDDhhmm [ Lee] yy]

[.sa]]

Display t.b.e current trirne in the g-i veri FOHl\.1_U!;.lT I' or set 'the system date.

< an;rument 1 i s t ami t ted>

redh.:::t

R dl Usaoe S ·

I .... '.,' .' .. ' .. ,: '., .".' . "' .•.... "1 • .". . ....• " ,I' .'., , "I '." '" .. ' I'" '.',

8,a,· .. " ,Ing .. , s,ag,e '-IU,lml!ml,a,rI9,S,

• Printed Ib:"'Y':/ --h,;O;'lp' ma m a n' d I o·i't·'h· .. ie rs

I . .... .... ' ..• ' ,- ,~,-, •. , I _. " .. -, - -, ..... ' -" ,.' .... ' ..

• Used' ,to d les cribs 'iI-'h'e syntax ot 8' corn rn and

< '.' - .• , I, .' ,-'~:' .••. ,.~ .. 1.1...,·11:.1 •• ' .. ', ,~:- '-I '-l-Ijl,

• Arqurnents iin "[]" are optional

• Arquments 'in CAP,S or "<>." are

variabl es

• 'Text followed Ib'y '~ ... " represents a list

• X'I'Y'lz m ea' n s "X' or \1 or r"

, .'."...... " ""., .... j, lj:- C,' - l' •.. " ',;'

• -abc means "any mix of -a, -b or -0"

redh.:::t

Tih' I' ','. C·····_.·, ' .. I·~··· 1·· .. ·.· ··d:

:., lie ,m:a,n .... -,IOlmllm!:a,n· .. ..

• Provides documentation 'for commands

• A···· lm ost eV"ery' corn m and has a' man "paqe"

~J "'\ ,,' .-, '.i - .. ··.·.·111:, .'. ..•.. .' .•...... ,'.1 . '11 '..1 '.'

• Page:s are groulped 'into "chapters"

• Ca!~~ectiive~y' referred to as the Linux Manulal

man [ <chap 't,er> ] <command>

redh.:::t

·Wh~lle viiewilngl a man paqe

• Naviqate with arrows, pgUp, pgO'ow'n

• /'<t,lext,> Search for text

.' n/N Next/P revlo us match

• CJ[ Oult viewing page

• Searching the Manula~

• ma .. n ... k '<:keyword> List a,11 matching paqes

• Uses whatis database 111

redhst

• Siimii~ar to man Ibut often more in-depth

• RUin ,ill,fo without args to list al! paqes

• .inf o paqes are structured liilke a web site

• Each page is divided into "nodes"

• links to nodes are preceded by ~'*""

i.nfo [<,comm,an.d>]

redh.:::t

112

·Wh~lle viiewilngl an ,in,fa page

• Naviqate with arrows, pgUp, pgO'ow'n

• T,ab, IMove to next link

.' Errt er Follow link the' cursor is on

• n/p/u Vie'w next/previous/up-one' node

• s.[<ts'x.t>] Sa-arch for text (default: last search)

• q Oult vlewlnq paqe

redh.:::t

E te nde d D······· ···1 II·.· itati .

LX ."en t ·• 19· .. .. -_ ..... IQICUllm!,8In .:a, IIIQln

• The /·usr·/sh,or·e/doc directory

• Subdirectories. for most installed package's

• Location of docs that don't fit elsewhere

• Example configuration files

• Html/pdflps documentation

• License details

redh.:::t

114

• Available on docs CD or Red Hat website

• [Installation Guide

• Intra to System Administration .' System Administration Guide' • Heference Guide

.' Security Guide

• Step-by-Step Guide

.' ... and mors'

redh.:::t

11!5

End of UNliT 2

• Ouestions and answers

• Summary

.' Running commands • Getting help

redh.:::t

116

UNI'T 3

Browsing the Filesystern

redh.:::t

U- - N'" I'T 3-1• ·0/ <·b··-····,· '.'_.'. ·_····t'· .'. : .... '_.'

..... . ....• --.. . ..•.... ··.·.·J8IC lives:

• By' the end of this unit, Y'O'UI will Ibe alblle

to:

.' Understand the' l.inux filesystern hierarchy .' 'Manage file's from the' cornrnand llne

• 'Manage files using 'Nautilus

redh.:::t

UNIT 3: Agenda

• The root directory and the fllesystem

hierarchy

• COiP'Y, move, and remove

• Creatinq and viiewiing fiilles

• Usinq Nautilus

redh.:::t

Linux File Hierarchy Concepts

• File s a nd d ire cto ries ~ a ire orqa " n ize 'd-' into

~.- '. ".-'" I:, .. :, .: '.' --. .: .: .. It ,- I v-'. II: .'-

a silnglle-rooted inverted tree structure

• File s'Y' ste m' b e' gl"'1 n s a' t th e U ro ot''

-~ :__ _~ .', .• .~,_ ,1_11: me : .'1' 1_

directory, represented by a lone "t" (forward slash) character.

• Names are case-sensitive

• Paths are delimited by "t"

redh.:::t

Sorn ···I,e······· '1 m p·······,O·····,· rt·· . a n' t D> :·1 r ,e' -c .. :tIO···1 'r···j·l,e······· s

, .' ·.·1 I I' 1 1[" . I 1 -/ I ".< 1.· ·.. . .

• The horne directories

.' /root, Ihome/<u'sername> • The biin directories

• /bin, lusrlbi n, lus.r/local/bi n

• /sbi n, /usr/sbl n, /us r/local/sbin

• Foreign fiilesystem rnountpoints .' /rnedia and Imnt

redh.:::t

• /etc

• /tmlp

• /boot

- S'y'steml confiq files

- Temporary files

- Kernel and bootloader

• Ivar and letv - Server data

• /proc and Is'y:s - S'ystem intorrnation

• The Iliilb directories

.' /lib, Ius r/l ib, /usr/loeal/lib

redh.:::t

Current Working Directory

• Each shell and system process has a current working directory' (cwd)

• plw1d

• Displays the' absolute path to the current directory (the shell's cwd)

redh.:::t

• Names may be UIIP to 255 characters

• A'II~ characters are valid, except the "I" .' lt may be unwise to use' certain special characters in file or directory names

.' Some characters should be' protected with quotes when referenclng them

• Namles are case-sensitive

.' Example: MAIL, Mail, mai.L, and :mAiL .' ,Again, possible, but may not be, wise redhst -- ' .. _.

Absolute Pathnarnes

• Absolute pathnarnes Ibegiin with a slash (/)

• Complete "road map" to file location

• Can Ibe used anytime you wish to specify a fiile name

redh.:::t

Helatlve Pathnarnes

• Helative pathnames do not lbegiin with /

• Specifies location relative to your current

working directory

• C'" a' -n° b e IU- s 'e' d' a' sash' orte r wa"Y to spe c ~f-y'

.·..:1 ~__ _.-_ '.'-.'. "c .-'_-'. anoi .•• _'_ '," .. ".""'-'._ I,:C_~-'II_

a file name

redh.:::t

• cd changes directories

• To an absolute or relative path: $ cd /home/j oshua/work $ cd project/docs

• To a directory one level up: $ cd ••

• To your home directory: • c .. ad

Ifl ':. ". -: .. - 1

• To your previous working directory: $ cd -

redh.:::t

11"11

• Liists the contents of the current directory or a specified directory

• Usaq .. -·.e···

.: '.'I~. __ .• _', .' ,".

l,s [op't"ion,s] [fi,l,e,s,~or=d,i,rs]

redh.:::t

112

Copying Files and Directories

• cp - copy files and directories

• Us' a" 'g' e:

, ,,' ,-, I " ,,' •

I t ii 1~ f" ii 1 d t ii t: ,.

cp ,op~,,~o,ns ',' ':~ ",f!!': ,es~,,~n,a,~o,n

• More than one fille may Ibe copied at a, time ii'f the destination is a directory

cp Iopti iotie] filel fil,e,;J' deet:

redh.:::t

C·· 'I F"III . d D:il . t· . 'I

"I" ..•.. ,.... -' I ,," , .', ........•. 'I '., " 1 .•...•.. I I' .' I '.' .•.. I' •

opyrnq I es, ano tnrec tones:

Tlh: 'e Desti n af o n

• lf the destlnation exists and iis a directory, the cOIP'Y is placed there wiith the same name

• I'f 't'h e· destin a' fion e' xists a' nd ','IS a f lie 'the'

I ure ueat ····'.:I~~.·,--,:~-I,:-I-I :~ ••• '.11-:,1---.

cOP'Y' o v 'e' rwrites th e d' eeo't"'1 n a' f o n f"",','11 e·

_~-IIVVIIII,'~ .ne •..• ,~ijjl--I-~IIIII L.

• lf the destination does not exist, the copy is created wiith that name

redh.:::t

114

• mv - move and/or rename files and directories

• Usaqe:

mv IoptzLotis I fil,e d,est.inat,ion

II' 'More than one filemay be moved at a time' if the destination is a directory

mv Loptz iotis I fil,el file,;2 d,est.

redh.:::t

11!5

Moving and IRena.ming Files and Dlrectories: The Destination

• I" the destination exists and is a, directory, the source tile or directory iis moved there wiith the same name

• lf the destinafion exists and ls a file, the source flle iis moved to that filename. overwritinq the file

• lf the destination does not exist, the

source file or directory ls renamed wii~" 116

- redrct

that name

f"~

. '. . , .

. zm - re move II es

• Us' aqe:

. '.' ,- ,I " .. ' •

rID, Loptz i one] fil·ena.m,es ... i • .. i-interactivE!'



• -r' - recursive

• oiii f" - to r' 'c'· '. e, ".-

, ., .. " ..... ,",

• t ouch '-, create empty fillies or update

'fille timestamps redhst

117

kd ·

• m · •• ·····1.,r

make a directory

remove an empty directory recursively remove a directory and alill 0" its contents

• rmd,i.,r

• rm -'r

redh.:::t

u· .. · .:1 N······· ..•..... , .. It':III· .

srnq au, I,ll U'S

• Gnome glraphiic;all filesystern [browser

• Can run iin "Spatial" air "Browser" mode -Accessed via ...

• Desktop icons

• ·c·.·· om puter: Hoot ·f~·11 esvste rn n e·tw·· . '0·· ··rk·· r e ·S·· ou rce ·S··

.•.•• • .•..• ,' i, .•• ••. '. "~1~' .• ' :! .' '. '.' : '.... .':': .•.. ' . .: .,:.~

and removable media.

.' "File Browser" option on Applications men

redh.:::t

119

'M"" .' ... ' .. ,::1 . '.':" ,'., ... ' d 'C>" ..... ',' >", . il '. " ' ..... ' :1 ... , ·N········· , .. ,. t:III' ".,.: .. ,

novrnq an ..... opyinq m 1 a,u, III UIS

• Draq-and-Drop

• Left-button: Move on same filesystern, copy on differe-nt fllesystem

• Ctrl-Left-buttcn: Alw'a'Ys copy

• .Alt-Left-button: Ask whether to copy, move, or create symbolic link (alias)

• Context menu

• Hiqht-cliek to rename cut, copy or paste

redhst

Determininq FHe Content

• Files can contain many types ot data

• Check file type wiith fii~,e before openinq to determine appropriate command or application to use

• S'y'ntax

fi.Le Iopti i one] file,nam,e{s,)

redh.:::t

211

• Sy'nta,x:

,cat, [options] [:f'ile ... 1

• Contents ot the files are displayed sequentially wiith no break

• Files display "concatenated"

redh.:::t

Viewinq Text Page by Page

• Sy'nta,x:

Le s s Loptz i one] [f'i1 eneme]

• Scrol II with arrows!P9IUIP/IP,gIDown

• Useful commands while viewinq:

.' ttext

- search for text

- next match

.' v - opsin file in text editor

• less iis the paqer used by man

redh.:::t

• Ouestions and Answers

• Summary

• 'The l.inux fllesystern hierarch'),'

• Cornrnand-Ilne file manaqernent tools

• The Nautilus' file rnanaqer

redh.:::t

UNI'T 4

'-Th·' S··· hili

I . L... .. . . - ' '

hebaah "" ,,9

redh.:::t

U- - N'" I'T 4·" • ·0/ <·b··-····I• '.'_.'. ·_····tl• .'. : .... '_.'

····.1 • . ..•..•. ··.·.·J8IC lives:

• Learn about available shells

• Learn command line shortcuts

• Learn how the command line is

ex . ~p' a" n' d 'e''- ·d· a n d' h· .' '0" 'W" t'o·· '1'1 n h·· "1IIb··· "lit e' '. 'X' p a' .' n s io n

.'1:1 ._'.' - ...• - - . -~ ....•. - <I -'11- --_ ,-I -- I .. 1 I :~...I--I:,- ~ ..•.. -

of specia! characters

redh.:::t

UNIT 4: Agenda

• Shelill heritage

• Command line shortcuts

• Command Iliine expansion

• Inhiilb,iitiing command 11~,ne expansion

• History and editing tricks

redh.:::t

• "Bourn . e" A"'ga"~lln" S~':he"II~u

......•...... "1'-,.".1 '. II

• Successor to ah the oriqinal Unix shelill

• Developed 'for the GNU Project

• The Ide 'facto standard l.inux shell

• Backward-cornpatlble with Bourne shell (sh) - the oriqinal (standard) UN IX shell

redh.:::t

b '.' h' H' r It,··,· ' ,'.', ' •. '" id Featu ' ,.

ne ar errtaqe anc ea UI res

• Bourne Aglaiin Shell (bash,)

• lrnplements many of: the best features from

earlier' shells: ah, e ah, leah, t.e ah

• Command line completion

• Command line editing

• Command line history

• Sophisticated prompt control

redh.:::t

Command l.ine ,S:hIIOrtC!U!t:s::

Fill,e Globbi ng

• G lobbinqis willdcard expansion:

.' * - matches zero or more characters .' :? - matches an')' single character

.' [a- :z:] -matches a range of characters .' [,I\a":z:] -matches all except the' range

redh.:::t

Command l.ine ,S:hIIOrtC!U!t:s::

The Tab Key

• Type <TAB> to complete command lines:

• For the command name, it will complete a command name

• For an argument, it will complete a tlle name

• Examples:

,$ xt"e'<,TAB:> $ x t.e rm

$1s myf'<'TA'B,>

,$ La myfile. t,xt, redhst

Command l.lne Shortcuts:

history

• b h stores a' history of commands

-as, ,-1.···- ,'-:-1 :~~_I '_1--- "-1 .'_ I>

you've entered, which can be used to repeat corn m ands

11-- - .1-,--;- .'- '-"JII' ; '.',

• Use h,i,s't,ory command to see, II~st of "remembered' commands

$ histo:ry

redh.:::t

C d 'L'· E , .

. ," I,' ," I," .. - , l . ,; ,-, ," '", ' "-., " .' _. ,"'- - "-" -' -, ," " - •

IQllmllm!a, n .• ".' 1,1 n 'ei _I x pa, ns: 1110 n .

'Tild,e

• Tii~de ( ,~ )

• :May refer to your home directory • cat, ~l.bash__profi1e,

.' :May rs,fs'r to another US9'rrS home, directory $ La ~julie/public __ ht.ml,

redh.:::t

Command Li ne Expansion:

Variable and Stri ng • Parameter/variable: ( $ )

• Substitute the value of' a variable in a command line

$ cd $:HOM:E/public __ ht.ml,

• CUI r ~'Y Ib races: ,( }

• ,A string is created for every pattern inside the braces reqardless if any file exists

$ rm hello .. {c , o]

redh.:::t

Command Li ne Expansion:

C· .. d d M h

ornrnan •.••• ·•· anc v ath

• Command Output _' " or $ ()

• Substitute output from a command in a command line

$ echo IIH:o s t.name : '~ ho s tmame - II

• Arithmetic _ $ [ ]

• Substitute result of arithmetic expression in a command line

s echo Are,a: $ [ $X * $Y ]

redh.:::t

11"11

• Backslash ( \ ,) is the escspe character and makes' the next character literal

$ echo Your cost: \$5~OO

• Used as last character on line' to "continue command on next line"

;$ eeh,Q II' ''!h,i till long t~.ampl e tEli't.r.'in,g' w'ill :be ech!oed, \ » :b,!!J.ck ,a.t~ one long line"

redh.:::t

112

Protecti ng trom Expansion:

QiUI10tI81:S:

• Ouotinq [prevents expansion

• Single quotes C) inhibit aJI expansion

• Double quotes ("II) inhibit all expansion, axe 'e' ·p·t"

" .'.- ... .,..: -'.' " - :~- ','.-. .

$ (dollar sign) variable expansion

.. (backquotes), command substitution

\ (backslash], single character inhibition (exclamation point), history substitution

redh.:::t

• Use, the up and down arrow k,B'"YS to scroll through previous commands

·T'ype '<,C TR,L .. R:>' to search fo r a co m m and in command history.

• (::re,ve,rse, - i-search] - II :

• 'To recall last argument from previous command:

• <' 'ES' C" ' .....

':'~I - - · .. · . .-'1.

(the escape key followed by a period)

• <:ALT - • ::>' (hold down the a.lt key while pressin 114

the period) redhst

C .. ... ... . ... ' ... d Ed; :It, 'I ... :-T··· ~I ., k , . Qllmllml,a,n" - " ,I dng r,le ::S

• <C't,:rl- a> moves to Iblegiinniing ot line

• <:C't"rl, -, e> moves tal end ot line

• -e C.'t,r 1, -u> deletes to Ibegl~nniingl ot Iliine

• <,C't"rl-' k> deletes to enid of line

• <C't,rl, _, ar,row> moves left air riight Ib'y' word

redh.:::t

11!5

Command Editing Tricks:

Editing Modes

• B'y default, bash, uses emacs-sty'~e keybindinqs for corn rnand ed ~,t-ing

,. _I ""<1 < ~ :1 , -,- ' .. "'11- III~ "',

• Type se't ., 0 v,i to chanqe keybindlnq to v,i,-sty'lle

• Malke v,i the default by addinq the

d b t' . $'-'" HOME/·'· t

-- ' .. , ".'" ' .. , ".,..- I .. "-1 ' ••..• - ' .. '.. •. 'I' .,' '.'.' - ". - .' . - 1 .. ' ," .•...• - - '.' - . "". '

CQ1mlmian a·101veo "',',', . ,"" =-- r» ,1"n,pu "re

redh.:::t

116

II 1 qnome- t eznu.na.

A 1 i ,. ii /. .. -1 /. Ii 1

• PP .t.ca.taone Syst.em. Too .s.>T·erm .. a.na ..

• Graphical terminal emulator with support 'for rnaintaininq multiple "tabbed" shells

s ii rnu ltan eO'1U1 S Ily'

• <C·trl·, Sh"ift,·, ·t,>

• <·C't.rl.·· PgUp!Pg:D:n,>

Open a .. new tab N ext / P rev tab

• <C't.rl · Sh"i f ,t.·, e/v> Copy I Paste

redhst

117

• Ouestions and answers

• Summary

redh.:::t

UNI'T 5

Sta nd a rd 1/·······0·· r ··· ·a······· nd Pipes

I - '. . ~I I.. ',.' _ I -:- .. ' '~_ I • ',.' .i ", . '_ .. '. '_ . ,.' : ~. . ~I II '. '. ,_ . _, .' .,: I. . . .' r 1,:'" . ..1

, I , , ... .,. . . I, I . "' I, r" " .- ...

redh.:::t

U' 'N'" I'T 5" .• ·0/ <·b··,····,· '.',.'. ·,····tl• .'. : .... ',.'

..... o , . ··.·.·J8IC lives:

• Understand standard 110 channels

• Understand fille redirection

• Understand pipes

redh.:::t

UNIT 5: Agenda

• Standard 110 channels

• FHe redirection

• Pipes

redh.:::t

Sta n "d' a' . r d 'I n' p' ··'u;t· a'" n 'd'" 0"""':' utp u t

'- : " , 1 I" ,- , " I. I' .', .. ,' ,~i, 1 ' .•.. ,.< .' .•... ' " I I, ' ' .. ' '. "., .

• Linux provides three 110 channels to

processes

• Standard input - keyboard is default

• Standard output - terminal window is default .' Standard error - terminal window is default

redh.:::t

Redirecting Input and Output

• Standard lnput, OUt:IPUlt, and Error can be reconnected to alternate locations

.. Shell redirectlon operators allow standard 11/0 channels to be' redirected to/from a file

.. Pipes allow standard 11/0' channels to connected to the, input or output of programs

redh.:::t

Redirecting Output

• In order to study redirectinq standard output and error, we w~~11 use the f,in,d command,

fin,d /,et,lc, <riame passwd

.' This command will search tor all fils's named passwd in /,et"c and its subdirectories.

• By default both the standard output and standard error are, displayed on the' screen.

redhst

• Hedirect standard output wiith > • Example:

find let.a -nama pasBw'd :>'findresult.

• St a' nd a' rd e' rror ','IS 8't-""1 II II d ~IS' play ed o n t he

· •• ··· .• I·'~: ..•..•• ~. 11:111 : ,-I ~ ..•• - .. '-lll-I~< ...• :II 1"-"-

screen

redhst

Overwriting or Appending

• I'f the tarqet file 0" flle redirection wiith > already exists, the existing file wii~lllbe overwritten

T d d t t ~l til t' ~ I

• " .. "11' ,.,' .' ..... r ".' 'I '- .'. ," .... ••••. , .... ~'I ....• -' • ....• • I. "" ~ •..

. 0 alPlpen .' a,.a,.o an e,XIIS :llngl III e, use

» to rediirect instead of >

redh.:::t

Hedirectinq Standard Error

• Hedirect standard error wiith 2>

• Example: redirect standard error to a file: find /e,'to -name passw'd 2::>· finderrars

• Standard OUI'tIP1Ut is displayed on the screen

• Rediirect further standard error,

appe ndl'I'lngl ·to· ·t·he sam e' 'f····I'llle with t-'\.>. > .

...•.. · ••.. enum ......•..• ~.· ..•. l :~<~ ... --: I .• ~., .... I'" L.I>

redhst

Redirect:ing Both Standard

Output and Error

• R·· e d 'II' re ct ~o· n ot sta n d' ard o ut put a -n· d'

_1__-, ~ ~.. .... . ~ II :~ 1-1- o r ...." .... 1,:1-

standard error can be performed s ii multan eOIUI:9 II'Y':

find / "name passwd 2:> errs >, result,s

• Each 110 channel can lbe redirected to difte rei nt file 5'" or 't-o' the' sam' e' file iI

I •• ·'_-1· 11- ,-, . ...•• . I ••. 11_:0 '-1- 1- •

find / -name passwd :>, allout.put 2:>,&:1 (or) find / -riame passwd s> al1out.put

redh.:::t

• Hedirect s nandard I inpu It W 'Iii ih <

_1._-, ,1,-1.· .•....... ··.·1· .• -.·.· .n v , 1 ....<

• Sorn e· commands only operate on

•........•• ~.... ...-: ir ...- ...•. ~ .1- ,.~ .. ~.· .• ·III_ . .1·/-:: IL- ' .• ·.-1

standard input

• t,r doesn't accept filenames as arguments - it requires its input to be redirected from somewhere

• t,r il A - Z II I a - z il .<: • bash_profile

• This command w'ill translate the uppercase characters in ,0 bash___pro:f"i.l e to lowercase

redh.:::t

11"11

Using Pipes To Connect Processes

• Pipes (the ,I characterj let y'OUI redirect output 'from one command to Ibecome the input to another command

$ Is lusr/lih I less

• Can create pipelines - B powerful feature of L'iinUIX'

$ cut -fl. -d: pa,sBw'd I Bort -r I Le.s s

redhst

112

Useful Pipe Targets

• l,ess displays input one paqe at a tiime Is -1 I less

• mad L sends input via email:

1 s - 1 Imai 1 - s ,1~Fi 1 e SI'I bob@example, • com

• Lp r sends input to the printer Is -1 I Ipr

• xargs converts input tOI arqurnent list cat, file,s_. t,o_. delet,e,. txt; I xarqs :rm -:f

redh.:::t

te···e··.·

. . .

"-"'-'" .. ' ..

• Lets ')I'OIUI tee a pipe: redirect output to a file wh 'lIllie s't~~11 P"'llllping lt to an' o·,t- he' r p roqra m

I ~- .. ,'. ,.-.' :'1-1111 1-/11 .-', ' .....•. III .• __I .' .• - ,I·., ' ••• ,'~' III .-'

$ set ~ tee Get.out ~ less

• ln example, output from s,et, is written to file B,e't, .. ,o'ut, while also being piped to l,ess

redh.:::t

114

• Ouestions and answers

• Summary

• Standard 11/0'

• Fils, Hedlrection

• Pipes

redh.:::t

11!5

You might also like