Vous êtes sur la page 1sur 18

:RH033RedHatLinuxEssential:

RedHatLinuxFamily
A) RedhatEnterpriseLinuxAdvanceServer:

ThetopofthelineRedHatEnterpriseLinuxSolution,thisproductsupports
thelargestx86compatibleserversandisavailablewiththehighestlevelsof
support.
B) RedhatEnterpriseLinuxEnterpriseServer:
Forentrylevelormidrangedepartmentservers.RedHat
EnterpriseLinuxESprovidesthesamecorecapabilitiesasAdvance
ServerforsystemswithuptotwophysicalCPUsandupto8GBof
mainmemory.
C) RedhatEnterpriseLinuxWorkstation:

:Commands:
1) #mkdir<foldername>
2) #mkdirp<parentfoldername>/<subfoldername>

p=createparent&subfolderevenifitisnotthere
3)#cat>newfilename(thisisallowtocreatefile&tosavefilepress
Ctlr+d)
4)#catfilename
(toviewfilescontent)
5)#catfilename>newfile(thiswillappendcontentofpreviousfiletonew
file)
6)#cat>>filename
(thiswillappendtothefile&tosavefilepress
ctlr+d)
7)#date
(Todisplaydateandtime)
8)#dates20041209(yyyymmdd)(thiswillchangethecurrentdate)
9)#dates18:00 (thisiswillchangetime)
10)#dateMMddhhmmyy(itchagesdate&timetogether)
MM:Month

dd:Date
hh:Hours
mm:Minutes
yy:Year
11)#date+Todayis%A,%B,%d,%Y.%nThetimenowis%r,%z.
TodayisSunday,may05,2005.
Thetimenowis02:54:45PM,EDT.
12)#cal122005
(12representsmonth,2005representsyear)
13)#cal
(Itwillshowyoucurrentcal)
14)#cal2006
13)#cpsam.txt/root
(Thisiswillcopysam.txtfiletorootfolder)
14)#cpfilenamefilename(Thisiswillcopythecontentofonefileto
another)
15)#cprip/onefolder/secondfolder
i=Interactiveaskbeforeoverwriting
r=recursive (Thecontentofsubfoldersandfiles)
p=preservepermission
16)#pwd

(Toseethestatusofpresentworkingdir)

17)#cd..
(Thisisallowtocomeonestepback)
18)#cd
(Ifthiscommandisexecutedbyanyuserthenheor
she
willbeswitchautomaticallytohomedirfore.g./rootforroot
user)
19)#cd/
(Thisiswilltakeyourootofthiscurrentpartition)
20)#cd~
(Ifthiscommandisexecutedbyanyuserthenheor
she
willbeswitchautomaticallytohomedirfore.g./rootforroot
user)
21)#cd
(Itwillswitchutopreviousworkingdirectory)
22)#cd../root/sameer/test(Thiswillfirsttakeubackonestepandthenit
willswitchutoparticularfolder.)
Note:.representstothecurrentdir
..representstotheparentdir

Therearetwotypesofpath1.isrelativepathwhichrepresents.and2.is
Absolutepathwhichisdenotedwith/root/desktop
23)#ls
(Thisislistthecontentofaparticularpartition)
24)#lsaldR
a
(Allhiddenfileswhichisstartingfrom.file)
l
(Longlisting)
d
(Toshowonlyyoudirectories)
R
(Toseethecontentofsubfolders)
#lsld/home/sameer(Toseeonlydirectories)
#lssh[]*(Itwilllistallwhichisstartingfromthewordshandinwhich
thirdpositioncanbeletterornowhichwecanputinsquare
bracket[]after*definesanything)
[]Thisisknownaspositionalparameter.
[]
#lssh[123456789]*
#lssh[09]*
#lssh[02468]*evennomatch
#lssh[!02468]*
!notoperator

#lsal|grep^d(Itshowsonlydir)
#lsal|grep^(Itshowsonlynormalfiles)
Note:^thissymbolisknownascaret.
*,?isknownaswildcharactersinwindowsbutunixitisknownas
globbingcharactersormetacharacters.
25)#mvoldfoldernamenewfoldername(Torenamefolderorfilename)
26)#mv/root/sameer/cms/home/sameer(Tomovefolderfromone
locationtoanother)
27)#rmfilename
(Todeleteafile)
28)#rmdirdirname (Todeleteanemptyfolder)
29)#rmrfoldername(Todeletesubdirofaparticularfolderwith
interactive)
30)#rmrf

(Toremoveallforcefullyallthecontent)

31)#touchnewfile
(Itwillallowyoutocreatenewemptyfileaswellas
toeventoupdatetimestampofafile)
32)#filefilename

(Torecognizeafiletype)

33)#lessfilename
34)#morefilename

(Toviewafilecontentonly)
(Toviewafilecontentonly)

35)#slocatefilenameorfoldername(Tofindorsearchsomethingona
system)
36)#locatefilenameorfoldername(Tofindorsearchsomethingona
system)
Note:slocateisactualcommandwhichissymlinkto/usr/bin/locate
Note:
37)#mancommand (Helpcommandoflinux)
38)#infocommand (Helpcommandoflinux)
39)#commandhelp (Helpcommandoflinux)
#whatiscommand(Helpcommandoflinux)
40)#switchdeskgnomeorkde(ToswitchbetweenGNOMEand
KDE
GNOME
KDE
desktops)
41)#history
(Toseecurrentcommandhistoryofaterminalwhich
getstoreinafile.bash_historyunderhomedirectory)
Note:!!
(Torepeatlastcommand)

!c
(TorepeatlastcommandthatstartswithC)
!n
(Torepeatacommandbyitsnumberinhistory
output)
!n
(Torepeatacommandenteredncommandback)
41)<ctrl+r>command (Tosearcharepeatedcommand)
42)#find/namefinddataprint&(Tosearchfilesorfoldersina
system)
43)#find.namefinddataprint&(Tosearchfilesorfoldersina
system)
#find/namefinddataprint2>>/dev/null(Tosearchfilesorfoldersin

asystembynormalusersandtosuppressamessageofpermission
deniedweuse2>>)
43)#
44)#which<command>
(Itshowsthefullpathofshellcommands)
#whichclear
(e.g.ofabovedescription)
#whereis<command>(Itshowsthefullpathofacommandalongwith
itsmanpageslocation)
45)#trazAZ</etc/passwd(Ittranslatetheoutputfromlowercaseto
uppercase)
#lsC|trazAZ
46)#tee(Itreadsfromstandardinputandwritetostandardoutputfiles)
#ls|teelogfile
(Thiscommandwilltakeoutputofwho
commandanditwillredirecttologfile(file)
#ls|tee|sortr>/root/logfile
#cat/etc/passwd|sortr|teesam

Note:sortr=itshowstheoutputinreverseorder

Note:Modesofviisasfollows:
Commandmode:
cursormovement
change,delete,yank,put,search
Insertmode:
Typeinnewtext
Returntocommandmodewith<Esc>
Exmode:
Configuring,exitingsaving
Searchandreplace
Enteringintoinsertmode:
aappendafterthecursor
iinsertbeforethecursor
oopenalinebelow
Aappendtoendofline
Iinsertatbeginningofline

Oopenalineabove

<esc>
takesyoufrominsertmodebacktocommandmode
Undoingchanges
uundomostrecentchange
Uundoallchangestothecurrentlinesincethecursorlandedontheline
<ctrlr>redolastundonechange
Searchingfortext
/textsearchdownwardsfortextword
?textsearchupwardsfortextword
n continuesearchinthesamedirection
N continuesearchintheoppositedirection

Savingandexiting:exmode

Exit
Donoexit

Savechanges
:wq,orshiftzz
:w

Abandonchanges
:qor:q!
:e!

Forcingchanges:
Savechanges
:wq!
:w!

Exit
Donotexit

5dd
deletefivelines
x deleteacharacter
r
replaceacharacter(orpressinserttwicetoreplace)
R replacecharacterforcharacteruntilyoupress<esc>
ExtraOptionsofvi:
:r newfile
:!command

(Itispossibletoreadotherfilesintocurrentfile)
(Thiswillappendgivencommand)

:!date
:e/etc/hosts
:setnumber
:senu
<esc><esc>gg
:$
:sh
:wnewfile
name)

