Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Aptitude
  • Engineering Mathematics
  • Discrete Mathematics
  • Operating System
  • DBMS
  • Computer Networks
  • Digital Logic and Design
  • C Programming
  • Data Structures
  • Algorithms
  • Theory of Computation
  • Compiler Design
  • Computer Org and Architecture
Open In App
Next Article:
Structures of Directory in Operating System
Next article icon

Structures of Directory in Operating System

Last Updated : 27 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

A directory is a container that is used to contain folders and files. It organizes files and folders in a hierarchical manner. In other words, directories are like folders that help organize files on a computer. Just like you use folders to keep your papers and documents in order, the operating system uses directories to keep track of files and where they are stored. Different structures of directories can be used to organize these files, making it easier to find and manage them.

Understanding these directory structures is important because it helps in efficiently organizing and accessing files on your computer. Following are the logical structures of a directory, each providing a solution to the problem faced in the previous type of directory structure.  

Directory in operating system

Different Types of Directory in OS

In an operating system, there are different types of directory structures that help organize and manage files efficiently.

Directories in an OS can be single-level, two-level, or hierarchical. To gain a comprehensive understanding of file systems, explore the GATE CS Self-Paced Course which covers operating systems in great detail.

Each type of directory has its own way of arranging files and directories, offering unique benefits and features.These are:

  • Single-Level Directory
  • Two-Level Directory
  • Tree Structure/ Hierarchical Structure
  • Acyclic Graph Structure
  • General-Graph Directory Structure

1) Single-Level Directory

 The single-level directory is the simplest directory structure. In it, all files are contained in the same directory which makes it easy to support and understand. 

A single level directory has a significant limitation, however, when the number of files increases or when the system has more than one user. Since all the files are in the same directory, they must have a unique name. If two users call their dataset test, then the unique name rule violated.

Single Level Directory

Advantages

  • Since it is a single directory, so its implementation is very easy.
  • If the files are smaller in size, searching will become faster.
  • The operations like file creation, searching, deletion, updating are very easy in such a directory structure.
  • Logical Organization : Directory structures help to logically organize files and directories in a hierarchical structure. This provides an easy way to navigate and manage files, making it easier for users to access the data they need.
  • Increased Efficiency: Directory structures can increase the efficiency of the file system by reducing the time required to search for files. This is because directory structures are optimized for fast file access, allowing users to quickly locate the file they need.
  • Improved Security : Directory structures can provide better security for files by allowing access to be restricted at the directory level. This helps to prevent unauthorized access to sensitive data and ensures that important files are protected.
  • Facilitates Backup and Recovery : Directory structures make it easier to backup and recover files in the event of a system failure or data loss. By storing related files in the same directory, it is easier to locate and backup all the files that need to be protected.
  • Scalability: Directory structures are scalable, making it easy to add new directories and files as needed. This helps to accommodate growth in the system and makes it easier to manage large amounts of data.

Disadvantages

  • There may chance of name collision because two files can have the same name.
  • Searching will become time taking if the directory is large.
  • This can not group the same type of files together.

2) Two-Level Directory

As we have seen, a single level directory often leads to confusion of files names among different users. The solution to this problem is to create a separate directory for each user. 

In the two-level directory structure, each user has their own user files directory (UFD). The UFDs have similar structures, but each lists only the files of a single user. System's master file directory (MFD) is searched whenever a new user id is created.

Two Level Directory
Two-Levels Directory Structure

Advantages

  • The main advantage is there can be more than two files with same name, and would be very helpful if there are multiple users.
  • A security would be there which would prevent user to access other user's files.
  • Searching of the files becomes very easy in this directory structure.

Disadvantages

  • As there is advantage of security, there is also disadvantage that the user cannot share the file with the other users.
  • Unlike the advantage users can create their own files, users don't have the ability to create subdirectories.
  • Scalability is not possible because one user can't group the same types of files together.

3) Tree Structure/ Hierarchical Structure 

Tree directory structure of operating system is most commonly used in our personal computers. User can create files and subdirectories too, which was a disadvantage in the previous directory structures. 

This directory structure resembles a real tree upside down, where the root directory is at the peak. This root contains all the directories for each user. The users can create subdirectories and even store files in their directory. 

