20
Introduction to UNIX

Introduction to UNIX. 2 Meta Characters zSpecial Characters with Special Meaning zUsed to Save Time y/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ | & # y#Comment Line

Embed Size (px)

Citation preview

Page 1: Introduction to UNIX. 2 Meta Characters zSpecial Characters with Special Meaning zUsed to Save Time y/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ | & # y#Comment Line

Introduction to UNIX

Page 2: Introduction to UNIX. 2 Meta Characters zSpecial Characters with Special Meaning zUsed to Save Time y/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ | & # y#Comment Line

2

Meta Characters

Special Characters with Special MeaningUsed to Save Time

/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ < > | & # # Comment Line

Turning Off Meta Characters Display a Line of **** echo ***

Doesn’t Work!

Page 3: Introduction to UNIX. 2 Meta Characters zSpecial Characters with Special Meaning zUsed to Save Time y/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ | & # y#Comment Line

3

Meta Characters

Turning Off Meta Characters \ Turns Off One Meta Character

$ echo \*\*\****

$ echo \*\*\****

Page 4: Introduction to UNIX. 2 Meta Characters zSpecial Characters with Special Meaning zUsed to Save Time y/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ | & # y#Comment Line

4

Meta Characters

Turning Off Meta Characters ‘ ‘ Turn off all Meta Characters between the ‘ ‘

$ echo ‘***’***

$ echo ‘***’***

Page 5: Introduction to UNIX. 2 Meta Characters zSpecial Characters with Special Meaning zUsed to Save Time y/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ | & # y#Comment Line

5

Meta Characters

Turning Off Meta Characters “ “ Turn off Meta Characters between the “ “ $ \ ` remain active

$ echo “My home is $HOME”My home is /home/rdefe

$ echo “My home is $HOME”My home is /home/rdefe

Page 6: Introduction to UNIX. 2 Meta Characters zSpecial Characters with Special Meaning zUsed to Save Time y/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ | & # y#Comment Line

6

Meta Characters

Turning Off Meta Characters with “ “ $ \ ` remain active

$ echo -e “My home is $HOME\nNext Line”My home is /home/rdefe

Next Line$

$ echo -e “My home is $HOME\nNext Line”My home is /home/rdefe

Next Line$

\n New Line

\t Tab

Page 7: Introduction to UNIX. 2 Meta Characters zSpecial Characters with Special Meaning zUsed to Save Time y/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ | & # y#Comment Line

7

Meta Characters