(Thisiswillappenddateintocurrentfile)
(Thisiswillopenfileintocurrentlocation)
(Thiswillappendnumberingtoeachline)
(Thiswillappendnumberingtoeachline)
(Itwilltakeyoutostartofthelineincurrentfile)
(Itwilltakeyoutoendofthelineincurrentfile)
(Thiswilltempshutdownvi)
(Thiswillsaveasthiscurrentfileintodifferent

Change,Delete,andYank:

Line
Letter
Word

Change
cc
cl
cw

Delete
dd
dl
dw

Yank(copy)
Yy
Yl
Yw

49)#vimfilename
50)#viRfilename

(Fileisnonmodifiable)
(Fileisonlymodifiablebyusingtheexclamation
point:w!)
51)#vinfilename (Donotuseaswapfileforabackup[usefulfor
floppies])
52)#virfilename
(Recoverdatafromaswapfileafteracrash)
53)#vixfilename (Encryptfilewhensaving,decryptfilewhenediting)
54)#vi+filename
(Itwillopenfileanditwillgotolastlineofthefile)

:BackupUtilities:
55)#tar
(tapearchive)
#tarcvf/root/backup.tar/projects/data/sameer(Tocreateatarfile
Backup)
#tartvf/root/backup.tar(Toviewthecontentofatarfile)
#tarxvf/root/backup.tar(Toextractthetarfilebutbefore
extractionofafileyoushouldbeinto
destinationfolder)
Note:Remembertarcommandnevercompressthedatabutitonly
combinesmultipledataintoonesingletarfile.

56)#compressv/root/backup.tar(Itcompresstarfiletoratioofapprox.
50%60%)
v=verbose
Note:Aftercompressingatarfileitgivesanextensiontothefilei.e.
backup.tar.Z
#zcatbackup.tar.Z(Itreadsacontainofan*tar.Zfile)
backup.tar.Z
#uncompressbackup.tar.Z
#tarZcvf/root/backup.tar.Z/projects/data/sameer
(Tocreateatarfilealongwithcompressutility)
#tarZtvf/root/backup.tar.Z(Toviewthecontentofacompresstar
file)
#tarZxvf/root/backup.tar.Z
(Toextractthecompresstarfilebutbeforeextractionofafileyoushouldbe
intodestinationfolder)

#gzipv/root/backup.tar(Itzipsatarfilewithanextension
.tar.gz)
.tar.gz
#gziplv/root/backup.tar.gz(Toviewthecontentsofan.tar.gzfile)
.tar.gz
#gunzipv/root/backup.tar.gz(Toextractthe.tar.gzfile)
.tar.gz
#tarzcvf/root/backup.tar.gz/projects/data/sameer
(Tocreateatarfilealongwithziputility)
#tarztvf/root/backup.tar.gz(Toviewthecontentofaziptar
file)
#tarzxvf/root/backup.tar.gz
(Toextractaziptarfilebutbeforeextractionofafileyoushouldbe
intodestinationfolder)
#bzip2v/root/backup.tar(Itzipsatarfilewithbzip2utilityan
extension.tar.bz2)
.tar.bz2
#bunzip2v/root/backup.tar.bz2(Toextractthe.tar.bz2file)
.tar.bz2
#tarjcvf/root/backup.tar.bz2/projects/data/sameer
(Tocreateatarfilealongwithbzip2utility)
#tarjtvf/root/backup.tar.bz2(Toviewthecontentsofan.tar.bz2file)
.tar.bz2
#tarjxvf/root/backup.tar.bz2
(Toextractabzip2tarfilebutbeforeextractionofafileyoushouldbe

intodestinationfolder)
#zipv/root/file1(Tozipafilewithhavingextensioni.e.zip)
.zip)
#unzipl/root/file1.zip(Toviewazipfilecontent)
#fileroller(Itsangraphicalutilityforallkindoftaror
zip,compress)
ln(Linkcommand)
Theretwotypeoflinkcanbemadetoafilesorfolder.
Symboliclink :isafilethatpointstoanotherfile.Inbetweentwo
linkfileboththefileseparatelyrepresentsdifferentinodesno.
#lns<filename><filename>
Hardlink
:Onephysicalfileonthefilesystemeachlink
referencesthefilesinode.Fileispresentinthefilesystemsaslongas
atleastonelinkremains.Afterlinkedbetweentwofilesbothfile
representtooneinodenumber.
#ln<filename><filename>

