“introduction to unix/linux” inx s17, day 2,...

30
“Introduction to Unix/Linux” INX_S17, Day 2, 2017-04-05 shell(s), prompt, setenv, echo, quoting, filesystem, paths, pwd, cd, ls Learning Outcome(s): Navigate and use the Unix/Linux file system, including understanding directory structure Matthew Peterson, OSU CGRB, [email protected] Please do not redistribute outside of OSU; contains copyrighted materials.

Upload: vulien

Post on 23-Mar-2018

226 views

Category:

Documents


1 download

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:

5

1977sh

1978csh

1983tcsh

~1989bashdashzsh

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

setenv inbash is: export

bashexport greeting="hello $USER"echo $greeting

11

Lifetimeofavariable?

•Variablessetinashell“last”untilyoulogout•Whenyoulogbackinnexttime,

12

WindowsandMacFilesystems

13

LinuxFilesystem

14

http://teaching.cgrb.oregonstate.edu/CGRB/oneil/primer/partI_3_the_command_line_and_filesystem.html

AbsolutePath(toafile)

15

LinuxFilesystem (upsidedown?)

16

http://faithandtech.nccumc.net/a-techies-advent-devotional/

AbsolutePathto“music”?

17

/

mnt

zipmusic

http://faithandtech.nccumc.net/a-techies-advent-devotional/

LinuxFilesystem

18

media bin

/

echo $HOME

https://commons.wikimedia.org/wiki/File:Home_Icon.svg

PrintWorkingDirectory

echo $PWD

pwd

Acronyms:•PWD=•CWD=

19

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

Command/VariableReview•echo $0•env / setenv $USER•tcsh / bash $HOME•pwd $PWD•cd•ls

28

Exercises/Practice•Movingaround(cd)• Listingfiles/directories(ls)•Checkingwhereyouare(pwd)• Settingsome(temporary)environmentvariables(setenv)•Displayingthem(echo)

29