+ All Categories
Home > Documents > Introduction to UNIX

Introduction to UNIX

Date post: 07-Feb-2016
Category:
Upload: elaine
View: 30 times
Download: 0 times
Share this document with a friend
Description:
Introduction to UNIX. Unix File System. Directory Organization Hierarchy of Files & Directories. Unix File System. Identifying Files Using Full Path Names. /home/rdefe/mbox. Full Path Names Always begin with /. mbox. data/jan/file1. Unix File System. - PowerPoint PPT Presentation
Popular Tags:
34
Introduction to UNIX
Transcript
Page 1: Introduction to UNIX

Introduction to UNIX

Page 2: Introduction to UNIX

2

Unix File SystemDirectory OrganizationHierarchy of Files & Directories

usr var

file1, file2,file3, file4

jan

file1, file2,file3, file4

feb

data m box, letter,prog1, prog2

rdefe jsm ith

x1, x2, x3, x4

save m box, jandatinfo

djones

hom e etc lib

/

Page 3: Introduction to UNIX

3

Unix File SystemIdentifying Files Using Full Path Names

usr var

file1, file2,file3 , file4

jan

file1, file2,file3, file4

feb

data m box, letter,prog1, prog2

rdefe jsm ith

x1, x2, x3, x4

save m box, jandatinfo

djones

hom e etc lib

/

/home/rdefe/mbox

Full Path Names Always begin with /

Page 4: Introduction to UNIX

4

Unix File System Identifying Files using Relative Path Names

Dependent on Your Location in the File System

usr var

file1, file2,file3 , file4

jan

file1, file2,file3, file4

feb

data m box, letter,prog1, prog2

rdefe jsm ith

x1, x2, x3, x4

save m box, jandatinfo

djones

hom e etc lib

/

data/jan/file1

Current Working Directory

mbox

Page 5: Introduction to UNIX

5

Directory Manipulation

mkdir [directory1] [directory2] … Create New Directories

$ mkdir mail$

file1, file2,file3, file4

jan

file1, file2,file3, file4

feb

data m ail m box, letter,prog1, prog2

rdefe

Directories created based on your current location in the File System

Page 6: Introduction to UNIX

6

Directory Manipulationcd [DirectoryName]

Change Directory

usr var

file1, file2,file3, file4

jan

file1, file2,file3, file4

feb

data m box, letter,prog1, prog2

rdefe jsm ith

x1, x2, x3, x4

save m box, jandatinfo

djones

hom e etc lib

/

$ cd data

$ cd /home/djones

Page 7: Introduction to UNIX

7

Directory Manipulationpwd

Display Present Working Directory

usr var

file1, file2,file3, file4

jan

file1, file2,file3, file4

feb

data m box, letter,prog1, prog2

rdefe jsm ith

x1, x2, x3, x4

save m box, jandatinfo

djones

hom e etc lib

/

$ pwd/home/rdefe$

Page 8: Introduction to UNIX

8

Directory Manipulation

rmdir [directory1] [directory2] … Remove Empty Directories

file1, file2,file3, file4

jan

file1, file2,file3, file4

feb

data m ail m box, letter,prog1, prog2

rdefe$ rmdir mail$ X

Page 9: Introduction to UNIX

9

Directory Manipulationrm [-ri] [directory1] [directory2] …

-r Remove Directories -i Interactive

file1, file2,file3, file4

jan

file1, file2,file3, file4

feb

data m ail m box, letter,prog1, prog2

rdefe

X$ rm -r data$

Caution: Will delete directories that have files & subdirectories

$ rm -i mboxmbox? y$

Page 10: Introduction to UNIX

10

Unix Commandscp [-i] [SourceFile] [DestinationFile]

Copy A File -i Interactive

$ cp jan jan.copy$

$ cp /home/jsmith/data mydata$

$ cp /home/jsmith/d5 /tmp/a5$

Page 11: Introduction to UNIX

11

Unix Commands

cp [-i] [File1] [File2] … [FileN] [Directory] Copy N number of files to a directory$ cp jan feb mar data

$

$ cp p1 /tmp/p2 p3 data$

