“introduction to unix/linux” inx s17, day 2,...
TRANSCRIPT
“Introduction to Unix/Linux” INX_S17, Day 2, 2017-04-05
shell(s),prompt,setenv,echo,quoting,filesystem,paths,pwd,cd,ls
LearningOutcome(s):NavigateandusetheUnix/Linuxfilesystem,includingunderstandingdirectorystructure
MatthewPeterson,OSUCGRB,[email protected];containscopyrightedmaterials.
Commandprompt
http://teaching.cgrb.oregonstate.edu/CGRB/oneil/primer/partI_3_the_command_line_and_filesystem.html
1
echo
• “displayalineoftext”• Example:
echo hello!
https://commons.wikimedia.org/wiki/File:Animal_echolocation.svg2
EnvironmentVariables• Bitsofinformation(preferences)storedyourshell• Canbeusedbyyouorbyotherprograms• Variablesstartwitha$ sign
echo $USER
echo $0
• Listofallthecurrentenvironmentvariablessetforyourshell?
3
“Kernel,”“Shell,”“Applications”
4
Hardware
Kernel
System Call Interface
Unix Commands and LibrariesShell
Shell:bash“itisadefaultshellonthemajorLinuxdistributionsandOSX.”https://en.wikipedia.org/wiki/Bash_(Unix_shell)
MacOSX switchedfromtcsh beingitsdefaultshelltobash inapproximately2003.
6
Shell:bash
bashecho $0
exit
echo $0
Howfarcanyougodowntherabbithole?...
https://commons.wikimedia.org/wiki/File:Russian_Dolls.jpg Photo:LachlanFearnley7
SettingEnvironmentVariablessetenv <var name> <value>
setenv greeting hellosetenv greeting hello class
setenv greeting 'hello class'setenv greeting "hello $USER"
Whathappensforeach?echo $greeting
8
Quotes
•Usedto“groupup”words,suchthattheyareasingle‘parameter’(value)•Canbeusedto“escape”specialcharacters,e.g.,spaces''•Examplenot usingquotesforaspace:
echo $greeting9
Quotes:single' anddouble"• Singlequotes''donot expandthecontentsofvariablesinsidethem• Doublequotes"" do expandthecontentsofvariablesinsidethem
setenv greeting
echo $greeting
setenv greeting
echo $greeting10
LinuxFilesystem
14
http://teaching.cgrb.oregonstate.edu/CGRB/oneil/primer/partI_3_the_command_line_and_filesystem.html
AbsolutePathto“music”?
17
/
mnt
zipmusic
http://faithandtech.nccumc.net/a-techies-advent-devotional/
cd ChangeDirectory
• Tomovearoundthefilesystem(“tree”)wecanusethecommand:cd• Thisallowsustomove“up”,“down”,andjumpallaroundthefilesystem
20
GoingbacktoyourHomeDirectoryThereareseveralwaystogetbacktoyourhomedirectory:
#Ifyouknowtheabsolutepath,typeitin:cd
cdcdcd
21
https://commons.wikimedia.org/wiki/File:Home_Icon.svg
Feelinglost?
There’snoplacelike$HOME
22https://commons.wikimedia.org/wiki/File:Ruby_slippers.JPGAttribution (CC BY-SA 3.0): https://en.wikipedia.org/wiki/User:RadioFan
ls Listingfilesanddirectories• ListfilesanddirectoriesinyourPWD/CWD(“whereIamlocatedrightnowinthefilesystem tree”)•Runningls aftercd isagoodwaytofamiliarizeyourselfwiththefilesystem• Intheshelldirectoriesaredenotedby:•BLUE highlightingofthename•
23
ls Listing“hidden”(“dot”files)ls –a
•Configurationfilesoftenstartwitha:.• There’snoreasonyouneedtoseethemonadailybasiswhenworking (buttheyarethere).
24
ls -l Longformatls –l
•Wewillgointodetailwhatalloftheseindividualfieldsmean(andhowtomanipulatethem)inalaterclass.•Bydefaultitshowsfilesizesinbytes•Onebyteisapproximately 1“character”,e.g.,xor 5or @
25
ls -h“humanreadable”ls –l -h
• The-hoptionisusedwith–l• Showsfilesizesnotedby:• K (kilobytes)•M (megabytes)• G (gigabytes)• T (terabytes)
26
ls “consolidation”ofargumentsls –l –h -a
Canbewrittenalsoas:
ls –lha
Note:Notallcommands/programssupportthe“merging”ofmultipleoptions.
27