Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to UNIX. 2 Unix File System zDirectory Organization zHierarchy of Files & Directories.

Similar presentations


Presentation on theme: "Introduction to UNIX. 2 Unix File System zDirectory Organization zHierarchy of Files & Directories."— Presentation transcript:

1 Introduction to UNIX

2 2 Unix File System zDirectory Organization zHierarchy of Files & Directories

3 3 Unix File System zIdentifying Files Using Full Path Names /home/rdefe/mbox Full Path Names Always begin with /

4 4 Unix File System zIdentifying Files using Relative Path Names yDependent on Your Location in the File System data/jan/file1 Current Working Directory mbox

5 5 Directory Manipulation zmkdir [directory 1 ] [directory 2 ] … yCreate New Directories $ mkdir mail $ $ mkdir mail $ Directories created based on your current location in the File System

6 6 Directory Manipulation zcd [DirectoryName] yChange Directory $ cd data $ cd /home/djones

7 7 Directory Manipulation zpwd yDisplay Present Working Directory $ pwd /home/rdefe $ $ pwd /home/rdefe $

8 8 Directory Manipulation zrmdir [directory 1 ] [directory 2 ] … yRemove Empty Directories $ rmdir mail $ $ rmdir mail $ X

9 9 Directory Manipulation zrm [-ri] [directory 1 ] [directory 2 ] … y-r Remove Directories y-i Interactive X $ rm -r data $ $ rm -r data $ Caution: Will delete directories that have files & subdirectories $ rm -i mbox mbox? y $ $ rm -i mbox mbox? y $

10 10 Unix Commands zcp [-i] [SourceFile] [DestinationFile] yCopy A File y-i Interactive $ cp jan jan.copy $ $ cp jan jan.copy $ $ cp /home/jsmith/data mydata $ $ cp /home/jsmith/data mydata $ $ cp /home/jsmith/d5 /tmp/a5 $ $ cp /home/jsmith/d5 /tmp/a5 $

11 11 Unix Commands zcp [-i] [File 1 ] [File 2 ] … [File N ] [Directory] yCopy N number of files to a directory $ cp jan feb mar data $ $ cp jan feb mar data $ $ cp p1 /tmp/p2 p3 data $ $ cp p1 /tmp/p2 p3 data $ $ cp jan data $ $ cp jan data $ Note: data is an existing directory

12 12 Unix Commands zmv [-i] [SourceFile] [DestinationFile] yRename a File yMove a File to a Different Directory $ mv jan feb $ $ mv jan feb $ $ mv jan /tmp/oldjan $ $ mv jan /tmp/oldjan $ $ mv jan /tmp $ $ mv jan /tmp $

13 13 Unix Commands zmv [-i] [File 1 ] [File 2 ] … [File N ] [Directory] yMove N number of files to a directory $ mv jan feb mar data $ $ mv jan feb mar data $ $ mv p1 /tmp/p2 p3 data $ $ mv p1 /tmp/p2 p3 data $ $ mv jan data/oldjan $ $ mv jan data/oldjan $ Note: data is an existing directory

14 14 Unix Commands zln [-i] [SourceFile] [DestinationFile] yCreate multiple names that all reference the same data $ ls jan $ ln jan feb $ ls jan feb $ $ ls jan $ ln jan feb $ ls jan feb $ 1 $ vi feb $ $ vi feb $ 2 $ cat jan $ cat feb $ $ cat jan $ cat feb $ 3 zChanges made to feb are reflected in jan zfeb and jan both reference the same data zChanges made to one will be reflected in the other

15 15 Unix Commands zHow Links Work $ ls jan $ ln jan feb $ ln feb mar $ ls jan feb mar $ $ 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

16 16 Unix Commands feb mar 1582 zHow Links Work yls -i to display inode numbers yls -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 -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 -i 1582 feb 1582 mar $ $ ls -i 1582 feb 1582 mar $

17 17 Unix Commands zln [-i] [SourceFile] [DestinationFile] yCreate multiple names that all reference the same data $ ls jan $ ln jan feb $ ls jan feb $ $ ls jan $ ln jan feb $ ls jan feb $ 1 $ vi feb $ $ vi feb $ 2 $ cat jan $ cat feb $ $ cat jan $ cat feb $ 3

18 18 Unix Commands zln [-i] [File 1 ] [File 2 ] … [File N ] [Directory] yCreate N number of linked files in a directory $ ln jan feb mar data $ $ ln jan feb mar data $ $ ln p1 /tmp/p2 p3 data $ $ ln p1 /tmp/p2 p3 data $ $ ln jan data/oldjan $ $ ln jan data/oldjan $ Note: data is an existing directory

19 19 Examples cp, mv, ln $ ls -li 1407 -rw-r--r-- 1 rdefe unix 1696 Oct 29 21:39 letter1 $ cp letter1 letter1.cp $ ls -li 1407 -rw-r--r-- 1 rdefe unix 1696 Oct 29 21:39 letter1 1509 -rw-r--r-- 1 rdefe unix 1696 Oct 29 21:39 letter1.cp $ mv letter1.cp doc $ ls -li 1509 -rw-r--r-- 1 rdefe unix 1696 Oct 29 21:39 doc 1407 -rw-r--r-- 1 rdefe unix 1696 Oct 29 21:39 letter1 $ ls -li 1407 -rw-r--r-- 1 rdefe unix 1696 Oct 29 21:39 letter1 $ cp letter1 letter1.cp $ ls -li 1407 -rw-r--r-- 1 rdefe unix 1696 Oct 29 21:39 letter1 1509 -rw-r--r-- 1 rdefe unix 1696 Oct 29 21:39 letter1.cp $ mv letter1.cp doc $ ls -li 1509 -rw-r--r-- 1 rdefe unix 1696 Oct 29 21:39 doc 1407 -rw-r--r-- 1 rdefe unix 1696 Oct 29 21:39 letter1