57)#head/etc/passwd (Toshowyoufirsttop10lines(default)inafile)
#headn40/etc/passwd (ToShowyoufirsttop40lines)
58)#tail/etc/passwd (Toshowyoulast10lines(default)inafile)
#tailn20/etc/passwd(Toshowyoulast20lines)
#tailf/var /log/messages
(Toshowautomaticupdatesmadeintothisfile)
#watchtail/var/log/messages
(Toshowautomaticupdatesmadeintothisfile)
59)#wc/etc/passwd(WordCountinafileorintosomeoutput)
#wcl/etc/passwd(Toreadhowmanylinesareavailableinafile)
lines

#wcw/etc/passwd(Toreadhowmanywordsareavailableinafile)
words
#wcc/etc/passwd(Toreadhowmanycharactersareavailableina
file)
#lsal|wcl

60)#sort/etc/passwd(Sortlinesofatextfiles)
#sortr/etc/passwd(sortinareverseorder)
#sortn/etc/passwd(sortinanumericorder)
#tail/etc/passwd|sort(Itwilldisplaylasttenlinewithalphabetical
order)
61)#cutd:f7/etc/passwd|sort|uniq
(Tocuttheoutputofafiled:meansdelimeterorseparatorf7fieldno
7ofafile/etc/passwd)
62)#grepbash/etc/passwd(Tosearchabashwordfromafile)
#lsR|grep.conf
Note:GlobalRegularExpressionPrint(grep)
#lsR|grep.conf|wcl
#lsal|grep^d(Tosearchforonlydirectory)
#dmesg|grepCD
#dmesg|grepicd(Toignorecasewhilesearchingaword)
#cat/etc/init.d/functions|grep\(\)|sort|nl

63)sed(streameditorwhichisusetoreplaceawordwithanotherword)
#seds/bash/nologin/g/etc/passwd|grepnologin
64)

:LinuxFileSystems:
Afilesystemisadatastructurewrittentothemediathatallows
userstostoreandaccessfiles.ThedefaultfilesystemforRedHatLinuxis
theThirdExtendedLinuxFilesystemorext3.RedHatLinuxsupports
over20differentfilesystemtypes.

:AnInode:
Aninodetablecontainsalistofallfilesinanext2orext3filesystem.

Aninode(indexnodes)isanentryinthetable,containinginformation
aboutafile(themetadata),including:
Filetype,permissions,linkcount,UID,GID
Thefilessizeandvarioustimestamps
Pointerstothefilesdatablocksondisk
Otherdataaboutthefile
Ext2andext3filesystemskeepalistoffilesinthefilesystemina
tablecalledaninodetable.
Anindividualentryintheinodetableiscalledaninode.
Theinodeisreferencedbyitsnumber,whichisuniquewithinafile
system.
Aninodemaintainsthefollowingthing:
Thefiletype
Filepermission
Linkcount:thenumberoffilenamesassociatedwiththenodenumber
TheuserIDnumberofthefileowner
ThegroupIDnumberoftheassociatedgroup
Timestamps,includinglastaccesstime,lastmodificationtime,andinode
changetime
Locationofthedataontheharddisk
Othermetadataaboutthefile

Note:Abovepointscambecheckbyexecutinglsalcommandwhich
lsal
showssamethinginasequence.
e.g.:lsali
total28
80788rwrwrw
80788drwrwrw

1
1

root root 5120 sep1111:35 mydata


root root 5120 sep1111:35 myfolder

