Prerequisite – File Systems
Hierarchical Directory Systems –
Directory is maintained in the form of a tree. Each user can have as many directories as are needed so, that files can be grouped together in a natural way.
Advantages of this structure:
- Searching is efficient
- Groping capability of files increase
When the file system is organized as a directory tree, some way is needed for specifying file names.
Two different methods are commonly used:
- Absolute Path name – In this method, each file is given an absolute path name consisting of the path from the root directory to the file. As an example, the path /usr/ast/mailbox means that the root directory contains a subdirectory usr, which in turn contains a subdirectory ast, which contains the file mailbox.
Absolute path names always start at the root directory and are unique.
In UNIX the components of the path are separated by ‘/’. In Windows, the separator is ‘\’.
- Relative Path name – This is used in conjunction with the concept of the working directory (also called the current directory).A user can designate one directory as the current working directory, in which case all path names not beginning at the root directory are taken relative to the working directory.
For example, if the current working directory is /usr/ast, then the file whose absolute path is /usr/ast/mailbox can be referenced simply as mailbox.
In other words, the UNIX
command : cp /usr/ast/mailbox /usr/ast/mailbox.bak
and the command : cp mailbox mailbox.bak
do exactly the same thing if the working directory is /usr/ast.
When to use which approach?
Some programs need to access a specific file without regard to what the working directory is. In that case, they should always use absolute path names. For example, a spelling checker might need to read /usr/lib/dictionary to do its work. It should use the full, absolute path name in this case because it does not know what the working directory will be when it is called. The absolute path name will always work, no matter what the working directory is.
Of course, if the spelling checker needs a large number of files from /usr/lib, an alternative approach is for it to issue a system call to change its working directory to /usr/lib, and then use just dictionary as the first parameter to open. By explicitly changing the working directory, it knows for sure where it is in the directory tree, so it can then use relative paths.
- Operating Systems | Set 1
- Operating Systems | Set 2
- Operating Systems | Set 3
- Operating Systems | Set 4
- Operating System | Critical Section
- Operating Systems | Set 5
- Operating Systems | Set 6
- Operating Systems | Set 10
- Operating Systems | Set 7
- Operating Systems | Set 8
- Operating Systems | Set 9
- Operating Systems | Set 11
- Operating Systems | Set 12
- Operating Systems | Set 13
- Operating Systems | Set 14
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : magbene