20 20 Examples cp, mv, ln $ ls -li 1509 -rw-r--r-- 1 rdefe unix 1696 Oct 29 21:39 doc 1407 -rw-r--r-- 1 rdefe unix 1696 Oct 29 21:39 letter1 $ ln doc a $ ln a b $ ls -li 1509 -rw-r--r-- 3 rdefe unix 1696 Oct 29 21:39 a 1509 -rw-r--r-- 3 rdefe unix 1696 Oct 29 21:39 b 1509 -rw-r--r-- 3 rdefe unix 1696 Oct 29 21:39 doc 1407 -rw-r--r-- 1 rdefe unix 1696 Oct 29 21:39 letter1 $ ls -li 1509 -rw-r--r-- 1 rdefe unix 1696 Oct 29 21:39 doc 1407 -rw-r--r-- 1 rdefe unix 1696 Oct 29 21:39 letter1 $ ln doc a $ ln a b $ ls -li 1509 -rw-r--r-- 3 rdefe unix 1696 Oct 29 21:39 a 1509 -rw-r--r-- 3 rdefe unix 1696 Oct 29 21:39 b 1509 -rw-r--r-- 3 rdefe unix 1696 Oct 29 21:39 doc 1407 -rw-r--r-- 1 rdefe unix 1696 Oct 29 21:39 letter1

21 21 Examples cp, mv, ln zcp Makes new copies of files zmv Moves and/or renames files zln Create additional file names

22 22 Unix Commands zgrep [string] [File 1 ] [File 2 ] … yFind a char string contained in a file yGlobal Regular Expression Processor $ cat data this is a sample file that we'll use to test the unix grep command. unix commands can some interesting names $ grep unix data unix grep command. unix commands can some interesting $ cat data this is a sample file that we'll use to test the unix grep command. unix commands can some interesting names $ grep unix data unix grep command. unix commands can some interesting

23 23 Unix Commands zgrep [string] [File 1 ] [File 2 ] … $ grep unix data wp data:unix grep command. data:unix commands can some interesting wp:created with the unix command vi. wp:this unix editor can $ $ grep "unix comm" data wp data:unix commands can some interesting wp:created with the unix command vi. $ $ grep unix data wp data:unix grep command. data:unix commands can some interesting wp:created with the unix command vi. wp:this unix editor can $ $ grep "unix comm" data wp data:unix commands can some interesting wp:created with the unix command vi. $

24 24 Meta Characters zSpecial Characters with Special Meaning y/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ | & # zUsed to Save time $ ls a*z $ ls a*9*z $ cp a* data $ more data* $ rm junk* $ ls a* * Match zero or more characters

25 25 Meta Characters zSpecial Characters with Special Meaning y/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ | & # zUsed to Save time $ ls a?z $ ls a?? $ cp a? data $ more data? $ rm junk? $ ls a? ? Match any single character

26 26 Meta Characters zSpecial Characters with Special Meaning y/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ | & # zUsed 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

27 27 Meta Characters zCombining Meta Charaters $ ls a?[123] aa1, au3, az2 $ ls data*[89][12] data81, data91, data82 $ ls mail?[xy]* mailxx1234, mail8y

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

29 29 Meta Characters zCopy /home/djones/info to rdefe $ cp /home/djones/info. $ $ cp /home/djones/info. $ pwd $ cp../djones/info. $ $ cp../djones/info. $

30 30 Meta Characters zCopy /home/rdefe/mbox to data $ cp../mbox tempmbox $ $ cp../mbox tempmbox $ pwd $ cp../mbox. $ $ cp../mbox. $

31 31 Meta Characters zOther Examples... $ cp../*.f. $ $ cp../*.f. $ pwd $ cp../../rdefe/mbox. $ $ cp../../rdefe/mbox. $

32 32 …Even More Redirection zOutput Normally Displayed to the Screen Can Be Redirected to a File $ pr prog1 >> prog1.pr $ $ 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

33 33 …Even More Redirection zUnixCommand | tee FileName yDisplay Screen Output and Redirect to a File $ who | tee whoison rdefe ttyp0 Aug 23 9:07 (dana) jsmith ttyp2 Aug 23 22:30 (dana) rdefe ttyp3 Aug 23 13:53 (dana) $ $ who | tee whoison rdefe 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

34 34 Shell Scripts zText File that Contains Unix Commands zCorrect Command Syntax yOptions yArguments zOne Command per Line $ cat myshell who date $ $ cat myshell who date $ $ rm * -i $ cat myshell2 who;date $ $ cat myshell2 who;date $ x


Download ppt "Introduction to UNIX. 2 Unix File System zDirectory Organization zHierarchy of Files & Directories."

Similar presentations


Ads by Google