:Theinodenumberforthemydatafileis80788

:ThesevenFundamentalFiletypes:

d
l
b
c
p
s

regularfile
directory
symboliclink
blockspecialfile
characterspecialfile
namedpipe
socket

:FilesystemStructureofLinux:
Interestingdirectoriesandtheircontents
Directory

Description

Therootdirectorywherethefilesystembegins.Inmostcasestheroot
directoryonlycontainssubdirectories.

/boot

ThisiswheretheLinuxkerneliskept.Itisafilecalledvmlinuz.

/etc

The/etcdirectorycontainstheconfigurationfilesforthesystem.
Mostofthefilesin/etcaretextfiles.Pointsofinterest:
/etc/passwd
Thepasswdfilecontainstheessentialinformationforeach
user.Itisherethatusersaredefined.
/etc/rc.d
Thisdirectorycontainsthescriptsthatgetthesystemstarted.
/etc/sysconfig
RedHatsystemshavethisdirectory.Itcontainsalotofstartup
scriptsandconfigurationfilesforvariousservices.

/bin,/usr/bin

Thesetwodirectoriescontainmostoftheprogramsforthesystem.The
/bindirectoryhastheessentialprogramsthatthesystemrequiresto
operate,while/usr/bincontainsapplicationsforthesystem'susers.

/sbin,/usr/sbin

Thesbindirectoriescontainprogramsforsystemadministration,
mostlyforusebythesuperuser.

/usr

The/usrdirectorycontainsavarietyofthingsthatsupportuser
applications.Somehighlights:
/usr/X11
TheXWindowssystem
/usr/dict
Dictionariesforthespellingchecker.Betyoudidn'tknowthat
Linuxhadaspellingchecker.
/usr/doc
Variousdocumentationfilesinavarietyofformats.
/usr/man
Themanpagesarekepthere.
/usr/src
Sourcecodefiles.Ifyouinstalledthekernelsourcecode
package,youwillfindtheentireLinuxkernelsourcecodehere.

/usr/local

/usr/localanditssubdirectoriesareusedfortheinstallationof

softwareandotherfilesforuseonthelocalmachine.Whatthisreally
meansisthatsoftwarethatisnotpartoftheofficialdistribution(which
usuallygoesin/usr/bin)goeshere.
Whenyoufindinterestingprogramstoinstallonyoursystem,they
shouldbeinstalledinoneofthe/usr/localdirectories.Mostoften,
thedirectoryofchoiceis/usr/local/bin.OnRedHatsystems,the/
usr/localdirectoriesarecreatedbuttheyareempty,readyforyour
use.
/var

The/vardirectorycontainsfilesthatchangeasthesystemisrunning.
Thisincludes:
/var/log
Directorythatcontainslogfiles.Theseareupdatedasthe
systemruns.Youshouldviewthefilesinthisdirectoryfrom
timetotime,tomonitorthehealthofyoursystem.
/var/spool
Thisdirectoryisusedtoholdfilesthatarequeuedforsome
process,suchasmailmessagesandprintjobs.Whenauser's
mailfirstarrivesonthelocalsystem(assumingyouhavelocal
mail),themessagesarefirststoredin/var/spool/mail

/lib

Thesharedlibraries(similartoDLLsinthatotheroperatingsystem)
arekepthere.

/home

/homeiswhereuserskeeptheirpersonalwork.Ingeneral,thisisthe

onlyplaceusersareallowedtowritefiles.Thiskeepsthingsniceand
clean:)
/root

Thisisthesuperuser'shomedirectory.

/tmp

/tmpisadirectoryinwhichprogramscanwritetheirtemporaryfiles.

/dev

The/devdirectoryisaspecialdirectory,sinceitdoesnotreally
containfilesintheusualsense.Rather,itcontainsdevicesthatare
availabletothesystem.InLinux(likeUnix),devicesaretreatedlike
files.Youcanreadandwritedevicesasthoughtheywerefiles.For
example/dev/fd0isthefirstfloppydiskdrive,/dev/hdaisthefirst
IDEharddrive.Allthedevicesthatthekernelunderstandsare
representedhere.

