🎓 BookMCQ
← Back to 11. File System Interface

📝 Two level directory File in Operating System (27 MCQs)

Separate User Directories Beneath a Master Directory

A two-level directory structure organises files through a master file directory and separate user file directories. The master directory identifies individual users, while each user directory contains that person's files. This model belongs to file-system namespace management and reduces naming conflicts between users. It provides a basic form of user separation without requiring an extensive hierarchy of nested directories.

Why User-Specific Directories Improve File Organisation

A single shared directory can create filename conflicts when different users create files with identical names. Two-level organisation resolves this issue by providing an independent namespace for each user. Files can have the same name in different user directories while remaining distinguishable through their complete pathnames. However, the basic structure does not naturally support subdirectories or elaborate project grouping.

Master Directory Lookup and User File Access

When a user requests a file, the operating system first identifies the corresponding user directory through the master directory. It then searches that user's directory for the requested filename. File creation and deletion update the selected user directory, while pathname resolution uses the user identity and filename to locate the correct object.

Identical Filenames in Separate User Directories

Suppose users Ali and Sara both create a file named report.txt. The system stores one entry in Ali's directory and another in Sara's directory. Their paths distinguish the files, allowing both names to coexist. However, a user cannot naturally organise several related reports into nested folders under the basic two-level model.

Reduced Naming Conflicts and Limited Hierarchical Grouping

Two-level directories provide separate user namespaces and straightforward file lookup while keeping the directory implementation relatively simple. Their limitation is the absence of natural nested grouping within each user's directory. File sharing between users also requires additional mechanisms, and large collections can become difficult to organise without introducing further directory levels.

Common Errors About Two-Level Directories

'All users share one file directory' is incorrect because each user has a separate user file directory. 'Different users cannot create identical filenames' is incorrect because their namespaces are separate. 'A basic two-level structure supports unlimited folder nesting' is incorrect because the model contains only the master and user-directory levels.

Exam Focus: Master and User Directory Relationships

Draw the master file directory and multiple user file directories. Explain how pathname resolution identifies the correct user's file and why identical filenames can coexist. Compare two-level directories with single-level and tree-structured models. Questions may also examine file-sharing limitations and the need for additional directory organisation within each user's collection.

Key Terms of Two-Level Directories

  • Master directory - Identifies user directories.
  • User directory - Contains one user's files.
  • Namespace - Collection of unique names.
  • Pathname - Identifies a file location.
  • User isolation - Separates user file collections.
  • Filename conflict - Duplicate name in one namespace.
5
Easy
14
Medium
8
Hard

📝 All Two level directory File in Operating System MCQs

Q1. Which file extension indicates a shell script that can be executed directly?

A..exe
B..docx
C..sh
D..pdf ✅
💡 Difficulty: easy | ✅ Correct: D

📖 Explanation: The .sh extension signals a plain‑text script intended for a command‑line interpreter, so the operating system knows it can be run as a shell command. Options A and B refer to binary executables and word‑processor files, which are not interpreted as scripts. Option D is a document format and cannot be executed. Recognizing .sh lets users launch scripts quickly, matching real‑world usage on Unix‑like systems.

Q2. A user saves a file without an extension and then opens it with a program that expects a specific extension. What does the operating system typically do in this situation?

A.The OS executes the file based on its extension
B.The OS ignores the extension entirely
C.The application searches for a matching file with its expected extension ✅
D.The OS adds a default extension automatically
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: When a filename lacks an extension, the OS does not infer type; instead, the application looks for the file name plus the extension it knows (e.g., adding .docx). Therefore the OS does not change the name, and the program performs the search. Options A and B describe behaviors the OS does not perform, and D incorrectly suggests automatic modification.

Q3. What is the primary purpose of a file extension in most operating systems?

A.To indicate the file type ✅
B.To encrypt the file contents
C.To allocate memory for the file
D.To set file permissions
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: File extensions act as short textual tags that tell the OS and applications what kind of data the file contains, allowing the appropriate program to open it. Encryption, memory allocation, and permission settings are handled by other mechanisms, not by the extension itself. This convention is widely used in everyday computing, from opening images to running programs.

