NAS Ebook

Page 1


Introductionto Linux(RHEL8)

LinuxHistoryandBasics

1.InitialRelease:LinusTorvaldsreleasedthefirstLinuxkernel(0.02) inOctober1991.Currentversion:2.6(major-minor-release).

2.Versioning:Evenminorversions(2.6)indicatestablereleases, whileoddversions(2.5)signifydevelopmentreleases.

LinuxBootSequence

1.Hardwareinitialization

2.Kernelloading

3.GUI(Gnome3/KDE)+shell(CLI)

ShellBasics

1.Shelltypes:Bourne(sh),Bash(bash),Korn(ksh),C(csh),Z(zsh)

2.Defaultshell:Bash

3.Promptformat:username@machinename:currentdirectory(# forroot,$forusers) CommandStructure

1.Commandname 2.Options(-/+)

3.Arguments

BasicLinuxCommands

#cal:Displaycalendar(e.g.,cal2020)

#who:Displayloggedusers

#whoami:Displaycurrentloggeduser

#mkdir:Createdirectory(e.g.,mkdirtest)

#date:Displaydate/time

#date+%x:10/03/2021

#date+%R:08:20

#date+%r:08:14:30AM

#date:Customformat:date+"nowis%A,%B%d,%y,%nitis%r"

#su:Switchuser(e.g.,su,suahmed)

#history:Displaylastcommands

#!!:Repeatlastcommand

#!32or!date:Executespecificcommands

#clear:Clearscreen

#passwd:Changepassword

#uptime:Displaysystemrunningtime

#du-hs/etc:Aggregatesizesofobjectswithin/etc

FileTypes

Ordinaryfiles(txt,jpg…..) (ls-l -)

1. Configurationfiles(/etc/passwd containsusrinfo) (/etc/shadowcontainencryptedpasswords)(-) 2. Devicefiles(/dev)(blockdevfile(harddesk),chardevfile( serialinterfaceRS232)(corb) 3. Directoryfile(containsinfoaboutinsidefiles) (d) 4. Linkfiles(symboliclink/softlink) (l) 5. Namedpipe 6 Socketfile 7.

FileTypeContents:

Static

Dynamicorvariable modifiedorappendedbyactiveprocess)

Persistent configurationremainsafterreboot)

Runtime systemspecificcontentsthatclearedduringreboot)

FileSystem

/ slashorrootdirectory

/root homedirectoryofrootuser

/home homedirs.Ofallusersexceptroot

/home/Mohamedhomedir.OfMohameduser

/home/sara homedirofsarauser

/etc alldifferentconfigurationfiles

/usr/bin normalcommands(executablefiles,binaryfiles)

/usr/sbin systemadmincommands

/bin,/sbin linkto/usr/bin,/usr/sbin

/dev devicefiles(driversfiles)

/media,/mntmounteddevices(cdorusb)

/var,/srv variablefiles(DB,ftp,web,log….)

/boot bootingfiles(bootloader(grub)runkernel)

/opt applicationsfiles

/proc infoaboutsystem

/tmp removedafter10days

/var/tmp removedafter30days(/usr/tmplinkedto/var/tmp)

/run runtimefilesforprocesses(processedIDandlockfiles)

Paths:absolutepathsstartwith/, relativepaths(dependonyour currentlocation)

#cdchangedirectorytohomedir

#cd-lastdir

#pwdprintworkingdir

#cd..stepup

#cd/home/studentmovetothisdir

#cd~alihomedirofuser

#filedeterminefiletype

#file/etc/passwd

#file/home

#file/dev/sda1

#file/bin/passwd

#cat/etc/passwdtextviewer

#cat-b/etc/passwdaddlinenumber

#head/etc/passwdview10lines(head)

#tail-n2/etc/passwdviewlasttwolines(or-2)

#tail-n+2/etc/passwdfromline2toend(or+2)

#tail-f/var/log/messagesfollowtheendoffile

#less/etc/passwdviewer(linebylineorpage)andcansearch (/,nnext,Nprevious)qforexit

#morenearlysamelikeless(notclearthescreenafterexit,

thefile