$ cp jan data$Note: data is an existing

directory

Page 12: Introduction to UNIX

12

Unix Commandsmv [-i] [SourceFile] [DestinationFile]

Rename a File Move a File to a Different Directory

$ mv jan feb$

$ mv jan /tmp/oldjan$

$ mv jan /tmp$

Page 13: Introduction to UNIX

13

Unix Commands

mv [-i] [File1] [File2] … [FileN] [Directory] Move N number of files to a directory

$ mv jan feb mar data$

$ mv p1 /tmp/p2 p3 data$

$ mv jan data/oldjan$

Note: data is an existing directory

Page 14: Introduction to UNIX

14

Unix Commandsln [-i] [SourceFile] [DestinationFile]

Create multiple names that all reference the same data

$ ls jan$ ln jan feb$ ls jan feb$

1 $ vi feb$

2

$ cat jan$ cat feb$

3

Changes made to feb are reflected in jan feb and jan both reference the same data Changes made to one will be reflected in the other

Page 15: Introduction to UNIX

15

Unix CommandsHow Links Work

$ ls jan$ ln jan feb$ ln feb mar$ ls jan feb mar$

jan

feb

mar

$ rm jan Use the rm command to remove links

X

Page 16: Introduction to UNIX

16

Unix Commands

feb

mar

1582

How Links Work ls -i to display inode numbers ls -l to display number of links

$ ls -l-rw-r--r-- 2 rdefe unix 53 Sep 12 21:46 feb-rw-r--r-- 2 rdefe unix 53 Sep 12 21:46 mar$

$ ls -i1582 feb1582 mar$

Page 17: Introduction to UNIX

17

Unix Commandsln [-i] [SourceFile] [DestinationFile]

Create multiple names that all reference the same data

$ ls jan$ ln jan feb$ ls jan feb$

1 $ vi feb$2

$ cat jan$ cat feb$

3

Page 18: Introduction to UNIX

18

Unix Commands

ln [-i] [File1] [File2] … [FileN] [Directory] Create N number of linked files in a

directory$ ln jan feb mar data$

$ ln p1 /tmp/p2 p3 data$

$ ln jan data/oldjan$

Note: data is an existing directory

Page 19: Introduction to UNIX

19

Examplescp, mv, ln

$ ls -li1407 -rw-r--r-- 1 rdefe unix 1696 Oct 29 21:39 letter1

$ cp letter1 letter1.cp$ ls -li1407 -rw-r--r-- 1 rdefe unix 1696 Oct 29 21:39 letter11509 -rw-r--r-- 1 rdefe unix 1696 Oct 29 21:39 letter1.cp

$ mv letter1.cp doc$ ls -li1509 -rw-r--r-- 1 rdefe unix 1696 Oct 29 21:39 doc1407 -rw-r--r-- 1 rdefe unix 1696 Oct 29 21:39 letter1

Page 20: Introduction to UNIX

20

Examplescp, mv, ln

$ ls -li1509 -rw-r--r-- 1 rdefe unix 1696 Oct 29 21:39 doc1407 -rw-r--r-- 1 rdefe unix 1696 Oct 29 21:39 letter1

$ ln doc a$ ln a b$ ls -li1509 -rw-r--r-- 3 rdefe unix 1696 Oct 29 21:39 a1509 -rw-r--r-- 3 rdefe unix 1696 Oct 29 21:39 b1509 -rw-r--r-- 3 rdefe unix 1696 Oct 29 21:39 doc1407 -rw-r--r-- 1 rdefe unix 1696 Oct 29 21:39 letter1

Page 21: Introduction to UNIX

21

Examplescp, mv, lncp Makes new copies of filesmv Moves and/or renames filesln Create additional file names

Page 22: Introduction to UNIX

22

Unix Commandsgrep [string] [File1] [File2] …

Find a char string contained in a file Global Regular Expression Processor

$ cat datathis is a sample filethat we'll use to test theunix grep command.unix commands can some interestingnames

$ grep unix dataunix grep command.unix commands can some interesting

Page 23: Introduction to UNIX

23

Unix Commands

