🎓 BookMCQ
← Back to 11. File System Interface

📝 Tree structured file directories in Operating System (20 MCQs)

Hierarchical Parent-Child Directory Organisation

A tree-structured directory system organises files and directories into a hierarchy beginning at a single root directory. Each directory can contain files and additional subdirectories, forming parent-child relationships. This structure supports logical grouping, pathname-based navigation, and separation of unrelated collections. Operating systems use tree-based directory organisation to manage large file collections and provide predictable locations for user and system data.

Why Hierarchical Grouping Simplifies Large File Collections

Flat directory structures become difficult to manage when thousands of unrelated files share one namespace. Tree organisation allows users to divide information into meaningful categories, projects, and subfolders. Identical filenames can exist in different directories because their full pathnames differ. The structure also supports directory-specific permissions and more manageable administration.

Path Traversal Through Parent and Child Directories

The operating system begins pathname resolution at the root or current working directory. It examines each path component, locates the corresponding directory entry, and follows the child-directory reference until reaching the target file. Directories commonly maintain references to filesystem objects, while metadata identifies permissions, ownership, and other properties required during traversal.

Locating a File in a Three-Level Hierarchy

Suppose a directory tree contains /home/ali/documents/notes.txt. The system starts at root, enters home, follows ali, then documents, and finally identifies notes.txt. Another file named notes.txt can exist under /home/sara/documents without a naming conflict because its full pathname is different.

Flexible Organisation and Directory-Management Costs

Tree directories provide scalable organisation, clear pathname resolution, and convenient permission management. However, users may encounter long paths and duplicated information when similar content must appear in different branches. Sharing files across branches requires links or other references. Moving directories can also change pathnames and affect applications that depend on fixed locations.

Clarifying Tree Hierarchy and File Sharing

'A tree directory permits a directory to have multiple parents' is incorrect because each node has one parent except the root. 'Identical filenames are forbidden throughout the tree' is incorrect because uniqueness applies within each directory. 'Every directory must contain another directory' is incorrect because a directory may contain only files or remain empty.

Exam Focus: Rooted Trees and Pathname Resolution

Draw hierarchical directory trees and identify roots, parents, children, and leaf files. Trace absolute and relative pathnames through the directory structure. Determine whether identical names conflict based on their parent directories. Compare tree structures with acyclic graphs and general graphs, particularly in parent relationships and file-sharing support.

Key Terms of Tree-Structured Directories

  • Root - Top-level directory.
  • Parent - Directory containing another entry.
  • Child - Entry inside a directory.
  • Absolute path - Path beginning at root.
  • Relative path - Path from current directory.
  • Leaf - Entry without child directories.
5
Easy
9
Medium
6
Hard

📝 All Tree structured file directories in Operating System MCQs

Q1. Which file extension is commonly used for Microsoft Word documents that use the newer Office format?

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

📖 Explanation: The modern Office format for Word documents uses the .docx extension, so selecting .docx opens the file correctly in Word. The older .doc extension belongs to legacy Word files, .txt denotes plain text, and .pdf is a portable document format that Word does not treat as a native editable file. In real‑world use, choosing the correct extension ensures the right program launches and the document retains its formatting.

Q2. What is the standard extension for compiled Java bytecode files?

A..java
B..class ✅
C..jar
D..jvm
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Compiled Java bytecode is stored in files with the .class extension, which the Java Virtual Machine loads and executes. The .java extension refers to source code, .jar is an archive of many .class files, and .jvm is not a standard Java file type. Knowing the correct extension lets developers locate executable classes and run them without confusion.

Q3. Why do operating systems rely on file extensions to determine which application should open a file?

A.They store metadata
B.They act as hints ✅
C.They encrypt the file
D.They define file size
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: File extensions act as simple hints that tell the OS which registered program is associated with a particular type, so the correct application launches automatically. Storing metadata, encrypting files, or defining size are unrelated to the selection process. In everyday computing, this convention saves users from manually choosing programs each time they double‑click a file.

Q4. How does a tree-structured directory hierarchy reduce name collisions compared to a flat file namespace?

A.By grouping files
B.By using unique IDs
C.By allowing same names in different branches ✅
D.By sorting alphabetically
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: A hierarchical tree lets identical filenames exist in separate branches, preventing collisions that would occur in a single‑level folder where each name must be unique. Grouping alone does not guarantee uniqueness, unique IDs are not required, and alphabetical sorting does not affect naming rules. In practice, developers organize projects into subfolders so that files like README.txt can appear in many modules without conflict.

Q5. Which statement best describes the relationship between a .exe extension and the type of code it contains?

A..exe contains source code
B..exe contains binary machine code ✅
C..exe contains script
D..exe contains HTML
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The .exe extension signals a binary executable that the operating system can load directly into memory and run as machine code. It does not contain human‑readable source, scripting language, or HTML markup. Recognizing this helps users understand that double‑clicking a .exe launches a program, whereas .sh scripts require a shell interpreter.

Q6. Why might an application ignore the operating system's file extension and enforce its own naming convention?

A.Because OS extensions are mandatory
B.Because application needs specific format ✅
C.Because extensions are security risk
D.Because OS cannot read them
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Applications often define their own expected extensions to guarantee they receive the correct file type, independent of the OS's generic handling. Mandatory OS extensions are not a constraint, security risk is unrelated, and the OS can read files regardless of naming. In real scenarios, a graphics program may require .png even if the OS would otherwise accept .bmp.

Q7. How do file extensions influence MIME type selection, and what effect does this have on a web browser's handling of a downloaded file?

A.They set MIME directly
B.They are ignored by browsers
C.They are used as fallback when MIME missing ✅
D.They encrypt the file
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: When a server omits an explicit MIME type, browsers often infer it from the file extension as a fallback, deciding whether to display, download, or open the file with a plug‑in. Direct MIME headers take precedence, so extensions are secondary. Ignoring extensions or encrypting files does not affect MIME detection. This behavior explains why a .pdf file opens in a viewer even if the server mislabels the content.

Q8. What security risk arises from trusting only the file extension to decide whether a file is executable?

A.Users may run malicious code disguised ✅
B.Extensions prevent viruses
C.Extensions guarantee safety
D.Extensions encrypt data
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Relying solely on extensions allows attackers to hide executable code behind harmless‑looking names such as .docx, leading users to run harmful programs unintentionally. Extensions themselves do not block viruses, guarantee safety, or provide encryption. In practice, security tools examine file headers and signatures, not just the suffix, to mitigate this risk.

Q9. A user saves a document named 'report' without an extension and wants to open it with Word. Which command most directly opens the file?

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

📖 Explanation: Adding the expected .docx extension to the command tells Word exactly which file to load, bypassing any guesswork. Running 'word report' lacks an extension, so Word may not locate the file. Using .txt or .pdf would open the wrong file type. This illustrates the practical need to specify the correct extension when the OS cannot infer it.

Q10. If a .sh script is moved to a directory not listed in the system's PATH, what must a user type to execute it from their current location?

A.sh script.sh
B../script.sh ✅
C.script.sh
D./script.sh
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Prefacing the script with ./ tells the shell to look in the current directory, bypassing the PATH search. Simply typing 'sh script.sh' runs the interpreter but still requires the correct path; 'script.sh' alone fails because the shell cannot find it, and '/script.sh' refers to the root directory. This mirrors everyday command‑line usage when scripts reside outside PATH.

Q11. A .zip archive contains a file named 'installer.exe'. To run this executable safely, which sequence of actions is most appropriate?

A.Extract then double-click
B.Extract then scan with antivirus ✅
C.Open directly
D.Rename to .txt then run
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Extracting the file first isolates it, and scanning with antivirus ensures it is not malicious before execution. Direct double‑clicking skips the safety check, opening directly could execute malware, and renaming to .txt does not change the executable nature. This process reflects best practice for handling unknown executables from archives.

Q12. A data‑processing script expects input files with a .csv extension. The user provides a file named 'data.txt' that contains comma‑separated values. What is the most likely outcome?

A.Script will process successfully
B.Script will reject the file ✅
C.Script will convert extension automatically
D.Script will crash
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Most scripts check the filename extension before parsing; a mismatched .txt extension will cause the script to reject the file, even if the content is correctly formatted. The script does not usually rename files or crash solely because of the extension. In real workflows, users must rename the file to .csv or adjust the script's expectations.

Q13. Company policy requires all source files to reside under the '/src' directory. A developer places a 'Main.java' file in '/docs'. Which build tool behavior will most likely cause a problem?

A.The compiler will not find the file ✅
B.The runtime will ignore it
C.The file will be compiled but not linked
D.The file will be automatically moved
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Build tools like Maven or Gradle scan the '/src' hierarchy for source files; a file outside that tree is ignored, so the compiler cannot locate 'Main.java'. The runtime does not search source locations, automatic moving does not occur, and linking is irrelevant without compilation. This demonstrates why adhering to directory conventions is essential for automated builds.

Q14. In a directory tree where folder A contains subfolder B which holds 'setup.exe', a user types 'setup' while in folder A. What will happen?

A.The executable runs
B.The command fails because the file is not in the current directory ✅
C.The shell searches subdirectories automatically
D.The system runs a different program named 'setup'
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The shell only searches the current directory and PATH entries; because 'setup.exe' resides in a subfolder, the plain command 'setup' is not found, resulting in an error. It does not automatically recurse into subfolders, nor does it run a different program unless one exists in PATH. Users must either change to B or specify the relative path './B/setup.exe'.

Q15. An administrator wants only files with a .sh extension to be executable in '/usr/local/bin'. Which combination of settings best enforces this rule?

A.Set execute permission only on .sh files
B.Use a wrapper script that checks extension
C.Rename all other files to .txt
D.Apply a SELinux policy that checks filename ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: A SELinux (or AppArmor) policy can enforce that only files matching a specific naming pattern, such as *.sh, may have execute permissions, providing system‑wide enforcement. Simply setting permissions on existing .sh files does not prevent new non‑.sh files from being made executable, and wrapper scripts rely on users invoking them correctly. Renaming files is not a security control.

Q16. When migrating a Windows directory tree to Linux, how should file extensions be handled to preserve application functionality?

A.Keep extensions unchanged ✅
B.Change all extensions to lower case
C.Remove all extensions
D.Convert .exe to .sh
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Preserving the original extensions ensures that Windows applications (or Wine) and scripts continue to recognize the file types they expect. Changing case or removing extensions can break associations, while converting .exe to .sh would alter the file's nature entirely. Maintaining extensions is a practical step in cross‑platform migrations.

Q17. A document appears as 'report.docx' but actually contains an embedded executable payload. Which technique can a user employ to detect the hidden code?

A.Open in Word and run macros
B.Use a file‑type analyzer that inspects the file header ✅
C.Rename to .exe and execute
D.Scan only the filename
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: A file‑type analyzer examines the internal header and structure, revealing discrepancies between the claimed .docx format and actual executable content. Opening in Word may trigger macros but not necessarily expose the payload, renaming to .exe is dangerous, and scanning only the name ignores hidden content. This reflects real‑world malware detection practices.

Q18. Two files named 'data' exist in the same folder, one with extension .csv and the other with .txt. When a program is invoked as 'data' without specifying an extension, how does the OS decide which file to open?

A.It opens the .csv file
B.It opens the .txt file
C.It prompts the user to choose ✅
D.It fails with an error
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: When multiple matches exist, many operating systems present a prompt or error rather than arbitrarily selecting one, preventing accidental use of the wrong file. The OS does not prioritize extensions, nor does it silently open one. Prompting the user mirrors typical command‑line behavior when ambiguity arises.

Q19. Design a naming convention for a project that uses a tree‑structured directory layout with source (.java), documentation (.md), and compiled binaries (.jar). Which of the following schemes minimizes ambiguity?

A.All files share same base name
B.Use unique prefixes per type ✅
C.Store all files in root
D.Append type suffix to filename
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Using distinct prefixes (e.g., src_, doc_, bin_) clearly separates file purposes, avoiding confusion when files share similar base names. Sharing a base name without differentiation leads to collisions, storing everything together defeats the hierarchy, and generic suffixes can still clash. Clear prefixes align with best practices for large, multi‑type projects.

Q20. A user accidentally renames a music file from 'song.mp3' to 'song.txt'. What will happen when they try to play it in a media player?

A.It will play normally
B.The player will refuse to open
C.The player will attempt to decode but fail ✅
D.The file will be automatically renamed back
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: Most media players rely on file headers to identify audio data; however, the mismatched .txt extension may cause the player to attempt text parsing and then fail to decode the audio stream, resulting in an error. The file is not automatically renamed, and some players may still play it if they ignore the extension, but failure is the typical outcome.

🔗 Related Topics (MCQs)