Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Agenda The Linux File System (chapter 4 in text) Directory Structures / Navigation Terminology / File Naming Rules Relative vs Absolute pathnames mkdir,"— Presentation transcript:

1 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

2 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.

3 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 / homeetc abc12

4 Typical UNIX Directories / Root directory (ancestor to all directories) /homeUsed to store users’ home directories /usr/binCommon utilities (commands) for user /usr/sbinCommon utilities for user administration /etcGeneral System Admin. Files (eg passwd) /varDynamic files (log files) /tmpUser’s temporary file for programs /dev Device files (terminals, printers, etc…)

5 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

6 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

7 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

8 Relative Pathnames Rules: Relative pathname does NOT begin with a slash. Following symbols can be used:.. parent directory. current directory

9 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.

10 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!!

11 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)

12 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)

13 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

14 Listing Directory Contents lsCompact listing on non-hidden files ls -aCompact listing of ALL files ls -lDetailed listing of non-hidden files ls -FDisplays symbols to mark directories and executable files ls -ldDetailed listing of specified directory ls -iDisplays i-node number (I.d. number of files)

15 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

16 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

17 chmod Command (Relative Method) Used to change the access permissions of a file or directory Format: chmod [option] [who] [operation] [permission] file chmod [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)

18 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

19 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

20 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: 111 2 = 7 8

21 Binary to Octal Relationship: OctalBinary 0000 1001 2010 3011 4100 5101 6110 7111 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

22 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 - -

23 Practical Applications of chmod 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------)

24 Practical Applications of chmod 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.

25 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

26 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

27 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

28 Setting Directory Mask Example: To set mask for newly-created directories to: r w x r - - r - - Determine octal number 1 1 1 1 0 0 1 0 0 = 744 Subtract 777 from 744 = 033 Issue command umask 033 Issue command umask to verify change

29 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]

30 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)

31 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

32 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 testfor 706640 chevy 703817 thefile Note that each file is unique since they have been assigned a different i-node number for identification.

33 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.

34 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.

35 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)

36 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.

37 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.


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

Similar presentations


Ads by Google