grep [string] [File1] [File2] …

$ grep unix data wpdata:unix grep command.data:unix commands can some interestingwp:created with the unix command vi.wp:this unix editor can$$ grep "unix comm" data wpdata:unix commands can some interestingwp:created with the unix command vi.$

Page 24: Introduction to UNIX

24

Meta CharactersSpecial Characters with Special Meaning

/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ < > | & #Used to Save time

$ ls a*z

$ ls a*9*z

$ cp a* data

$ more data*

$ rm junk*

$ ls a*

* Match zero or more characters

Page 25: Introduction to UNIX

25

Meta CharactersSpecial Characters with Special Meaning

/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ < > | & #Used to Save time

$ ls a?z

$ ls a??

$ cp a? data

$ more data?

$ rm junk?

$ ls a?

? Match any single character

Page 26: Introduction to UNIX

26

Meta CharactersSpecial Characters with Special Meaning

/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ < > | & #Used to Save time

[ ] Match any single character in the list

$ ls a[abc] aa, ab, ac

$ ls a[abc,0-9]z aaz, a9z, acz

$ ls a[adz,A-Z] aa, aZ, aA

Page 27: Introduction to UNIX

27

Meta CharactersCombining Meta Charaters

$ ls a?[123] aa1, au3, az2

$ ls data*[89][12] data81, data91, data82

$ ls mail?[xy]* mailxx1234, mail8y

Page 28: Introduction to UNIX

28

Meta Characters . Current Directory .. Parent Directory ~ Home Directory

usr var

file1, file2 ,file3, file4

jan

file1, file2 ,file3, file4

feb

data m box, le tter,prog1, prog2

rdefe jsm ith

x1, x2, x3, x4

save m box, jandatinfo

djones

hom e etc lib

/

Current DirectoryParent Directory

Page 29: Introduction to UNIX

29

Meta CharactersCopy /home/djones/info to rdefe

usr var

file1, file2,file3, file4

jan

file1, file2,file3, file4

feb

data m box, letter,prog1, prog2

rdefe jsm ith

x1, x2, x3, x4

save m box, jandatinfo

djones

hom e etc lib

/

$ cp /home/djones/info .$$

pwd

$ cp ../djones/info .$

Page 30: Introduction to UNIX

30

Meta CharactersCopy /home/rdefe/mbox to data

usr var

file1 , file2,file3 , file4

jan

file1 , file2,file3, file4

feb

data m box, letter,prog1, prog2

rdefe jsm ith

x1, x2, x3, x4

save m box, jandatinfo

djones

hom e etc lib

/

$ cp ../mbox tempmbox$$

pwd

$ cp ../mbox .$

Page 31: Introduction to UNIX

31

Meta CharactersOther Examples...

usr var

file1 , file2,file3 , file4

jan

file1 , file2,file3, file4

feb

data m box, letter,prog1, prog2

rdefe jsm ith

x1, x2, x3, x4

save m box, jandatinfo

djones

hom e etc lib

/$ cp ../*.f .$

pwd

$ cp ../../rdefe/mbox .$

Page 32: Introduction to UNIX

32

…Even More RedirectionOutput Normally Displayed to the

Screen Can Be Redirected to a File

$ pr prog1 >> prog1.pr$

If the file prog1.pr exists append the output of the pr command to prog1.pr

Note: Nothing is displayed to the screen

If the file prog1.pr does not exist send the output of the pr command to a new file prog1.pr

Page 33: Introduction to UNIX

33

…Even More RedirectionUnixCommand | tee FileName

Display Screen Output and Redirect to a File

$ who | tee whoisonrdefe ttyp0 Aug 23 9:07 (dana)jsmith ttyp2 Aug 23 22:30 (dana)rdefe ttyp3 Aug 23 13:53 (dana)$

Output saved to the file whoison

Output displayed to the screen

Page 34: Introduction to UNIX

34

Shell ScriptsText File that Contains Unix CommandsCorrect Command Syntax

Options Arguments

One Command per Line$ cat myshellwhodate$

$ rm * -i

$ cat myshell2who;date$

x


Recommended