1 / 34

Introduction to UNIX

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.

elaine
Download Presentation

Introduction to UNIX

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to UNIX

  2. Unix File System • Directory Organization • Hierarchy of Files & Directories

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

  4. mbox data/jan/file1 Unix File System • Identifying Files using Relative Path Names • Dependent on Your Location in the File System Current Working Directory

  5. Directory Manipulation • mkdir [directory1] [directory2] … • Create New Directories $ mkdir mail $ Directories created based on your current location in the File System

  6. $ cd /home/djones Directory Manipulation • cd [DirectoryName] • Change Directory $ cd data

  7. Directory Manipulation • pwd • Display Present Working Directory $ pwd /home/rdefe $

  8. Directory Manipulation • rmdir [directory1] [directory2] … • Remove Empty Directories $ rmdir mail $ X

  9. Directory Manipulation • rm [-ri] [directory1] [directory2] … • -rRemove Directories • -i Interactive X $ rm -r data $ Caution: Will delete directories that have files & subdirectories $ rm -i mbox mbox? y $

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

  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

  12. Unix Commands • mv [-i] [SourceFile] [DestinationFile] • Rename a File • Move a File to a Different Directory $ mv jan feb $ $ mv jan /tmp/oldjan $ $ mv jan /tmp $

  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

  14. 1 $ ls jan $ ln jan feb $ ls jan feb $ 2 $ vi feb $ 3 $ cat jan $ cat feb $ • 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 Unix Commands • ln [-i] [SourceFile] [DestinationFile] • Create multiple names that all reference the same data

  15. X $ rm jan Use the rm command to remove links Unix Commands • How Links Work $ ls jan $ ln jan feb $ ln feb mar $ ls jan feb mar $ jan feb mar

  16. Unix Commands • How Links Work • ls -ito display inode numbers • ls -lto display number of links 1582 feb $ ls -i 1582 feb 1582 mar $ 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 $

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

  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

  19. Examplescp, 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

  20. Examplescp, 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

  21. Examplescp, mv, ln • cpMakes new copies of files • mvMoves and/or renames files • lnCreate additional file names

  22. Unix Commands • grep [string] [File1] [File2] … • Find a char string contained in a file • Global 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

  23. Unix Commands • grep [string] [File1] [File2] … $ 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. * Match zero or more characters $ ls a* Meta Characters • Special Characters with Special Meaning • / \ “ ` * ; ? { } ( ) [ ] ~ ! $ < > | & # • Used to Save time $ more data* $ ls a*z $ cp a* data $ ls a*9*z $ rm junk*

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

  26. [ ] 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 Meta Characters • Special Characters with Special Meaning • / \ “ ` * ; ? { } ( ) [ ] ~ ! $ < > | & # • Used to Save time

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

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

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

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

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

  32. …Even More Redirection • Output Normally Displayed to the Screen Can Be Redirected to a File If the file prog1.prdoes not exist send the output of the pr command to a new file prog1.pr $ pr prog1 >> prog1.pr $ If the file prog1.prexists append the output of the pr command to prog1.pr Note: Nothing is displayed to the screen

  33. …Even More Redirection • UnixCommand | tee FileName • Display Screen Output and Redirect to a File Output saved to the file whoison $ 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 displayed to the screen

  34. Shell Scripts • Text File that Contains Unix Commands • Correct Command Syntax • Options • Arguments • One Command per Line x $ rm * -i $ cat myshell who date $ $ cat myshell2 who;date $

More Related