/proc

The/procdirectoryisalsospecial.Thisdirectorydoesnotcontain
files.Infact,thisdirectorydoesnotreallyexistatall.Itisentirely
virtual.The/procdirectorycontainslittlepeepholesintothekernel
itself.Thereareagroupofnumberedentriesinthisdirectorythat
correspondtoalltheprocessesrunningonthesystem.Inaddition,
thereareanumberofnamedentriesthatpermitaccesstothecurrent
configurationofthesystem.Manyoftheseentriescanbeviewed.Try
viewing/proc/cpuinfo.Thisentrywilltellyouwhatthekernel
thinksofyourCPU.

/mnt

Finally,wecometo/mnt,anormaldirectorywhichisusedinaspecial
way.The/mntdirectoryisusedformountpoints.Aswelearnedinthe,
thedifferentphysicalstoragedevices(likeharddiskdrives)are
attachedtothefilesystemtreeinvariousplaces.Thisprocessof
attachingadevicetothetreeiscalledmounting.Foradevicetobe
available,itmustfirstbemounted.
Whenyoursystemboots,itreadsalistofmountinginstructionsinthe
file/etc/fstab,whichdescribeswhichdeviceismountedatwhich
mountpointinthedirectorytree.Thistakescareoftheharddrives,but
youmayalsohavedevicesthatareconsideredtemporary,suchasCD
ROMsandfloppydisks.Sincetheseareremovable,theydonotstay
mountedallthetime.The/mntdirectoryprovidesaconvenientplace
formountingthesetemporarydevices.Inanormalinstallation,you
willseethedirectories/mnt/floppyand/mnt/cdrom.Toseewhat
devicesandmountpointsareused

55)#
56)dfhT(Reportdiskspaceusage)
h displayssizesineasiertoreadunits
T displayswhichfilesystemisusedbyparticularfilesystem
hHumanreadablemeansinMBorKBorGB
57)duh/data(Reportsdiskspaceusageusedperdirectory)
:FormattingaFloppy:
Twotypesofformatneededtoprepareafloppy
Alowlevelformat(rarelyneeded)
fdformat
/dev/fd0F1440
Afilesystem,oneof
mkfstext2/dev/fd0
mke2fs/dev/fd0

mkfstvfat/dev/fd0
mformata:
74)#aliascls=clear(thisiswillcreatealiastempbutifyouwant
permanent
thenwriteinusershomedirectoryin.bashrcfiletoremainlastevenif
userloggedout)
75)#su
(ifausernameisnotsupplied,thesucommandassumes
that
youwishtobecomeroot.)
76)#su
(ifausernameisnotsupplied,andifyoutypedashafter
su
commandthenassumesthatyouwishtobecomerootand
youwantopenanewshellafterlogin.)
77)#suusername(tochangeidentityortoswitchidentity)
78)#suusername(tochangeidentityortoswitchidentitywithavailable
withnewshellafterlogin)
79)#who
(tofindoutwhoisloggedin)
80)#users
(
)
81)#w
(
82)#groups
(tofindoutwhatgroupsyoubelongto)
83)#id
(tofindoutgroupid,userid)
84)#last
(whohasloggedinasystemlast,orwhohas
rebooted
systemlasttime)
85)#whoami
(tofindoutwhoyouare)
86)#umask
(tocheckdefaultpermission)
umaskvalueissetfornormalusersis0002
umaskvalueisserforrootuseris0022
Withoutumaskineffecttheumaskvalueforfilesitis
666and
umask
666

forfoldersitis777
Umaskvaluecanbesetperindividualuserbysettingumaskin
eachusershomedirectorysthereisafilecalledas.bashrc,
whichwillbereadonlyoncewhenusersloggedintosystem

Ifyouwantchangeumaskvaluegloballytoalluserssoyouhave
setthisvaluein
Umaskvalueiscalculatedforrootandnormalusersis
666
777
002002
664
775
87)#newgrpothergroup(Whereothergroupisoneoftheuserssecondary
groups)

Vous aimerez peut-être aussi