A user do not have access to the root directory data and cannot modify it. And, even in this directory the user do not have access to other user's directories.  The structure of tree directory is given below which shows how there are files and subdirectories in each user's directory. 

Tree Structure Directory
Tree/Hierarchical Directory Structure

Advantages

  • This directory structure allows subdirectories inside a directory.
  • The searching is easier.
  • File sorting of important and unimportant becomes easier.
  • This directory is more scalable than the other two directory structures explained.

Disadvantages

  • As the user isn't allowed to access other user's directory, this prevents the file sharing among users.
  • As the user has the capability to make subdirectories, if the number of subdirectories increase the searching may become complicated.
  • Users cannot modify the root directory data.
  • If files do not fit in one, they might have to be fit into other directories.

4) Acyclic Graph Structure

As we have seen the above three directory structures, where none of them have the capability to access one file from multiple directories. The file or the subdirectory could be accessed through the directory it was present in, but not from the other directory. 

This problem is solved in acyclic graph directory structure, where a file in one directory can be accessed from multiple directories. In this way, the files could be shared in between the users. It is designed in a way that multiple directories point to a particular directory or file with the help of links. 

In the below figure, this explanation can be nicely observed, where a file is shared between multiple users. If any user makes a change, it would be reflected to both the users. 

Acyclic group structure
Acyclic Graph Structure

Advantages

  • Sharing of files and directories is allowed between multiple users.
  • Searching becomes too easy.
  • Flexibility is increased as file sharing and editing access is there for multiple users.

Disadvantages

  • Because of the complex structure it has, it is difficult to implement this directory structure.
  • The user must be very cautious to edit or even deletion of file as the file is accessed by multiple users.
  • If we need to delete the file, then we need to delete all the references of the file inorder to delete it permanently.

5) General-Graph Directory Structure

Unlike the acyclic-graph directory, which avoids loops, the general-graph directory can have cycles, meaning a directory can contain paths that loop back to the starting point. This can make navigating and managing files more complex.

General Graph directory
General Graph Directory Structure

In the above image, you can see that a cycle is formed in the User 2 directory. While this structure offers more flexibility, it is also more complicated to implement.

Advantages of General-Graph Directory

  • More flexible than other directory structures.
  • Allows cycles, meaning directories can loop back to each other.

Disadvantages of General-Graph Directory

  • More expensive to implement compared to other solutions.
  • Requires garbage collection to manage and clean up unused files and directories.

Conclusion

Understanding the different directory structures in an operating system is important for efficient file organization and management. Each structure, whether single-level, two-level, tree-structured, acyclic graph, or general graph, offers unique ways to arrange and access files. Choosing the right directory structure helps ensure that files are easy to find, use, and maintain.


Next Article
Structures of Directory in Operating System

A

AshishVishwakarma1
Improve
Article Tags :
  • Operating Systems
  • GATE CS
  • Operating Systems-Input Output Systems

Similar Reads

    Operating Systems Structures
    The operating system can be implemented with the help of various structures. The structure of the OS depends mainly on how the various standard components of the operating system are interconnected and merge into the kernel. This article discusses a variety of operating system implementation structu
    8 min read
    Directory Implementation in Operating System
    Directory implementation in the operating system can be done using Singly Linked List and Hash table. The efficiency, reliability, and performance of a file system are greatly affected by the selection of directory-allocation and directory-management algorithms. There are numerous ways in which the
    5 min read
    File Systems in Operating System
    A computer file is defined as a medium used for saving and managing data in the computer system. The data stored in the computer system is completely in digital format, although there can be various types of files that help us to store the data.File systems are a crucial part of any operating system
    8 min read
    Inode in Operating System
    In Unix-based operating systems, each file is identified by an Inode, which stands for Index Node. Inodes are special data structures created when the file system is initialized. The total number of inodes determines the maximum number of files and directories that the file system can hold.An inode
    5 min read
    Free Space Management in Operating System
    Free space management is a critical aspect of operating systems as it involves managing the available storage space on the hard disk or other secondary storage devices. The operating system uses various techniques to manage free space and optimize the use of storage devices. Here are some of the com
    7 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences