1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

27
1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System

Transcript of 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

Page 1: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

1

THE UNIX FILE SYSTEM

By

Chokechai Chuensukanant

ID 121779

COSC 513 Operating System

Page 2: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

2

Why you should know UNIX

- FREE ! FREE ! FREE !!!!!!

- Source code is openly available

- Linux, its background in UNIX, will soon have a lead position in the mid to high-end server market

Page 3: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

3

The UNIX File System

• DISK ORGANIZATION

- UNIX allows you to divide your hard disk into many units (called directories), sub units (called subdirectories)

- UNIX provides commands to create, organize, and keep track of directories and files on the disk.

Page 4: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

4

FILE TYPES UNDER UNIX

• Regular files - Contain sequences of bytes that could be programming code, data, text, and so on.

• Directories files- Contain information (like the file name) about other files. It consists of a number of such records in special format defined by your operating system.

• Special Files (device files)

- Contain specific information corresponding to peripheral devices such as printers, disk, and so on. UNIX treats I/O devices as files, and each de

vice in your system.

Page 5: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

5

ABOUT DIRECTORY

• The directory structure is organized in levels and is known as a hierarchical structure.

• The highest level is called the ‘root’.

• Do not contain the information but instead provide a reference path to allow you to organize your files.

Page 6: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

6

ABOUT DIRECTORY

• Directory Structure

binbin liblib usrusr devdev

rootroot

Page 7: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

7

Important Directories

• /usr : holds users’ home directories. Similarly to /home in Linux

• /bin : holds many of the basic UNIX program files. holds many of the basic UNIX program files. bin stands for binary, and these files are executable files.

• /dev : holds device files.

• /etc : holds many of UNIX configuration files.

• /sbin : holds system files that usually are run automatically by UNIX system.

Page 8: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

8

Path and Pathnames

• Every file has a pathname.

• The pathname locates the file in the file system.

• 2 types

- Absolute Pathname

- Relative Pathname

Page 9: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

9

Path and Pathnames

/// (root pathname)

binbin liblib usrusr devdev

/usr (usr pathname)Root Subdirectories

daviddavid danieldaniel gabrielgabriel

user subdirectories

/usr/david pathname)

myfirst

myfirst

reportreport

/usr/david/myfirst (myfirst pathname)

/usr/david/report (report pathname)

Pathnames in a Directory Structure

Page 10: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

10

Absolute Pathname

• Traces a path from the root to the file.

• Using when you want to access file that is not in your current directory.

• Always use the forward slash (/) at the beginning of the pathname for the root directory.

Page 11: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

11

Relative Pathname

• Traces a path from current directory to the file.

• Using when you want to access file that is in your subdirectories of your current directory.

• There is no initial forward slash (/)

Page 12: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

12

Using File and Directory Name

• The maximum length depend on the UNIX version, up to 255 characters.

• Avoid to use <>,(),[],{},*,?,”,’,-,$,^

• Can’t use spaces ( ), in files name

• Using more than one dot is allowed in UNIX

• Case sensitive

Page 13: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

13

Directory Command

• Displaying a Directory pathname: The pwd (print working directory) command.

• Changing your Working Directory: The cd command

• Creating Directories The mkdir Command

• Removing Directories: The rmdir Command

• Listing Directories: The ls Command

Page 14: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

14

The pwd command

• Display the absolute pathname of your working directory.

• Similarly to chdir command in DOS

Page 15: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

15

The cd command

• Change your current directory

• cd $HOME using when want to return your directory.

• Similarly to cd command in DOS

Page 16: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

16

The mkdir Command

• Create new subdirectory under your working directory

• Similarly to md or mkdir command in DOS• Using option –p to create level directories in si

ngle command

Example mkdir –p /level1/level2/level3 means create directory level1 in current directory and create directory level2 in level1 directory and create level3 in level2 directory

Page 17: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

17

The rmdir Command

• Remove existing directory

• Must be in the parent directory to remove subdirectory.

• Must remove only empty directory.

• Similarly to rd or rmdir command in DOS

Page 18: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

18

The ls Command

• List subdirectories and files in current directory.

• Can use multiple options in single line

• Similarly to dir command in DOS

Page 19: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

19

Display File Contents:

• Using the cat Command

- To display file contents.

- Usually use with small files.

- Similarly to type command in DOS.

Page 20: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

20

Printing File Contents

• The lp command

- To send a copy of a file to the printer for producing a hard copy of the file.

- Can specify several files on one command line .

- Similarly to print command in DOS.

Page 21: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

21

Printing File Contents

• The cancel command

- To cancel request for print jobs made with the lp command.

• The lpstat command

- To obtain information about printing requests and the status on the printers.

Page 22: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

22

FILE MANIPULATION COMMANDS

Copying Files: The cp CommandMoving Files: The mv CommandLinking Files: The ln CommandDeleting files : The rm command

Page 23: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

23

The cp Command

• Used to create a copy (duplicate) of a file.

• Syntax

$ cp [option] [Source] [Destination]

• Source and Destination could be file or directory.

• Could have more than one source on single line but Destination must be directory.

• Similarly to copy command in DOS

Page 24: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

24

The mv Command

• Used to move a file from one place to another or to change the name of a file or directory

• Syntax

$ mv [option] [Source] [Destination]

• Source and Destination could be file or directory.

• Could have more than one source on single line but Destination must be directory.

• Similarly to move command in DOS

Page 25: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

25

The ln Command

• To create new links (name) between an existing file and a new filename.

• In the other word, create additional names for an existing file

• Syntax

$ ln [option] [existing file name] [new name]

Page 26: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

26

The rm command

• UNIX does not give you any warning message, so think twice before using this command.

• Syntax

$ rm [Existing file names] • Similarly to del command in DOS.

Page 27: 1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID 121779 COSC 513 Operating System.

27

Summary

• This presentation just show you a few basic command in UNIX.

• In more advance, I have summary more command and keep them at

http://www10.brinkster.com/boyb1917/unix.htm

• If you want to know more about UNIX , please check that out or register UNIX class on next quadmester and I will see you there.

• GOOD LUCK !!!!!!!!!!