Skip to content

File Systems and Directory Structure

Category: Operating System Fundamentals
Type: Operating System Concept
Generated on: 2025-07-10 03:00:08
For: System Administration, Development & Technical Interviews


File Systems and Directory Structure Cheatsheet

Section titled “File Systems and Directory Structure Cheatsheet”

What is it? A file system is the method an operating system uses to organize, store, and retrieve data on a storage device (e.g., hard drive, SSD, USB drive). It provides a logical structure, allowing users and applications to access files by name rather than physical addresses. The directory structure (also known as a file system hierarchy) is the way files and directories are organized within the file system.

Why is it important? A well-organized file system is crucial for:

  • Data Management: Efficiently storing, retrieving, and managing large amounts of data.
  • Performance: Fast access to files and directories.
  • Security: Controlling access to files and directories.
  • Organization: Making it easier to find and manage files.
  • System Stability: Preventing data corruption and system crashes.
  • File: A named collection of data (e.g., a document, image, program).
  • Directory (Folder): A container that can hold files and other directories.
  • Root Directory: The top-level directory in the file system (e.g., / on Linux/macOS, C:\ on Windows).
  • Path: A sequence of directories that specifies the location of a file or directory in the file system.
    • Absolute Path: Starts from the root directory (e.g., /home/user/documents/report.txt).
    • Relative Path: Starts from the current working directory (e.g., documents/report.txt).
  • File System Metadata: Information about a file, such as its name, size, creation date, last modified date, permissions, and owner. This is typically stored in an inode (on Unix-like systems) or the Master File Table (MFT) on NTFS.
  • Inode: A data structure in Unix-like file systems that stores metadata about a file or directory. Each file has a unique inode number.
  • Block: The smallest unit of storage that a file system can allocate.
  • Mounting: The process of making a file system accessible by attaching it to a directory in the existing file system.
  • Partition: A logical division of a physical storage device.
  • File System Types: Different ways of organizing and managing data on storage devices (e.g., FAT32, NTFS, ext4, XFS, APFS).
  • Journaling: A technique used by some file systems to ensure data consistency in case of a system crash. Changes are written to a log (journal) before being applied to the main file system.

Simplified File System Structure (Linux/macOS):

/ (Root Directory)
├── bin (Essential binaries)
├── boot (Bootloader files)
├── dev (Device files)
├── etc (Configuration files)
├── home (User home directories)
│ └── user1
│ └── documents
│ └── report.txt
├── lib (System libraries)
├── media (Mount point for removable media)
├── mnt (Temporary mount point)
├── opt (Optional software packages)
├── proc (Process information)
├── root (Root user's home directory)
├── sbin (System binaries)
├── tmp (Temporary files)
├── usr (User programs and files)
└── var (Variable data, logs)

Simplified File System Structure (Windows):

C:\ (Root Directory)
├── Program Files
├── Program Files (x86)
├── Users
│ └── User1
│ └── Documents
│ └── report.txt
├── Windows
└── ...

File Access Process (simplified):

  1. User requests a file: The user (or application) specifies the file by its path (e.g., /home/user/documents/report.txt).
  2. OS parses the path: The operating system breaks down the path into its components (directories and filename).
  3. Directory lookup: The OS starts at the root directory and traverses the directory structure, using metadata (like inodes) to find the correct directory entries.
  4. File lookup: Once the OS reaches the final directory, it looks for the file name within that directory.
  5. Inode retrieval: The OS retrieves the inode associated with the file. The inode contains information about the file’s location on the storage device (the blocks where the file’s data is stored).
  6. Data retrieval: The OS reads the data from the specified blocks on the storage device.
  7. Data delivery: The OS presents the data to the user or application.

Example: Creating a file:

  1. Application requests to create a file /home/user/new_file.txt.
  2. File system checks permissions in /home/user directory.
  3. If permitted, the file system allocates a new inode.
  4. The file system allocates data blocks for the file’s content.
  5. The file system updates the directory entry for /home/user to include new_file.txt and its associated inode number.
  6. The file system updates the inode with metadata (size, timestamps, etc.).
  • Web Server: A web server uses the file system to store website files (HTML, CSS, JavaScript, images). The directory structure might reflect the website’s organization (e.g., /var/www/html/images, /var/www/html/css).
  • Database: A database system often stores its data in files on the file system. The file system is used to manage the database’s tables, indexes, and logs.
  • Version Control (Git): Git stores project files and history in a special .git directory. The file system is used to track changes and manage different versions of files.
  • Log Files: System logs and application logs are typically stored as files in the /var/log directory (on Linux/macOS) or in the C:\Windows\System32\LogFiles directory (on Windows).
  • Image Editing Software: Image editing software (e.g., Photoshop) uses the file system to open, save, and manage image files.

Example: Setting permissions on a file (Linux):

Terminal window
chmod 755 my_script.sh # Make the script executable

This command changes the permissions of the file my_script.sh to:

  • 7 (rwx): Owner has read, write, and execute permissions.
  • 5 (r-x): Group has read and execute permissions.
  • 5 (r-x): Others have read and execute permissions.
  • Disk Full: The storage device is full, preventing the creation of new files or the modification of existing ones.
    • Troubleshooting: Identify large files or directories and remove unnecessary data. Use tools like du -sh * | sort -hr (Linux/macOS) or Disk Cleanup (Windows).
  • File System Corruption: The file system metadata is damaged, leading to data loss or system instability.
    • Troubleshooting: Run file system check utilities (e.g., fsck on Linux/macOS, chkdsk on Windows). Backup data regularly.
  • Permissions Issues: Users or applications do not have the necessary permissions to access files or directories.
    • Troubleshooting: Check file permissions using ls -l (Linux/macOS) or the Security tab in file properties (Windows). Use chmod (Linux/macOS) or take ownership (Windows) to adjust permissions.
  • Slow File Access: Slow performance when accessing files.
    • Troubleshooting: Defragment the drive (Windows), check for disk errors, consider upgrading to a faster storage device (SSD).
  • Incorrect File Associations: Double-clicking a file opens the wrong application.
    • Troubleshooting: Change file associations in the operating system settings (e.g., “Default apps” in Windows, “Open with” in macOS).

Example: Fixing file system errors (Linux):

Terminal window
sudo fsck /dev/sda1 # Check and repair the file system on /dev/sda1

Example: Dealing with “Permission Denied” error:

Terminal window
sudo chown user:user my_file.txt # Change ownership to the user
sudo chmod 644 my_file.txt # Give read/write to owner, read-only to group/others
  • Q: What is a file system, and why is it important?
    • A: (See Quick Overview and Key Concepts sections). Emphasize its role in organization, performance, and security.
  • Q: Explain the difference between absolute and relative paths.
    • A: Absolute paths start from the root directory, while relative paths start from the current working directory.
  • Q: What is an inode?
    • A: An inode is a data structure in Unix-like file systems that stores metadata about a file, such as its size, permissions, and location on the disk.
  • Q: What are some common file system types?
    • A: FAT32, NTFS, ext4, XFS, APFS. Be prepared to discuss their strengths and weaknesses.
  • Q: What is journaling in a file system?
    • A: Journaling is a technique used to ensure data consistency in case of a system crash. Changes are written to a log (journal) before being applied to the main file system.
  • Q: How do you troubleshoot a “disk full” error?
    • A: (See Common Issues section). Mention identifying large files, removing unnecessary data, and potentially upgrading storage.
  • Q: How do you change file permissions in Linux?
    • A: Use the chmod command. Explain the octal representation of permissions (e.g., 755).
  • Q: What is the purpose of the /etc directory in Linux?
    • A: It contains system-wide configuration files.
  • Q: What are some advantages and disadvantages of using an SSD (Solid State Drive) compared to a traditional HDD (Hard Disk Drive)?
    • A: Advantages of SSD: Faster read/write speeds, lower latency, more durable, less power consumption. Disadvantages: Typically more expensive per GB.
  • Q: What is mounting a file system?
    • A: The process of making a file system accessible by attaching it to a directory in the existing file system. For instance, mounting a USB drive to /mnt/usb.
  • Q: Explain the difference between hard links and soft links (symbolic links) in Linux.
    • A: A hard link creates a new directory entry that points to the same inode as the original file. Multiple hard links share the same data. A soft link (symbolic link) is a special file that contains a path to another file or directory. It’s essentially a shortcut. If the original file is deleted, the soft link becomes broken.
  • Operating System Concepts (Silberschatz, Galvin, Gagne): A classic textbook covering file systems in detail.
  • The Linux Documentation Project: Provides comprehensive documentation on Linux file systems and directory structure.
  • Microsoft Documentation: Provides detailed information on Windows file systems (NTFS) and directory structure.
  • File System Forensic Analysis (Brian Carrier): A deep dive into the technical aspects of file systems for digital forensics.
  • Online tutorials and articles: Search for specific file systems (e.g., “ext4 file system tutorial”) or file system concepts (e.g., “file system journaling”).
  • man pages (Linux/macOS): Use the man command to access the manual pages for file system utilities (e.g., man fsck, man mount, man chmod).