Presentation is loading. Please wait.

Presentation is loading. Please wait.

The file structure and related utilities CS240 Computer Science II.

Similar presentations

Presentation on theme: "The file structure and related utilities CS240 Computer Science II."— Presentation transcript:

1 The file structure and related utilities CS240 Computer Science II

2 The hierarchical or tree file structure

3 Typical UNIX hierarchical or tree file structure


5 Typical contents of various directories / (root): the top of the file hierarchy /export/home: usually contains all users’ subdirectories. /usr: traditionally contains subdirectories that keep system information. /usr/bin: usually contains the standard Unix utilities. /usr/sbin: contains utilities for system administration. /etc: keeps configuration and other administration files, e.g., /etc/passwd contains a list of all users. /var: contains files that vary as the system runs, e.g., users’ mailbox files, system log files, etc. /dev: contains information about peripheral devices. /tmp: used by programs to hold temporary files.

6 Directory or file name Directory or file folder may hold files and sub- directories. A file or directory name is case-sensitive and may be up from 14 to 255 characters (depending on the system). Allowable characters include A-Z, a-z, 0-9, “_”, “.”, and “,”. ls –a utility displays all files, including hidden ones (those files whose name begin with a “.”), in a directory. ls –F utility displays directories with / as the last character.

7 Directories Working or current directory: pwd utility displays your current (present) working directory. Home directory is usually your logging directory. It contains an important file named.profile (Bourne or Korn shell) or.login (C-shell) known as the start-up file. the start-up file contains shell commands and variables that customize a user’s work environment.

8 The mkdir utility mkdir create a directory. It automatically puts two entries in every directory that you create: the “.” and “..”, representing the directory itself and its parent directory. –the “.” is synonymous with the pathname of the working directory. –the “..” is synonymous with the pathname of the parent of the working directory.

9 The cd utility cd without argument makes home directory your working directory. cd.. moves you from you present working directory to its parent directory. cd pathname moves you to the pathname that you specify.

10 The rmdir utility rmdir removes or deletes a directory that is empty (no files or sub-directories in it.). If the directory is not empty, you must use rm utility to first remove all files.

11 Relative pathname $ pwd /faculty/ewh $ mkdir CS240# relative to present # working directory $ pwd /faculty/ewh/CS240 $ mkdir /faculty/ewh/CS240# absolute #pathname is # specified Note that you can use either relative or absolute pathname in virtually anywhere that requires a filename or pathname for other utilities such as cd, ls, vi, mkdir, rm, etc.

12 Examples of using pathnames Assuming /faculty/ewh is the present working directory. $ cp abstract CS480/Seminars/abstract.2002 $ vi CS480/Seminars/abstract.2002 $ cd CS480/Seminars $ pwd /faculty/ewh/CS480/Seminars $ vi abstract.2002 $ cd..

13 The mv utility the mv can be used to rename a file. The mv can also be used to move files from one directory to another. –mv existing-file-list directory The following command moves the prog1 and prog2 files from their present working directory to its child CS240 sub-directory. $ mv prog1 prog2 CS240

14 Access permissions Three types of users –the owner of a file –a member of the owner’s group –anyone else Three types of access –read –write –execute So, there can be nine different combinations.

15 Access permissions continued $ ls –l prog1.cpp - r w - r - - r - - 1 ewh faculty 524 Nov 8 17:52 prog1.cpp -the type of the file (first character) -the file’s access permission (next 9 characters) -r (read), w (write), x (execute), and - (no permission) -In the 9-character group -first three: owner -next three: group -last three: anyone else -the number of links to the file -the name of the owner of the file -the name of the group that has group access -the size of the file in bytes -the date and time the file was created or last modified -the name of the file

16 The chmod utility “+” adds and “-” removes a permission “a”: all users; “u”: owner; “o”: other, “g”: group. A superuser (usually system administrator) can have full access to all files. $ chmod a+aw prog1.cpp# adds read/write to all $ ls –l prog1.cpp - r w - r w - r w - 1 ewh faculty 524 Nov 8 17:52 prog1.cpp

17 Directory access permission Since a directory is not a file, it cannot be executed. Execution right of a directory has been defined as the right to search through the directory. The command below grants all users with permission to look through, read, write and remove all files from Dr. Hu’s CS240 directory. $ chmod a+rwx /faculty/ewh/CS240 To view the access permission of a subdirectory, one can use ls with -d option. $ ls -ld /faculty/ewh/CS240

18 Link: a pointer to a file Everytime a file is created, a pointer which is associated with the filename and points to the file is stored in a directory. The same file can be shared by creating additional links with the ln utility.

19 The ln utility Issuing a the following command in Dr. Hu’s home directory to share the prog1.cpp file in Dr. Hu’s home directory (/faculty/ewh/prog1.cpp); a new link will appear in Dr. Najarian’s directory /faculty/najarian $ ln prog1.cpp /faculty/najarian/newname.cpp Note –the filename may differ, but both refer to the same physical file –file status information such as access permission. owner, and the time the file was last modified is the same for all links! the rm utility removes a link. When the last link is removed, the files is deleted the operating system releases the storage space used by the file. links or pointers to a file may be placed in different directories of the same user. It is not possible to create links between different file systems.

20 Symbolic link The link just described that directly points to a file is known as the hard link. Only the superuser can create a hard link to a directory. A symbolic link in an indirect pointer; it is a driectory entry that contains the pathname of the pointed-to file. Anyone can create a symbolic link to a directory. A symbolic link can link to any file regardless of where the file is located in the file structure. To create a symbolic link, use the -s option of the ln utility. to create s symbolic link to a directory, use the -s option the the ln utility. Note that the pwd utility does not recognize the symbolic link; it only recognizes the linked-to directory.

Download ppt "The file structure and related utilities CS240 Computer Science II."

Similar presentations

Ads by Google