πŸŽ“ BookMCQ
← Back to 11. File System Interface

πŸ“ File Directory overview in Operating System (15 MCQs)

Directory Structures for Organising File Names

A file directory is a file-system structure that organises names and references to files and other directories. It provides a logical organisation layer through which users and applications locate stored objects using pathnames. Directory entries commonly associate names with file identifiers or metadata structures. The operating system manages directory creation, searching, modification, and traversal while enforcing appropriate access permissions.

Why File Systems Need Hierarchical Organisation

Without directories, identifying and managing a large collection of files becomes difficult. Naming conflicts also arise when different users independently create files with identical names. Directory structures address these problems by grouping related files, separating user namespaces, and supporting logical organisation. Different directory models provide different levels of flexibility, sharing, and complexity.

Directory Entries and Pathname Resolution

When an application accesses a pathname, the operating system begins at an appropriate starting directory and searches its entries for the next component. It follows directory references until reaching the requested file or directory. Operations such as create, delete, rename, and list require directory metadata updates, permission checks, and coordination with the underlying file system.

Locating a File Through Nested Directories

Suppose a user requests /home/ali/projects/report.txt in a hierarchical file system. The operating system begins at the root directory, locates home, then ali, projects, and finally report.txt. Each directory lookup identifies the next component. This pathname structure allows files with identical names to exist in different directories without conflicting.

Searching Efficiency and Naming Flexibility

Directories improve file organisation, naming, sharing, and navigation. Large directories may require indexed or tree-based lookup structures to maintain efficient searches. Permission restrictions can prevent unauthorised traversal or modification, while symbolic links can introduce additional path-resolution steps. Directory consistency is also important because incorrect entries can make files inaccessible or leave references to missing objects.

Common Misunderstandings About Directories

'A directory contains the complete contents of every file' is incorrect because it normally stores names and references. 'Two files cannot share the same name anywhere in a system' is incorrect because separate directories can contain identical names. 'Every file system requires exactly two directory levels' is incorrect because directory models differ across systems.

Exam Focus: Directory Operations and Pathnames

Explain the purpose of directories and identify common operations such as search, create, delete, rename, and list. Trace pathname resolution through nested directories. Compare single-level, two-level, tree, acyclic-graph, and general-graph structures. Questions may also examine naming conflicts, access permissions, directory traversal, and the role of metadata references.

Key Terms of File Directories

  • Directory - Organises filesystem names.
  • Directory entry - Associates a name with an object.
  • Pathname - Identifies a filesystem location.
  • Root directory - Top-level directory.
  • Traversal - Follows directory components.
  • Metadata - Describes filesystem objects.
2
Easy
7
Medium
6
Hard

πŸ“ All File Directory overview in Operating System MCQs

Q1. Which extension represents a shell script on Unix-like systems?

A..bat
B..sh βœ…
C..exe
D..py
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: The correct answer is .sh, which signals a shell script containing commands for the command interpreter. .bat is used for Windows batch files, .exe denotes binary executables, and .py indicates Python scripts. Knowing that .sh identifies scripts lets users and the OS invoke the right interpreter, enabling the script to run correctly.

Q2. Why do operating systems rely on file extensions to determine file type?

A.To enforce security policies
B.To provide hints for applications βœ…
C.To compress files automatically
D.To encrypt data
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: Operating systems use extensions as hints so applications know how to handle a file. They do not enforce security, compress, or encrypt based on extensions. By reading the extension, the OS can launch the appropriate program, allowing users to open documents, images, or executables without manually selecting the application each time.

Q3. How does a .exe file differ from a .obj file regarding execution readiness?

A..exe is source code, .obj is compiled
B..exe is fully linked binary, .obj is compiled object not yet linked βœ…
C.Both are plain text files
D.Both are archive files
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: A .exe file contains a fully linked binary ready for the processor to execute directly. In contrast, a .obj file holds compiled machine code that still requires linking with other objects or libraries to become executable. This distinction explains why .exe can be run immediately, while .obj must be combined into an executable first.

Q4. If an application expects a .pdf file but the user omits the extension, what typically happens?

A.The OS refuses to open the file
B.The application searches for a default extension βœ…
C.The file becomes corrupted
D.The file becomes read‑only
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: When the extension is missing, the application often tries adding its expected extension (e.g., .pdf) to locate the correct file. The operating system does not reject the file, nor does the omission corrupt or lock it. This behavior allows the program to find and open the intended document despite the user's shorthand naming.

Q5. Why are compound extensions like .tar.gz used, and how does the OS process them?

A.They indicate a file is both an archive and compressed; the OS first decompresses then extracts βœ…
B.They are decorative and have no functional impact
C.They tell the OS to encrypt the file
D.They cause the OS to ignore the file
πŸ’‘ Difficulty: hard | βœ… Correct: A

πŸ“– Explanation: Compound extensions convey two processing steps: .tar denotes an archive of multiple files, and .gz indicates compression. The operating system (or utilities) first decompress the .gz layer, then extract the .tar archive to retrieve the original files. Understanding this sequence is essential for correctly handling packaged data.

Q6. How does using extensions as β€œhints” affect file sharing across different platforms?

