You are on page 1of 33

TutorialonLinux Basics

KARUNYALINUXCLUB www.karunya.edu/linuxclub

Outline
1. 2. 3. 4. 5. 6. 7. 8.

OverviewofLinuxSystem BasicCommands Relative&AbsolutePath Redirect,AppendandPipe Permission ProcessManagement InstallSoftware TextEditor

OverviewofLinuxSystem
Kernel&Shell

Linuxisoperatingsystem(OS). Linuxsystemisdescribedaskernel& shell. KernelisamainprogramofLinux system.Itcontrolshardwares,CPU, memory,harddisk,networkcardetc. Shellisaninterfacebetweenuserand kernel.Shellinterpretsyourinputas commandsandpassthemtokernel.

User
input

Shell Kernel

LinuxOverview(cont.)
Multiuser&Multiprocess Manypeoplecanuseonemachineatthesame time. File&Process Data,directory,process,harddisketc(almost everything)areexpressedasafile. Processisanrunningprogramidentifiedbya uniqueid(PID).

LinuxOverview(cont.)
DirectoryStructure

Filesareputinadirectory. Alldirectoriesareinahierarchicalstructure(tree structure). Usercanputandremoveanydirectoriesonthe tree. Topdirectoryis/,whichiscalledslashorroot. Usershavetheowndirectory.(homedirectory)

LinuxOverview(cont.)
DirectoryStructure

LinuxOverview(cont.)
ImportantDirectories

/binThiscontainsfilesthatareessentialforcorrect operationofthesystem.Theseareavailablefor usebyallusers. /mntProvidesalocationformountingdevices,suchas remotefilesystemsandremovablemedia /homeThisiswhereuserhomedirectoriesarestored. /var Thisdirectoryisusedtostorefileswhichchange frequently,andmustbeavailabletobewrittento. /etc Varioussystemconfigurationfilesarestoredhere.

LinuxOverview(cont.)
ImportantDirectories

/dev Thiscontainsvariousdevicesasfiles,e.g.hard disk,CDROMdrive,etc. /rootThisistheroot(administrator)user'shome directory /sbin Binarieswhichareonlyexpectedtobeusedby thesuperuser. /tmpTemporaryfiles. /bootHasthebootableLinuxkernelandboot loaderconfigurationfiles(GRUB) /usrContainsuserdocumentation,games,graphical files,libraries(lib),etc..

LinuxOverview(cont.)
NormaluserandSuperuser InLinuxsystem,thereisonespecialuserforadministrator, whichcandoanything. Thisspecialuseriscalledrootorsuperuser. CaseSensitivity LinuxlikeUNIXiscasesensitive. MYFILE.doc,Myfile.doc,mYfiLe.Docaredifferent. OnlineManual Linuxhaswellwrittenonlinemanuals.

BasicCommands
Howtoruncommands

WhenyoulogonLinuxmachine,youwillsee,

[cswug@hyperion001cswug]$

Onecommandconsistsofthreeparts,i.e.commandname, options,arguments.

Example)

[cswug~]$commandnameoptionAoptionBargument1argument2

BasicCommands
Howtoruncommands

Betweencommandname,optionsandarguments,spaceis necessary. Opitionsalwaysstartwith

Example) cd.. lsl.bashrc mvfileAfileB

BasicCommands
Commands

ls showfilesincurrentposition cd changedirectory cp copyfileordirectory mv movefileordirectory rm removefileordirectory pwd showcurrentposition mkdir createdirectory rmdir removedirectory catdisplayfilecontents less displayfilecontentspagewise man displayonlinemanual

BasicCommands
Commands

su switchuser passwd changepassword useradd createnewuseraccount userdel deleteuseraccount mount mountfilesystem umount unmountfilesystem df showdiskspaceusage shutdown rebootorturnoffmachine

PracticeBasicCommands
1.Typefollowingcommandin yourdirectory.
ls lsa lsla lsFa

3.Inyourhomedirectory,

ls.bash_profile cp.bash_profilesample.txt lesssample.txt(note:toquitless,pressq) rmsample.txt

2.Makeadirectory mkdirlinux pwd cdlinux pwd cd pwd rmdirlinux

4.Trytochangeyourpassword,
passwdusername (Typecurrentpasswordonce,then typenewpasswordtwice.Youdonthaveto changepasswordhere.Justapractice)

5.checkdiskspaceusage
df dfh

Relative&AbsolutePath

Pathmeansapositioninthedirectorytree. Toexpressapath,youcanuserelativepath orabsolutepath. Inrelativepathexpression,thepathisnot defineduniquely,dependsonyourcurrent path. Inabsolutepathexpression,thepathis defineduniquely,doesnotdependonyour currentpath.

Relative&AbsolutePath

Charactersusedin relativepath .currentdirectory ..parentdirectory

Absolutepathstartswith/ Example) cd/home/user01 /home/root/a.out

Example) cd.. ./a.out

Relative&AbsolutePath
Userelativepath. Inhomedirectory,type pwd cd. pwd cd.. pwd cd.. pwd cd

Useabsolutepath. Inhomedirectory,type pwd cd/home/cswug pwd cd/home pwd cd/ pwd cd/home/cswug

Redirect,AppendandPipe
Redirectandappend

Outputofcommandisdisplayedonscreen. Using>,youcanredirecttheoutputfromscreentoafile. Using>>youcanappendtheoutputtothebottomofthefile.

Pipe

Somecommandsrequireinputfromafileorothercommands. Using|,youcanuseoutputfromothercommandasinputtothe command.

Redirect,AppendandPipe
Commands

head tail

showfirstseverallinesandomitotherlines. showlastseverallinesandomit otherlines. showlinesmatchingapattern

grep

Redirect,AppendandPipe

Inhomedirectory,type ls.bash_profile cp.bash_profilesample.txt lesssample.txt Useredirect. head3sample.txt head3sample.txt>redirect.txt Useappend. tail3sample.txt tail3sample.txt>>redirect.txt lessredirect.txt

Usepipe. lessredirect.txt grepPATHredirect.txt tailredirect.txt|grepPATH rmsample.txt rmredirect.txt

Permission

Alloffilesanddirectorieshaveownerandpermission. Therearethreetypesofpermission,readable, writeableandexecutable. Permissionsaregiventothreekindsofgroup.owner, groupmemberandothers.

Example) [cswug@hyperion001cswug]$lsl.bash_profile r:

rwrr1cswugcswug191Jan413:11.bash_profile

readable,w:writable,x:executable

Permission
Command

chmod changefilemode,addorremove permission chown changeownerofthefile

Example) chmoda+wfilename addwritablepermissiontoallusers chmodoxfilename removeexecutablepermissionfromothers

u:user(owner), g:group, o:others a:all

Permission

Checkpermission lsl.bash_profile cp.bash_profilesample.txt lslsample.txt Removereadablepermissionfromall. chmodarsample.txt lslsample.txt lesssample.txt Addreadable&writablepremissionstofileowner. chmodu+rwsample.txt lslsample.txt lesssample.txt rmsample.txt

ProcessManagement

Processisaunitofrunningprogram. Eachprocesshassomeinformations,likeprocessID,owner, priority,etc.

Example) Output of top command

ProcessManagement
Commands kill Sendsspecifiedsignaltospecified process.Thisprocessisspecifiedby processID. killall Stopaprogram.Theprogramis specifiedbycommandname. ps Showprocessstatus top Showsystemusagestatistics

ProcessManagement

Checkyourprocess.
ps psu

Checkprocessofallusers. top(Toquittop,pressq)
pse psef

Findyourprocess.

psef|grepcswug

InstallSoftware

Linux system has a de facto standard way to install a software. configure, make & make install Typical software installation procedure as following.
1. 2. 3.

Download source code. Usually, it s archived with tar command and compressed with gzip command. configure command creates Makefile automatically which is used to compile the source. Program compilation is written in Makefile.

InstallSoftware
Commands

gzip gunzip tar configure make

compress a file uncompress a file archive or expand files create Makefile compile & install software

InstallSoftware
Example)parallelprogramminglibraryinstallation Executingcommandslinebyline:
tarxvfzmpich.tar.gz cdmpich1.2.5.2 ./configureprefix=/usr/localrsh=ssh make makeinstall

TextEditor

Programs & configuration files are text file. There are two popular text editors, vi and Emacs. Very powerful and useful.

TextEditor
WritehelloworldprograminC(assumingGCCisinstalledon yourLinuxsystem). Typevihello.c[whereviiseditornameandhello.cisfilename] PressIforinsertingandtypetehello.casfollows. #include<stdio.h> intmain(void){ printf(HelloWorld\n); } AfterfinishingtypingsavethefilebypressingESC buttonandthentypingcolonfollowedbywqasfollows: :wq[wtosaveandqtoquit] Compile gcchello.c Run ./a.out

TextEditor

Weopenthevieditorforediting/writingafileusingvicommand as:vifilename[wherefilenameisthenameofthefileused] PressIforinserting(iefortypingintheeditor),ifany. Aftertyping,pressESCfollowedby(eitherofthefollowing) :q[toquitsimply] :wq[tosaveandquit] :q![toforcequitwithoutsaving]

TutorialofLinux
E N D

You might also like