1 CSE 391 Lecture 1 introduction to Linux/Unix environment slides created by Marty Stepp, modified by Jessica Miller, Ruth Anderson, and Brett Wortzman http://www.cs.washington.edu/391/
1
CSE 391Lecture 1
introductiontoLinux/Unixenvironment
slidescreatedbyMartyStepp,modifiedbyJessicaMiller,RuthAnderson,andBrettWortzmanhttp://www.cs.washington.edu/391/
3
Lecture summary• Courseintroductionandsyllabus
• UnixandLinuxoperatingsystem
• IntroductiontoBashshell
6
Course Introduction• Website:http://cs.washington.edu/391
§ CollectionoftoolsandtopicsnotspecificallyaddressedinothercoursesthatCSEmajors(andinterestedothers)shouldknow§ CSE351maybethefirstcourseyoutakethatusesLinux
§ Credit/NoCreditcourse,determined byweeklyassignments§ Gradedprimarilyoneffort/completion
§ “Textbook” – LinuxPocketGuide§ Optionalbutrecommended; veryusefulguide
7
Course Topics• Linuxcommandlineinterface(CLI)• Shellcommands• Usersandgroups• Permissions• Shellscripting• Regularexpressions• Projectmanagementtools(e.g.makefiles)• Versioncontrol(e.g.git)
8
Homework/Grading• ~Nineweeklyassignments
§ Releasedafterlecture§ DuefollowingTuesday,1:00pm(nolateworkaccepted)
• Basedonmaterialcovered inthatweek’s lecture§ Afew“self-discovery” extensions§ Allrequired informationinlecture,slides,book,and/ormanpages
• Gradedoutof2pointseach§ Primarilydetermined byeffort/completion (seesyllabus)§ Totalof14pointsrequired toreceive creditforthecourse
• TobecompletedonLinux/Unixsystems(nextslide)• Collaborationallowed/encouraged, butALLSUBMITTEDWORKMUSTBEYOUROWN
9
Accessing Linux/UnixRoughlyinsuggestedorder…•ssh toattu (CSEmajors),linuxNN (EEmajors),orovid (allUWstudents)
• Download/runCSEVM• VisitCSorEEbasement labs• SetupLinuxonyourownmachine
• See“WorkingatHome”oncoursewebsiteformoreinfo
11
Operating systems• operatingsystem:Managesactivitiesandresourcesofacomputer.
§ softwarethatactsasaninterfacebetweenhardwareanduser§ providesalayerofabstractionforapplicationdevelopers
• featuresprovidedbyanoperatingsystem:§ abilitytoexecuteprograms (andmulti-tasking)§ memorymanagement (andvirtualmemory)§ filesystems,diskandnetworkaccess§ aninterfacetocommunicatewithhardware§ auserinterface (oftengraphical)
• kernel:Thelowest-levelcoreofanoperatingsystem.
12
Unix• briefhistory:
§ Multics(1964)formainframes§ Unix(1969)§ K&R§ LinusTorvaldsandLinux(1992)
• keyUnixideas:§ writteninahigh-level language(C)§ virtualmemory§ hierarchicalfilesystem; "everything" isafile§ lotsofsmallprogramsthatworktogethertosolvelargerproblems§ security,users,access,andgroups§ human-readabledocumentation included
13
Linux• Linux:Akernel foraUnix-likeoperatingsystem.
§ commonly seen/usedtodayinservers,mobile/embedded devices,...
• GNU:A"freesoftware"implementation ofmanyUnix-liketools§ manyGNUtoolsaredistributedwiththeLinuxkernel
• distribution: Apre-packagedsetofLinuxsoftware.§ examples:Ubuntu,Fedora,CentOS
• keyfeaturesofLinux:§ opensourcesoftware:sourcecanbedownloaded§ freetouse§ constantlybeingimproved/updatedbythecommunity
14
Linux Desktop• X-windows• windowmanagers• desktopenvironments
§ Gnome§ KDE
• HowcanItryoutLinux?§ CSEVirtualmachine§ CSEbasementlabs§ attu sharedserver
15
Things you can do in Linux• Loadthecoursewebsiteinabrowser
• Installandplaygames
• PlayMP3s
• Editphotos
• IM,Skype
16
Shell• shell:Aninteractiveprogramthatusesuserinputtomanagetheexecutionofotherprograms.§ Acommandprocessor,typicallyrunsinatextwindow.§ Usertypescommands,theshellrunsthecommands§ Severaldifferentshellprogramsexist:
•bash :thedefaultshellprogramonmostLinux/Unixsystems• Wewillusebash• Othershells:Bourne,csh,tsch
• WhyshouldIlearntouseashellwhenGUIsexist?
17
Why use a shell?• WhyshouldIlearntouseashellwhenGUIsexist?
§ faster§ workremotely§ programmable§ customizable§ repeatable
18
Example shell commands
$ pwd/homes/iws/rea$ cd CSE391$ lsfile1.txt file2.txt$ ls –l-rw-r--r-- 1 rea fac_cs 0 2017-03-29 17:45 file1.txt-rw-r--r-- 1 rea fac_cs 0 2017-03-29 17:45 file2.txt$ cd ..$ man ls$ exit
command descriptionpwd printthecurrentworkingdirectorycd changestheworkingdirectoryls listsfilesinadirectoryman bringsupthemanualforacommandexit logsoutoftheshell
19
System commands
• "manpages"areaveryimportantwaytolearnnewcommandsman lsman man
command descriptionman or info gethelponacommandclear clearsouttheoutputfromtheconsoleexit exitsandlogsoutoftheshelldate outputthesystemdatecal outputatextcalendaruname printinformationaboutthecurrentsystem
20
Relative directoriesdirectory description
. thedirectoryyouarein("workingdirectory")
.. theparentoftheworkingdirectory(../.. isgrandparent,etc.)
~ yourhome directory(onmanysystems,thisis/home/username )
~username username'shome directory
~/Desktop yourdesktop
21
Unix file systemdirectory description
/ rootdirectorythatcontainsallothers(drivesdonothavelettersinUnix)
/bin programs/dev hardwaredevices/etc systemconfigurationfiles
§ /etc/passwd storesuserinfo§ /etc/shadow storespasswords
/home users'homedirectories/media,/mnt,...
drivesandremovabledisksthathavebeen"mounted"foruseonthiscomputer
/proc currentlyrunningprocesses(programs)/tmp, /var temporaryfiles/usr user-installedprograms
22
Directory commands
• somecommands(cd,exit)arepartoftheshell("builtins")• others(ls,mkdir)areseparateprogramstheshellruns
command descriptionls listfilesinadirectorypwd printthecurrentworkingdirectorycd changestheworkingdirectorymkdir createanewdirectoryrmdir deleteadirectory(mustbeempty)
23
Command-line arguments• manyacceptarguments orparameters
§ example:cp (copy)acceptsasourceanddestinationfilepath
• aprogramuses3streamsofinformation:§ stdin,stdout,stderr(standardin,out,error)
• input:comesfromuser'skeyboard• output:goestoconsole• errors canalsobeprinted (bydefault,senttoconsolelikeoutput)
• parametersvs.input§ parameters: beforeEnterispressed;sentinbyshell§ input: afterEnterispressed;sentinbyuser
24
Command-line arguments• mostoptionsarea- followedbyalettersuchas-c
§ somearelongerwordsprecededbytwo- signs,suchas--count
• optionscanbecombined:ls -l -a -r canbels -lar
• manyprogramsaccepta--help or-help optiontogivemoreinformationaboutthatcommand(inadditiontoman pages)§ orifyouruntheprogramwithnoarguments, itmayprinthelpinfo
• formanycommandsthatacceptafilenameargument, ifyouomittheparameter, itwillreadfromstandardinput(yourkeyboard)
25
File commands
• caution:theabovecommandsdonotpromptforconfirmation§ easytooverwrite/delete afile; thissettingcanbeoverridden (how?)
• Exercise:Givenseveralalbumsof.mp3 filesallinonefolder,movethemintoseparatefoldersbyartist.
• Exercise:Modifya .java file tomakeitseemasthoughyoufinishedwritingitonDec28at4:56am.
command descriptioncp copyafilemv moveorrenameafilerm deleteafiletouch createanewemptyfile,or
updateitslast-modifiedtimestamp
26
Exercise Solutions • caution:thecp,rm,mvcommandsdonotpromptforconfirmation
§ easytooverwrite/delete afile; thissettingcanbeoverridden (how?)• Use“-i”withthecommand,“interactive”topromptbeforeoverwrite
• Exercise:Givenseveralalbumsof.mp3 filesallinonefolder,movethemintoseparatefoldersbyartist.§ mkdir U2§ mkdir PSY§ mkdir JustinBieber § mv GangnamStyle.mp3 PSY/§ mv Pride.mp3 U2/
• Exercise:Modifya .java file tomakeitseemasthoughyoufinishedwritingitonDec28at4:56am.§ touch –t "201812280456" Hello.java
27
Text editors
• youcannotrungraphicalprogramswhenconnectedtoattu (yet)§ soifyouwanttoeditdocuments,youneedtouseatext-onlyeditor
• mostadvancedUnix/Linux userslearnemacs orvi§ Iwouldrecommendyoutrytopickupthebasicsofoneofthese.§ Yourchoice!
command descriptionpico or nano simpleeditorsemacs Moreadvancedtexteditorvi or vim Moreadvancedtexteditor
28
Basic Emacs Commands• C- =controlkey M- =meta/altkey• readafileintoEmacs: C-xC-f• saveafilebacktodisk: C-xC-s• exitEmacs permanently: C-xC-c• searchforward: C-s searchbackward: C-r• scrolltonextscreen: C-v scrolltopreviousscreen: M-v• Undo: C-xu
entitytomoveover backward forward
character C-b C-f
word M-b M-f
line C-p C-n
gotolinebeginning/end C-a C-e
gotobufferbeginning/end M-< M->
https://courses.cs.washington.edu/courses/cse391/18sp/handouts/emacs.pdf
29
Basic Vim Commands• :w Writethecurrentfile• :wq Writethecurrentfileandexit.• :q!Quitwithoutwriting• Tochangeintoinsertmode:i ora
§ Useescape toexit• searchforward/,repeatthesearchbackwards:N• Basicmovement:
§ hlkj character left,right;lineup,down(alsoarrowkeys)§ bw word/tokenleft,right§ ge e endofword/tokenleft,right§ 0$ jumptofirst/lastcharacterontheline
• x delete• u undo
https://wiki.gentoo.org/wiki/Vim/Guide and http://tnerual.eriogerg.free.fr/vimqrc.pdf