Filenamerules:upto255char.,connotuse(*,$,&,”,#)

#wc-l-w-c/etc/passwdcountlines,characters,wordsoftext files

#mkdircreatenewdir

#mkdir-p/dir1/dir2/dir3(pparent)

#rmdirremoveemptydir

#cpsourcedestinationcopyfiles/direct(-roption)

#mvsourcedestinationcut/movefile/dir(-roption)

#rm-rargumentdeletefiles/dir(-roption)

#rm-i/test/testinteractiveconfirmation

#\rmpreventaliase

#rm-rffwillnotpromptforconfirmation

#aliasviewaliaes

#aliasmm=”ls-l”

#unaliasmm

lab:createtwodiron/(dir1,dir2),touchabc,alfa,beta,d123indir1 copyabcalfatodir2 movebeta,d123todir2 renamed123to123 removeabcfromdir2

Help

1.

#whatispasswd (#makewhatis)

man commandname (in/usr/share/man) 2.

man-kkeyword (mustrun#mandbfirst)searchontitleand description

1pinfocommandname . 2sharedocuments(/usr/share/doc) .

3internetsites .

#ls -a all

#ls -d directory

#ls-l longlisting(includehardlinkcounts)

#ls -R recursive

#ls-s listsizeinblocks(block=512B)

#ls -r reverse

#ls-t sortbylastmodificationtime(-ltrreverse)

#ls-F (/dir,*exec,@symbolic,noneplaintext)

#ls-ullastaccesstimeinsteadoflastmodification(catorlesson files)

#ls-n uid&gidoffiles

#dircmpdisplayuniquefilesineachdir&commonfiles

#dircmp-s-ddir1dir2(ssuppressidenticalfiles,ddifference operationbetweentwofiles)

#echo“testfile“>/dir1/link

#lnfilehardlink-file

#ln-sfilesoftlink-file

#ls-il/showinodenumberoffiles,hardlinkedfileshavethesame inode

#dflistfilesystems(-bfreespace,-tusedblocksandtotal)

######hardlinkcountfieldindirectoriesindicatenumberof directoriesinside

#whichnanoexecutablefilelocation

#whereispasswdexecutablefile,manual,configurationfiles locations

##lab

Createhiddenfilenamed.filein/dir2

Listallfilesin/dir2

Createsoftlinknamed/softin/to/dir1/link

Createhardlink/hardto/dir1/link

Viewhardlinkcountof/hard&/dir1/link

Removeonelinkandcheckhardlinkcount

Bashexpansion

PatternMatching

-lsb*-zeroormorecharacters

-lsb??-listfilesstartingwith"b"andendingwithanytwo characters

-ls[abc]??-listfilesstartingwith"a","b",or"c"andendingwith anytwocharacters

-ls[!abc]??-listfilesnotstartingwith"a","b",or"c"andending withanytwocharacters([^abc])

-ls[[:alpha:]]-startwithanyalphabeticcharacter

-ls[[:digit:]]-startwithanynumber(0-9)

-ls[[:upper:]]*

-ls[[:lower:]]*

BraceExpansion

-touch{alfa,b,c,d,1,2}.log -echofile{a{1,2,3},b,c}.txt

CommandSubstitution

-echo"todayis$(date+%x)"

-echo"linenumbersofpasswordfileare`wc-l/etc/passwd"

HomeDirectoryExpansion

-cd~user-user'shomedirectory -ls~/mm

VariableSubstitution

-echo"executablepathsare$PATH"

PreventingExpansion

-\beforethepattern -\*,\?,"*"-preventsomeexpansions

''-preventallexpansions

Redirection

->file-overwrite

->>file-appendmode

-2>file-redirectstandarderror

-2>/dev/null-discardstandarderror

-&>file-redirectbothoutputanderror

-&>>file-appendbothoutputanderror

Piping

-|-passoutputasinputtoanothercommand

-tee-takesnapshotofoutputandsendcopytonextcommand

Tasks

-Countfiles:ls-R|wc-l

-Redirecterror/output:ls//zxy2>/err>/out

-Countfiles/sizes:ls-l|wc-l>/count;du-sh/etc>>/count;date +%x>>/count

TextfileEditing

1.nano

2.vim (vi ->vim)

speed,mostunix/linux,difficult searchasless(/dogsearchdown,?dogsearchupword) searchandreplaceassed(:%s/dog/cat/g alllines) 4modes

Commandmode(yycopyline,ppaste,ddcutline,uundolast changeUlastchangesontheline,ctrl+rredo,wmoveword……..,: extendedmode,Iinsertmode)

Insertmode (editmode)(A-appendendofline,I-appendbegin oflight,o–insertnewline)

Extendedmode(wq saveandquit,q! quitwithoutsave,w save, searchandreplace)

Visualmode(v,Vlines,^vblocks)selectmultiple 3.gedit

4.streameditor(sed)

##sed‘s/cat/dog/’file #onechangeinline

##sed‘s/cat/dog/gi’file#global(multiplechangeinline)case insensitive

##sed‘1,50s/cat/dog/g’file

##sed-e‘s/cat/dog/g’-e‘s/cow/goat/g’file

Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.