Top Banner
1 Unix File System Stores Files Text, Programs, Images, etc. Made up of Many Files User, Unix System, Unix Commands
34

1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

Jan 18, 2018

Download

Documents

Posy Chase

3 Unix File System zHome Directory yPersonal Directory to store files yUsually the Directory Name = login ID yCurrent Directory after successful login Home directories for: rdefe, jsmith and djones
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

1

Unix File SystemStores Files

Text, Programs, Images, etc.Made up of Many Files

User, Unix System, Unix Commands

Page 2: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

2

Unix 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

root

Home Directory Directory

containing all home directories

Top most directory in Unix

Page 3: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

3

Unix File SystemHome Directory

Personal Directory to store files Usually the Directory Name = login ID Current Directory after successful login

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

root

Home directories for: rdefe, jsmith and djones

Page 4: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

4

Unix File SystemWhat Can You Do?

Create New Files & Directories Organize Files Locate Files Based on a Directory

Structure Change to a New Directory

Page 5: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

5

Unix File SystemFile & Directory Naming Guidelines

Don’t Use Meta Characters/ \ “ ` * ; ? { } ( ) [ ] ~ ! $ < > | & #

Do Usea-z A-Z0-9. _ -

Remember Unix is Case Sensitive!

Page 6: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

6

Unix File System

File & Directory Name Examples feb1998, 178987, my_data,

my.data.new mbox, Mbox, mboX, MBOX, mBox prog1..2 .profile

Page 7: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

7

Unix Commandsls

List Files & Directories$ ls198Aaa.bb.cc.ddbindatefileetcmailmboxmbox.oldunix$

Page 8: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

8

Unix Commandsls -p

-p Show Directories$ ls -p198Aaa.bb.cc.ddbin/datefileetc/mail/mboxmbox.oldunix/$

Page 9: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

9

Unix Commands

ls [directory1] [directory2] ... List the contents of a directory

$ ls unixawk.dataawk.prgbgraphcpyhomework2homework3unix2test$

$ ls -p198Aaa.bb.cc.ddbin/datefileetc/mail/mboxmbox.oldunix/$

Page 10: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

10

Unix Commandsls -s

-s Show File Size in Blocks Block Sizes

512 bytes1024 bytes2048 bytes

$ ls -stotal 19 1 198 1 A 1 aa.bb.cc.dd 1 bin 1 datefile 1 etc 1 mail 2 mbox 1 unix

Page 11: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

11

Unix Commandsls -l

-l Long Listing$ ls -ltotal 19-rw-r--r-- 1 rdefe unix 53 Sep 12 21:46 198-rw-r--r-- 1 rdefe unix 62 Sep 12 21:47 Adrwxr-xr-x 2 rdefe unix 96 Sep 4 20:58 bindrwxr-xr-x 3 rdefe unix 80 Aug 29 20:54 dbdrwxr-xr-x 2 rdefe unix 64 Aug 29 20:54 etcdrwxr-xr-x 2 rdefe unix 32 Sep 2 1992 mail-rw------- 1 rdefe unix 984 Sep 12 21:44 mboxdrwxr-xr-x 2 rdefe unix 144 Aug 29 20:54 unix$

Page 12: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

12

Unix Commandsls -a

-a List All Files $ ls -a....profile.sh_history198Abindatefiledbetcmboxunix$

Include Files That Begin with a ‘.’

Files that begin with a ‘.’ are usually configuration files

Page 13: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

13

Unix Commandsls -r

-r Reverse Sortls -R

-R List Contents of Subdirectories

$ ls -runixmboxmailetcdbdatefilebinA198$

• List files in each subdirectory.

• Subdirectories with Subdirectories will also be listed…and so on...

Page 14: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

14

Unix Commandsls -l -t or ls -lt

-t Sort On Modification Time$ ls -lttotal 19-rw-r--r-- 1 rdefe unix 62 Sep 12 21:47 A-rw-r--r-- 1 rdefe unix 53 Sep 12 21:46 198-rw------- 1 rdefe unix 984 Sep 12 21:44 mboxdrwxr-xr-x 2 rdefe unix 96 Sep 4 20:58 bindrwxr-xr-x 2 rdefe unix 64 Aug 29 20:54 etcdrwxr-xr-x 2 rdefe unix 144 Aug 29 20:54 unixdrwxr-xr-x 3 rdefe unix 80 Aug 29 20:54 dbdrwxr-xr-x 2 rdefe unix 32 Sep 2 1992 mail$

Page 15: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

15

Unix Commandsls -l -t -r or ls -ltr

-tr Reverse Sort On Modification Time$ ls -ltrtotal 19drwxr-xr-x 2 rdefe unix 32 Sep 2 1992 maildrwxr-xr-x 3 rdefe unix 80 Aug 29 20:54 dbdrwxr-xr-x 2 rdefe unix 144 Aug 29 20:54 unixdrwxr-xr-x 2 rdefe unix 64 Aug 29 20:54 etcdrwxr-xr-x 2 rdefe unix 96 Sep 4 20:58 bin-rw------- 1 rdefe unix 984 Sep 12 21:44 mbox-rw-r--r-- 1 rdefe unix 53 Sep 12 21:46 198-rw-r--r-- 1 rdefe unix 62 Sep 12 21:47 A$

Page 16: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

16

Unix Commands

ls -[ltrRa] [Filename1] [Filename2] … UnixCommand Options Arguments

$ ls -lt unix$

Page 17: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

17

Unix Commandscat [Filename1] [Filename2] …

Concatenate Files Display Files to the Screen Ctrl-s Pause Screen Ctrl-q Unpause Screen

$ cat sample.fileThis is a sample file that i'll use to demo how the pr command is used.The pr command is useful in formattingvarious types of text files.$

Page 18: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

18

Unix Commandsmore [Filename1] [Filename2] …

Display Files to the screen one page at a time$ more largefileThis is a sample file that i'll use to demo how the pr command is used.The pr command is useful in formattingvarious types of text files.--More--(16%)

Spacebar (next page) b (previous page) Enter Key (next line)

q (Quit & return to unix) /string (search for string) :n (next file) :p (previous file)

Page 19: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

19

Unix Commandslpr [Filename1] [Filename2] …

Send Files to a Unix Printer No Formatting (page numbers, etc.)

$ lpr prog1 mbox$

$ pr sample.file

98-05-22 23:07 sample.file Page 1

This is a sample file that i'll use to demo how the pr command is used....

Ideal solution would be to combine the lpr & pr to achieve formatted printed output

Page 20: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

20

Unix RedirectionRedirecting Input

A Command Requiring Input Can Receive it’s Input From a File

$ mail rdefe < mesg$

Page 21: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

21

Unix RedirectionRedirecting Input

Command < File

Command that requires input

File used to provide input (instead of typing it!)

$ mail rdefe < mesg$

Page 22: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

22

Redirection Examples

$ pr data > data.pr$ lpr data.pr $ pr data | lprIs the same as1

$ cal 3 1993 > year Using arguments with redirection2

$ ls -l data > stuff Using arguments & options with redirection3

Page 23: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

23

Redirection Examples

$ pr data > lpr4

$ cat text let > mesg5

$ pr f1 f2 > f16Create the file f1 Erases f1 if it already exists

1

pr f1 and f2, redirect to f1

2

Page 24: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

24

Unix Commandsrm [Filename1] [Filename2] …

remove files $ rm prog1 mbox$

Caution Unix Assumes You Know What Your Doing Be Sure You Know What Your Deleting No Undelete!

$ rm *$

$ rm p*$

* is a Meta Char that matches anything

Page 25: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

25

Unix Commandsvi [Filename]

Full Screen, Visual Editor Changes Displayed As They Are Made Edits A Copy of the File Changes Must Be Saved

$ vi mesg

emacshttp://www.gnu.org/software/emacs/emacs.html

Page 26: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

26

Unix CommandsVi ModesCommand Mode

Start in command mode Every Key Performs an Editing Command

Insert Mode Perform Text Entry/Input

Command Mode Insert Mode

Insert Mode Command

ESC Key

Page 27: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

27

Sample vi Edit Session

Start in Command Mode Press a key for Append After Cursor Command Enter text (Input Mode) Press ESC key (Command Mode) Press :wq followed by Enter key to Save & Exit

$ vi mesg Welcome to UNIX

This is an example ofa text file in vi~~~

Wnewtextelcome to UNIX

This is an example ofa text file in vi~~:wq$

Page 28: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

28

Cursor PositioningMoving the Cursor in Command Mode

h

j

l

kw Forward One Wordb Backward One WordCntrl-d Scroll DownCntrl-u Scroll UpEnter Down One Line G Go To Last Line5G Go To Line 5

Key Command

Page 29: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

29

Text Input Modevi Text Input Mode Commands

Wnewtextelcome to UNIX

This is an example ofa text file in vi~~

a Append After CursorWelcome to UNIXnewtext

This is an example ofa text file in vi~~

A Append at End of LinenewtextWelcome to UNIX

This is an example ofa text file in vi~~

i Insert Before Cursor

newtextWelcome to UNIX

This is an example ofa text file in vi~~

I Insert at Beginning of Line

R Replace Text (typeover)r Replace One Char

newtextWelcome to UNIX

This is an example ofa text file in vi~~

O Open New Line Above Cursoro Open New Line Below Cursor

Page 30: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

30

Deleting TextWelcome to UNIX

This is an example ofa text file in vi~~

x Delete One CharX Delete Char Before Cursor

dd Delete One LineThis is an example ofa text file in vi~~

Proceed Any Command with a Number to multiply effect 4x Delete 4 chars 5dd Delete 5 lines 3dw Delete 3 words

Page 31: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

31

Undo ChangesWelcome to UIX

This is an example ofa text file in vi~~

x Delete One Charu Undo Last Change

Welcome to UNIX

This is an example ofa text file in vi~~

WELcome to UIX 123

This is an example ofa text file in vi~~

U Undo All Changes on Line

Welcome to UNIX

This is an example ofa text file in vi~~

Page 33: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

33

Other Goodies... /string Forward Search for `string`?string Backward Search for `string`

n Repeat Search N Repeat Search in reverse direction

Ctrl-G Display Current Location in File J Join two lines together

http://www.thomer.com/thomer/vi/vi.html

Page 34: 1 Unix File System zStores Files yText, Programs, Images, etc. zMade up of Many Files yUser, Unix System, Unix Commands.

34

That’s All ...