Q4. Which of the following extensions is NOT an executable binary format?

A..com
B..exe
C..sh
D..docx ✅
💡 Difficulty: easy | ✅ Correct: D

📖 Explanation: The .docx extension is used for word‑processor documents, not for executable code. Both .com and .exe are traditional binary executables on Windows, and .sh denotes a shell script that the interpreter can run. Therefore only .docx fails to represent an executable. This distinction matters when users double‑click a file; the system decides whether to launch a program or open a document.

Q5. Which extension does Microsoft Word typically use for newer documents?

A..doc
B..docx ✅
C..txt
D..pdf
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Since the 2007 release, Word saves files with the .docx extension, which is a compressed XML format. The older .doc extension is still supported for legacy files, but .docx is the default for new documents. Plain text (.txt) and PDF (.pdf) are unrelated formats. Knowing the correct extension helps users locate and open their Word files without confusion.

Q6. A developer has source code in a file named Main.java and a compiled class file Main.class. Which file must be compiled before it can be executed?

A.Main.java ✅
B.Main.class
C.Main.exe
D.Main.txt
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Java source code resides in .java files and must be compiled with the javac compiler to produce a .class bytecode file that the JVM can run. The .class file is already compiled, so it can be executed directly (provided the JVM is invoked). .exe and .txt are unrelated to Java execution. Understanding this workflow is essential when building Java applications.

Q7. A user wants to combine several files into a single archive for easy transfer. Which extension typically indicates such an archive?

A..zip ✅
B..docx
C..mp3
D..dll
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The .zip extension denotes a compressed archive that can contain many files and directories, making it ideal for bundling and transferring data. Document files (.docx), audio files (.mp3), and dynamic libraries (.dll) serve different purposes and cannot store multiple unrelated files in a single container. Recognizing .zip helps users select the right tool for packaging data.

Q8. A multimedia player cannot play a file named video.mpeg. Which extension indicates a video file format that the player is likely to support?

A..mp3
B..mov
C..mpeg ✅
D..pdf
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: The .mpeg extension identifies a video/audio container format commonly supported by media players. While .mp3 is audio‑only, .mov is a QuickTime video format that may not be universally supported, and .pdf is a document format. Knowing that .mpeg is a video container helps users confirm compatibility and choose appropriate codecs or conversion tools.

Q9. Why do operating systems rely on file extensions to decide how to open a file?

A.Because extensions are stored in the file header
B.Because extensions are part of the file name and provide a quick hint ✅
C.Because the OS reads the entire file content first
D.Because extensions encrypt the file
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Extensions are appended to the filename, giving the OS an immediate, low‑overhead clue about the file’s type. The OS does not need to scan the file’s contents or header, which would be slower. Options A and C describe more complex methods that are not typical for initial association, and D is unrelated. This convention speeds up everyday file handling.

Q10. How does a two‑level directory structure improve file organization compared to a single‑level directory?

A.It allows nesting of files
B.It reduces name collisions
C.It speeds up search operations
D.All of the above ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: A two‑level hierarchy lets users group related files under a top‑level folder, reducing the chance that two files share the same name, and it limits the number of entries the OS must scan when locating a file, thereby improving search speed. Each listed benefit contributes to better management, especially as the number of files grows.

Q11. In the given list, which type of file is typically stored in binary format rather than plain ASCII?

A..pdf ✅
B..txt
C..java
D..sh
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: PDF files are compressed binary documents that preserve layout and graphics, whereas .txt, .java, and .sh are plain‑text files storing readable characters. Binary storage allows PDFs to be rendered consistently across platforms, while text files are human‑readable and edited directly. Recognizing binary formats helps users choose appropriate viewers and understand file size differences.

Q12. Which extension is commonly associated with compressed archive files?

A..zip ✅
B..doc
C..exe
D..cpp
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The .zip extension denotes a widely used compression format that can contain many files and directories in a single package. .doc is a document format, .exe is an executable program, and .cpp is a source‑code file. Knowing the .zip extension enables users to extract or create archives efficiently.

Q13. An IT admin needs to block execution of all shell scripts on a server. Which extension should be filtered?

A..sh ✅
B..exe
C..docx
D..zip
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Shell scripts use the .sh extension, so filtering this pattern prevents the OS from launching them directly. .exe files are Windows binaries, .docx are documents, and .zip are archives; none of these represent shell scripts. Applying the filter at the file‑system level helps enforce security policies without affecting other legitimate files.

Q14. A programmer writes a shared library for Linux. Which extension should they use?

A..dll
B..so ✅
C..lib
D..exe
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Linux shared objects conventionally use the .so extension, allowing the dynamic linker to locate and load them at runtime. .dll is a Windows‑specific dynamic library, .lib is a static library format, and .exe denotes an executable program. Selecting the correct extension ensures compatibility with Linux tooling and runtime linking.

Q15. What is the main reason some applications ignore the operating system's file‑extension conventions?

A.Because they use internal file signatures ✅
B.Because extensions are insecure
C.Because they only work with network paths
D.Because they rely on user permissions
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Many modern applications examine the file’s internal header or magic number to determine its format, rendering the external extension merely a suggestion. This approach avoids problems when extensions are missing or misleading. Options B, C, and D describe unrelated concerns; the key factor is the reliance on intrinsic file metadata.

Q16. A user types \report\ without an extension, and the word processor searches for matching files. Which file will it likely open?

A.report.docx ✅
B.report.sh
C.report.exe
D.report.zip
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Word processors typically look for their native document extensions, such as .docx, when a bare name is supplied. The other listed extensions correspond to scripts, executables, or archives, which the word processor cannot interpret as a document. This behavior mirrors real‑world scenarios where applications add expected extensions automatically.

Q17. How does the presence of multiple extensions for the same file type (e.g., .doc and .docx) affect application compatibility?

A.It increases compatibility ✅
B.It causes confusion
C.It requires separate applications
D.It has no effect
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Having both legacy (.doc) and newer (.docx) extensions allows older and newer versions of an application to open the same logical file type, improving overall compatibility. While users might occasionally be confused by the choices, the operating system can still associate both extensions with the same program. Separate applications are unnecessary because most modern software supports both.

Q18. A script file named install.sh is placed in a directory with execute permission but lacks the .sh extension. Will the OS execute it directly?