A.It guarantees identical behavior on all systems
B.It may cause incompatibility if the receiving OS does not recognize the extension βœ…
C.It encrypts the file for security
D.It automatically converts the file format
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: Extensions act as clues for applications, but not all operating systems recognize every extension. When sharing files, a platform that lacks an associated program may not know how to open the file, leading to compatibility issues. Therefore, relying solely on extensions can hinder cross‑platform usability unless the appropriate software is installed.

Q7. A user saved a script named \backup\ without an extension on Linux. Which command must they run to make it executable?

A.chmod +x backup βœ…
B.chmod 777 backup
C.chmod -x backup
D.chmod r+w backup
πŸ’‘ Difficulty: easy | βœ… Correct: A

πŸ“– Explanation: The chmod +x command adds the executable permission to the file, allowing the shell to run it as a program. The other options either grant excessive permissions, remove execution rights, or modify read/write bits incorrectly. Setting the executable flag is necessary for the OS to treat the script as runnable code.

Q8. A developer has files: main.c, utils.o, libmath.so. Which extensions indicate files ready for linking into an executable?

A..c only
B..o and .so βœ…
C..c and .so
D.All three
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: Object files (.o) and shared libraries (.so) contain compiled code that can be linked to form an executable. The source file (.c) still needs compilation. Therefore, .o and .so are the ready-to-link components, while .c must be transformed first. Recognizing these extensions helps developers manage the build process efficiently.

Q9. A system administrator receives a file named \report\ with no extension, but expects it to be a PDF. Which method should they use to verify the file type?

A.Open it with Microsoft Word
B.Run the file command in the terminal βœ…
C.Rename it to report.pdf and open it
D.Assume it is a text file
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: The file command examines the file’s header bytes to identify its format regardless of the name. Opening with Word may fail, renaming does not change content, and assuming it is text could be wrong. Using the file utility provides a reliable way to confirm whether the data matches a PDF structure.

Q10. In a mixed Windows/Linux environment, a shared archive is named \data.zip\. Linux users need to extract it while preserving executable permissions. Which approach ensures permissions are retained?

A.Use unzip with -X option
B.Convert the archive to .tar.gz and use tar with --preserve-permissions βœ…
C.Rename the file to .exe and run it
D.Copy the file to a Windows machine first
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: ZIP archives do not store Unix permission bits reliably. Converting to a tarball compressed with gzip (.tar.gz) and extracting with tar --preserve-permissions retains the original execute bits. The unzip -X option may help but is not as reliable across systems. Preserving permissions is crucial for scripts and binaries to run after extraction.

Q11. A programmer mistakenly names Java source files with a .txt extension and runs javac. What is the outcome, and how can they compile without renaming?

A.javac compiles them anyway
B.javac reports an error because it ignores non‑.java files βœ…
C.javac compiles but produces .class files with .txt names
D.javac treats them as comments
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: The Java compiler only processes files ending in .java; therefore it will not compile the .txt files and will display an error. To compile them without renaming, the programmer must either rename the files to .java or use a build tool that can specify source file names, but direct compilation with javac requires the correct extension.

Q12. Which mechanism does an operating system typically use to associate file extensions with the appropriate program?

A.Environment variables
B.MIME types
C.PATH variable βœ…
D.User permissions
πŸ’‘ Difficulty: medium | βœ… Correct: C

πŸ“– Explanation: MIME types map extensions to applications, allowing the OS to launch the correct program when a file is opened. While the PATH variable locates executables and environment variables store settings, they do not directly link extensions to programs. Understanding MIME type associations helps users configure default applications for various file types.

Q13. A backup script copies .docx, .pdf, and .exe files into a directory, but later users cannot run the .exe files. What is the most likely cause?

A.The files were copied without execute permission βœ…
B.The extensions were changed during copying
C.The operating system does not support .exe files
D.The files became corrupted
πŸ’‘ Difficulty: hard | βœ… Correct: A

πŸ“– Explanation: When files are transferred, especially from non‑Windows systems, the execute bit may be cleared, preventing the OS from running .exe binaries. Changing extensions or OS incompatibility would not stop execution if the files were intact, and corruption would affect all files, not just executables.

Q14. Among files with extensions .mp3, .jpg, .zip, and .sh, which is most likely to be directly executed by the operating system?

A..mp3
B..jpg
C..zip
D..sh βœ…
πŸ’‘ Difficulty: medium | βœ… Correct: D

πŸ“– Explanation: A shell script (.sh) contains commands that the OS can interpret and run directly, whereas media files (.mp3, .jpg) and archive files (.zip) require specific applications to open them. Recognizing .sh as an executable script helps users know which files can be launched without additional software.

Q15. An IT policy mandates that all executable files must have extensions .exe, .com, or .bat. A new binary arrives without any extension. Which step best ensures compliance while keeping the file functional?

A.Rename the file to have a .exe extension βœ…
B.Create a wrapper script that calls the binary
C.Change only the file permissions to executable
D.Add a .txt extension to the file name
πŸ’‘ Difficulty: hard | βœ… Correct: A

πŸ“– Explanation: Renaming the binary to include a permitted executable extension satisfies the policy and allows the OS to recognize it as runnable. A wrapper script adds complexity, changing permissions alone does not address the naming rule, and adding .txt would misclassify the file, preventing execution.

πŸ”— Related Topics (MCQs)