agenda the linux file system (chapter 4 in text) directory structures / navigation terminology /...

37
Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir, mkdir -p, rmdir, rm -r ls, ls -a, ls -F, ls -l, ls -ld Setting Access Permissions chmod / umask Linking Files Hard Links / Symbolic Links

Upload: stephen-bryan

Post on 17-Dec-2015

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Agenda

The Linux File System (chapter 4 in text) Directory Structures / Navigation

Terminology / File Naming Rules Relative vs Absolute pathnames mkdir, mkdir -p, rmdir, rm -r ls, ls -a, ls -F, ls -l, ls -ld

Setting Access Permissions chmod / umask

Linking Files Hard Links / Symbolic Links

Page 2: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

File System A File System is a structure used to

organize programs and data on a computer’s storage device

Linux (Unix) OS has a special file called a directory file used to store ordinary files as well as other “directories”

Directories allow a computer’s file system to be better organized.

Page 3: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Hierarchical File System In the Linux (Unix) OS, the “root

directory” / is the starting directory, and other “child directories”, “grandchild directories” …etc. are created

The hierarchical structure resembles an “upside-down tree”

root /

home etc

a b c 1 2

Page 4: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Typical UNIX Directories / Root directory (ancestor to all directories) /homeUsed to store users’ home directories /usr/bin Common utilities (commands) for user /usr/sbin Common utilities for user administration /etc General System Admin. Files (eg passwd) /var Dynamic files (log files) /tmp User’s temporary file for programs

/dev Device files (terminals, printers, etc…)

Page 5: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

File Naming Rules The following rules apply to naming

ordinary files or “directory files”: Some file systems restrict filename size to 14

characters, other file systems allow for 255 characters (best to select filename size of 14)

Can use letters (upper & lower case), numbers, period , comma or underscore _ characters

Upper case different than lower case Period at beginning of filename hides file

Page 6: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Pathnames A pathname is a listing of

directories that will lead to a directory or a file.

Examples: Directory pathname:

/home/username/ics124/assignments

File pathname: /home/username/ops224/assignments/assn1.txt

Page 7: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Absolute vs Relative Pathnames

Absolute Pathname A pathname that begins from root. The pathname usually begins with a slash / or

~ eg. /home/msaul/ops224 ~/ics124/sample_tests

(where ~ represents /home/username)

Relative Pathname A pathname that is “relative” to the location

of another directory

Page 8: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Relative Pathnames Rules:

Relative pathname does NOT begin with a slash.

Following symbols can be used: .. parent directory . current directory

Page 9: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Relative Pathnames Examples:

Change to another directory branch from parent directory: cd ../ops224

copy sample.c file from your professor’s directory to your current directory:cp /home/profid/oop244/sample.c .

Page 10: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Making Directories

Building directories is similar in approach to building a house Begins from a foundation (eg home

directory) Need to build in proper order (add on

addition to house in right location) when building directories from different

locations, must provide proper absolute or relative pathname!!

Page 11: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Where do we want to build directory?

Want to build a directory called tmp that branches-off of your home directory