Turning Off Meta Characters “ “ Turn off Meta Characters between the “ “ $ \ ` remain active

$ echo “Today is `date`”Today is Mon Jan 22 22:04:46 EST 1996

$ echo “Today is `date`”Today is Mon Jan 22 22:04:46 EST 1996

Page 8: Introduction to UNIX. 2 Meta Characters zSpecial Characters with Special Meaning zUsed to Save Time y/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ | & # y#Comment Line

8

Unix Commands

wc [-lwc] File1 File2 … FileN

Word Count -l Display Number of Lines -w Display Number of Words -c Display Number of Characters

$ wc mbox 59 279 1473 mbox$ wc mbox ls.file 59 279 1473 mbox 1 1 12 ls.file 60 280 1485 total

$ wc mbox 59 279 1473 mbox$ wc mbox ls.file 59 279 1473 mbox 1 1 12 ls.file 60 280 1485 total

Page 9: Introduction to UNIX. 2 Meta Characters zSpecial Characters with Special Meaning zUsed to Save Time y/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ | & # y#Comment Line

9

Unix Commands

cmp File1 File2 Compare Two Files (binary or text)

$ cmp s1 mboxs1 mbox differ: char 1, line 1

$ cmp p1 p2$

$ cmp s1 mboxs1 mbox differ: char 1, line 1

$ cmp p1 p2$

Page 10: Introduction to UNIX. 2 Meta Characters zSpecial Characters with Special Meaning zUsed to Save Time y/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ | & # y#Comment Line

10

Unix Commands

sort [-fnr] File1 File2 … FileN

Sort the Contents of a File -f Ignore Case -n Sort Numbers Based on Value -r Reverse Order

$ cat wordssandboxzooxraysamjones

$ cat wordssandboxzooxraysamjones

$ sort wordsboxjonessamsandxrayzoo

$ sort wordsboxjonessamsandxrayzoo

Page 11: Introduction to UNIX. 2 Meta Characters zSpecial Characters with Special Meaning zUsed to Save Time y/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ | & # y#Comment Line

11

Unix Commands

uniq [-d] File1 File2 … FileN

Read a Sorted File Reject or Report Duplicates -d Display Duplicates

$ cat stuffdosmacmvsmvsunixunixwindows95

$ cat stuffdosmacmvsmvsunixunixwindows95

$ uniq stuffdosmacmvsunixwindows95

$ uniq stuffdosmacmvsunixwindows95

$ uniq -d stuffmvsunix

$ uniq -d stuffmvsunix

Page 12: Introduction to UNIX. 2 Meta Characters zSpecial Characters with Special Meaning zUsed to Save Time y/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ | & # y#Comment Line

12

Unix Commands

compress File1 File2 … FileN

uncompress File1 File2 … FileN

Used to compress Large Files

$ ls -s datafile 297 datafile$ compress datafile$ ls -s datafile* 177 datafile.Z

$ ls -s datafile 297 datafile$ compress datafile$ ls -s datafile* 177 datafile.Z

$ uncompress datafile$ ls -s datafile 297 datafile

$ uncompress datafile$ ls -s datafile 297 datafile

Page 13: Introduction to UNIX. 2 Meta Characters zSpecial Characters with Special Meaning zUsed to Save Time y/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ | & # y#Comment Line

13

Unix Commands

cut -c[col number] FileName Cut columns and display to screen

$ cat namesJones JohnSmith RoberDoe John

$ cat namesJones JohnSmith RoberDoe John

$ cut -c1-3 namesJonSmiDoe

$ cut -c1-3 namesJonSmiDoe

$ cut -c1-3,11-13 namesJonJohSmiRobDoeJoh

$ cut -c1-3,11-13 namesJonJohSmiRobDoeJoh

Page 14: Introduction to UNIX. 2 Meta Characters zSpecial Characters with Special Meaning zUsed to Save Time y/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ | & # y#Comment Line

14

Unix Commands

find Location Criteria Action Locate Files Based on a Search Criteria

$ find /home -name mbox -print/home/mbox/home/rdefe/mbox/home/ssmith/mbox$

$ find /home -name mbox -print/home/mbox/home/rdefe/mbox/home/ssmith/mbox$

$ find /home -name “mbox*” -print$

$ find /home -name “mbox*” -print$

Page 15: Introduction to UNIX. 2 Meta Characters zSpecial Characters with Special Meaning zUsed to Save Time y/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ | & # y#Comment Line

15

Unix Commands

find Location Criteria Action Specify Multiple Search Locations

$ find /home /usr -name mbox -print/home/mbox/home/rdefe/mbox/home/ssmith/mbox/usr/mbox/usr/tmp/mbox$

$ find /home /usr -name mbox -print/home/mbox/home/rdefe/mbox/home/ssmith/mbox/usr/mbox/usr/tmp/mbox$

Page 16: Introduction to UNIX. 2 Meta Characters zSpecial Characters with Special Meaning zUsed to Save Time y/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ | & # y#Comment Line

16

Unix Commands

find Location Criteria Action -user [login] -group [GroupName]

$ find /home -user rdefe -print/home/rdefe/mbox/home/rdefe/doc$

$ find /home -user rdefe -print/home/rdefe/mbox/home/rdefe/doc$ $ find /home -group unix -print

/home/rdefe/mbox/home/rdefe/doc/home/jsmith/p1$

$ find /home -group unix -print/home/rdefe/mbox/home/rdefe/doc/home/jsmith/p1$

Page 17: Introduction to UNIX. 2 Meta Characters zSpecial Characters with Special Meaning zUsed to Save Time y/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ | & # y#Comment Line

17

Unix Commands

find Location Criteria Action -mtime [+|-] Days -links [+|-] Number

$ find /home -mtime 7 -print$ find /home -mtime 7 -print Files modified exactly 7 days ago

$ find /home -mtime +7 -print$ find /home -mtime +7 -print Files modified greater than 7 days ago

$ find /home -mtime -7 -print$ find /home -mtime -7 -print Files modified less than 7 days ago

Page 18: Introduction to UNIX. 2 Meta Characters zSpecial Characters with Special Meaning zUsed to Save Time y/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ | & # y#Comment Line

18

Unix Commands

find Location Criteria Action -inum [InodeNumber] -type [f|d]

$ find /home -inum 10203 -print$ find /home -inum 10203 -print Find file with inode number 10203

$ find /home -type d -print$ find /home -type d -print Find all directories in /home

Page 19: Introduction to UNIX. 2 Meta Characters zSpecial Characters with Special Meaning zUsed to Save Time y/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ | & # y#Comment Line

19

Unix Commands

find Location Criteria Action -print Display File Location -exec UnixCmds Execute Unix Command(s) -ok UnixCmds Interactive Unix Command(s)

$ find /home -user rdefe -exec pr {} \;$ find /home -user rdefe -exec pr {} \;

$ find /home -user rdefe -ok pr {} \;/home/rdefe/mbox?

$ find /home -user rdefe -ok pr {} \;/home/rdefe/mbox?

Prompt for Each File

Page 20: Introduction to UNIX. 2 Meta Characters zSpecial Characters with Special Meaning zUsed to Save Time y/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ | & # y#Comment Line

20

Unix Commands

find Examples

$ find /home -user rdefe -links 2 -print$ find /home -user rdefe -links 2 -print

Implied “and”

$ find /home -user rdefe -o -links 2 -print$ find /home -user rdefe -o -links 2 -print

“or”

$ find /home \( -user rdefe -o -user jdoe \) -links 2 -print

$ find /home \( -user rdefe -o -user jdoe \) -links 2 -print