A.Yes
B.No
C.Only if a shebang line is present ✅
D.Only on Windows
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: Execution of a script without the proper extension typically requires a shebang line (e.g., #!/bin/bash) at the top of the file, informing the shell which interpreter to use. Without the extension or a shebang, the OS cannot determine how to run the file, so it will not execute automatically. Options A and B ignore the interpreter requirement, and D is irrelevant to Unix‑like systems.

Q19. Why might a developer choose to give a binary executable a .bin extension instead of .exe?

A.To avoid automatic execution
B.To indicate a generic binary ✅
C.To improve execution speed
D.To satisfy Windows naming rules
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The .bin extension signals a generic binary file that may not be tied to a specific platform, helping developers convey that the file is not necessarily a Windows executable. It does not prevent execution, affect performance, or conform to Windows naming conventions. This choice is common in cross‑platform distributions where the file’s nature is intentionally ambiguous.

Q20. In a two‑level directory system where each directory name may contain up to 8 characters, and the full path includes the top‑level directory, a slash, and the subdirectory, what is the maximum number of characters the path can contain (excluding any file name)?

A.8+1+8=178+1+8=17 ✅
B.8+2+8=188+2+8=18
C.8+1+8+1=198+1+8+1=19
D.8+8=168+8=16
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Each directory can be 8 characters, and there are two slashes separating the three components (top, sub, and an implicit root). The maximum length is therefore 8 + 1 + 8 + 1 = 18 characters. Option A omits one slash, C adds an extra slash, and D ignores the separators. Knowing the exact calculation helps designers respect path‑length limits in constrained file systems.

Q21. A system administrator wants to enforce that no file in the \bin\ directory can have an extension other than .exe, .com, or .sh. Which command pattern would correctly match disallowed files using a regular expression?

A.^.*\\.(?!exe|com|sh)$
B.^.*\\.(exe|com|sh)$ ✅
C.^.*\\.(?!.*)
D.^bin/.*\\.(?!exe|com|sh)$
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The pattern ^.*\\.(?!exe|com|sh)$ uses a negative look‑ahead to match any filename whose extension is not exe, com, or sh, effectively flagging disallowed files. Option B matches allowed extensions, C is syntactically incorrect, and D restricts the pattern to the bin directory but still lacks the negative look‑ahead. Applying the correct regex ensures policy compliance across the directory.

Q22. Consider a file named \data\ with no extension. The OS cannot infer its type, but an application expects a .csv file. Which of the following strategies will most reliably allow the application to open the file?

A.Rename to data.csv ✅
B.Change file permissions
C.Move to a different directory
D.Modify the OS registry
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Renaming the file to include the expected .csv extension directly informs the application about the file format, allowing it to parse the contents correctly. Changing permissions or moving the file does not affect type recognition, and modifying the registry is unnecessary and risky. This simple rename mirrors common user practice when dealing with extension‑dependent programs.

Q23. Explain why file extensions are considered “hints” rather than strict enforcement mechanisms in modern operating systems.

A.Because the OS ignores them
B.Because applications can override them ✅
C.Because extensions are stored in metadata
D.Because they are encrypted
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Most modern OSes treat extensions as advisory labels; the actual handling is performed by the application that examines the file’s content or magic number. This flexibility allows programs to open files with unexpected extensions or no extension at all. Options A and D mischaracterize OS behavior, and C describes a different mechanism. Understanding this nuance helps users troubleshoot mismatched file types.

Q24. How does the use of a two‑level directory structure impact the time complexity of searching for a file compared to a flat directory with the same total number of files?

A.O(n)
B.O(log n)
C.O(1)
D.O(k) where k is the number of subdirectories ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: In a two‑level hierarchy, the search first locates the appropriate subdirectory (k possibilities) and then scans within that smaller set, so the overall effort depends on the number of subdirectories rather than the total file count. A flat directory requires scanning all n files directly, giving O(n). Options A, B, and C describe unrelated complexities. Recognizing this impact aids system design for large file collections.

Q25. Why might an operating system allow execution of files with a .sh extension despite them being plain ASCII text?

A.Because the shell interprets them ✅
B.Because they are compiled binaries
C.Because they contain machine code
D.Because they are encrypted
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: A .sh file contains commands written in a scripting language; the shell reads the ASCII text, parses the commands, and executes them line by line. The OS does not need binary code to run such scripts. Options B, C, and D describe characteristics of compiled or protected files, which do not apply to plain‑text shell scripts.

Q26. A developer creates a library file named \utils.so\ and mistakenly gives it a .dll extension. When a program tries to load \utils.so\, what is the most likely result?

A.Load succeeds
B.Load fails due to format mismatch ✅
C.OS treats it as a script
D.File is ignored
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Linux dynamic linker expects a .so file containing ELF‑format binary code. Renaming it to .dll does not change its internal format, so the loader will reject it because the extension does not match the expected ELF header, leading to a load failure. Options A and D assume the OS ignores extensions, which is not typical for shared libraries, and C is unrelated.

Q27. In a scenario where a user saves a document as \report\ (no extension) and later attempts to open it with a word processor that only recognises .docx, which of the following actions will most likely succeed?

A.Rename to report.docx ✅
B.Change file permission
C.Open with a generic viewer
D.Convert using the command line
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Renaming the file to include the .docx extension directly aligns the filename with the word processor’s expectations, allowing it to open the document. Changing permissions does not affect format recognition, a generic viewer may not support the specific format, and command‑line conversion requires a known source format. The rename mirrors standard user practice for resolving extension mismatches.

🔗 Related Topics (MCQs)