Verify which directory you are located (either look at directory from command prompt or issue the command pwd

Type mkdir tmp at the Unix prompt, followed by ENTER

Always verify that directory has been created (e.g. use ls or ls -ld command)

Page 12: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Creating Parent Directories

To create directory paths with parent directories that do not exist you can use the command mkdir -p pathname eg. Mkdir -p mur/dir1 (This would create the parent

directory mur and then the child directory dir1)

Page 13: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Removing Directories

Removing directories is reverse order of building directories

Issue command rmdir Cannot remove directories containing files

or other subdirectories (unless using rm -r)

Need to “step-back” to at least parent directory to remove empty directory or related child, grandchild, etc… directories

Page 14: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Listing Directory Contents

ls Compact listing on non-hidden files ls -a Compact listing of ALL files ls -l Detailed listing of non-hidden files ls -F Displays symbols to mark directories

and executable files ls -ld Detailed listing of specified directory ls -i Displays i-node number

(I.d. number of files)

Page 15: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Access Permissions Limiting unauthorized access to your

directories and files is a very important concern for ALL Linux (Unix) users.

Consequences of Unauthorized Access: Copying your assignments (cheating) Using your account for illegal activity Using your account to send obscene

messages Tampering with files

Page 16: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

File / Directory Permissions

The Linux (Unix) OS can allow the user to specify read, write and execute permissions to the user, group or all others (UGO) for files.

A user can also specify read, write and execute permissions for a directory. The execute permission for a directory allows the person to view files in that directory

Page 17: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

chmod Command(Relative Method)

Used to change the access permissions of a file or directory

Format:

chmod [option] [who] [operation] [permission] filechmod [option] [permission] file-list

who relates to user (u) , group (g) or all others (o) operation relates to adding (+), removing (-) or

setting (=) permissions permissions are read (r), write (w) and execute (x)

Page 18: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

chmod Command(Relative Method)

Examples: Add Permission

chmod g+rw file.name chmod o+x file.name

Remove Permission chmod g-w file.name chmod a-w file.name (removes write for ugo)

Set Permission chmod o=rx file.name chmod go=rx filename

Note: you can use wildcard symbols (eg *) to match particular files

Page 19: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

chmod Command(Absolute Method)

You can use the chmod command with octal number to represent (in binary) a permission (1) or removal of a permission (0) for the file or directory

This is referred to as an Absolute command, and many prefer this “short-cut” method to changing file / directory permissions

Page 20: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Relationship of a Binary to an Octal Number

Notice the Pattern: Largest 3 digit binary is 111 1 octal digit will represent a 3 digit

binary number Highest Octal digit is 7

Therefore: 1112 = 78

Page 21: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Binary to Octal

Relationship:Octal Binary0 0001 0012 0103 0114 1005 1016 1107 111

Therefore:

Octal number 755 is equal to:

1 1 1 1 0 1 1 0 1 in binary

This can be related to the permissions:

r w x r - x r - x

Page 22: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

chmod - Example(Absolute Method)

Applying octal values of rwx use the absolute chmod command:

chmod 777 filename- r w x r w x r w x chmod 755 filename - r w x r - x r - x chmod 711 filename- r w x - - x - - x chmod 644 filename- r w - r - - r - -

Page 23: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Practical Applications ofchmod Command

Pass-Through Permissions Pass-Through Permissions allow users to

pass-through the home directories and other subdirectories until they reach a directory that provides read and execute permissions to read files. (pass-through permissions drwx--x--x)

To deny any access other than yourself, you can remove pass-through permissions of your home directory (drwx------)

Page 24: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Practical Applications ofchmod Command

Linking & Sharing Files Set up directory and file permissions to allow

users to modify a file or set up permissions of file to allow user to view, but not modify a file.

Webpages Allow or deny other access to files. For

example, use chmod command to allow group & others read and execute permissions to “pass-through” your directories.

Page 25: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Creating a Mask Are you tired of continually changing access

permissions for newly-created files or directories?

The umask command automatically sets the file permissions upon creation of the file.

This process is useful, since user may sometimes forget to change the permissions of newly-created files or when they transfer files via the FTP application

Page 26: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

umask Command Used to automatically establish file

permission upon creation

Format: umask [mask] where mask represents a 3-digit octal

number regarding UGO and permissions to be assigned.

Note: The rules vary between setting file masks and directory masks

Page 27: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Setting Directory Mask To change directory mask:

Determine octal number that would set directory permission

Subtract octal number 777 from octal number determined above to get result

issue the command : umask [octal number]

Note: should also be able to use “relative method” with umask command - may be easier

Page 28: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Setting Directory Mask Example:

To set mask for newly-created directories to:r w x r - - r - -

Determine octal number1 1 1 1 0 0 1 0 0 = 744

Subtract 777 from 744 = 033 Issue command umask 033 Issue command umask to verify change

Page 29: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Setting File Mask To change directory mask:

Determine binary number that would set directory permission

Subtract above binary number from 110110110 and convert result to octal number to determine umask value

issue the command : umask [octal number]

Page 30: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Setting File Mask - Example1

Example: To set mask for newly-created files to:

r w - r - - r - - Convert to binary

110100100 Subtract above from 110110110

110110110 - 110100100= 000010010 (which is 022)

issue umask 022 (enter umask to verify)

Page 31: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Setting File Mask - Example2

Example: To set mask for newly-created files to:

r w x r - - r - - Convert to binary

111100100 Subtract above from 110110110

110110110 - 111100100= 000010010 (which is 022 octal)

issue umask 022 (enter umask to verify)

Cannot subtract 1 from 0

Page 32: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

File Identification Files in UNIX and Linux contain contents

(e.g. source code) but each file also contains information regarding the file itself.

Each file is assigned a i-node number. To view i-node information, you can issue the UNIX command ls -i

705900 testfor706640 chevy703817 thefile

Note that each file is unique since they have been assigned a differenti-node number for identification.

Page 33: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Linking Files Since UNIX is a multi-user operating

system, it makes sense to allow users to share files to collaborate on projects (such as programming projects, reports, etc.)

In order to avoid duplication and inefficiency, it is better to provide links between files to give user illusion that what is edited on their file affects contents on other groups’ files.

Page 34: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Linking Files

There are two major types of links:Hard Link: ln [existing_file] [linked_file]

A directory entry containing the same “i-node number” of a file. All files have at least one hard-link - when removed, the link is removed

Symbolic Link: ln -s [existing_file] [linked_file] A directory entry containing pathname to file

(i.e. a pointer). Unlike hard links, i-node numbers can be different, but possess other useful features.

Page 35: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Linking Files Remember to set appropriate

permissions for: your directories (such as pass-

through permissions and permissions for appropriate directory)

the file to link (which groups can modify the link file, which groups can view, but not modify file, and which groups are not permitted to modify or view linked file)

Page 36: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Hard Link Features Cannot make hard links to directories Cannot cross different file systems (since

other file system may use i-node number for a already existing file…)

User can allow access to file to link via directory access permissions and will still allow access if user later block group & other access.

When “original file” that other user’s linked to is removed “linked file(s)’ will still exist.

Page 37: Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,

Soft Link Features Can be used by users to link

directories Can link across different file

systems since they are considered to be “pointers”

“Broken Links” can occur if original file is removed and link “points” to a file that does not exist.