π 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.
π All File Directory overview in Operating System MCQs
Q1. Which extension represents a shell script on Unix-like systems?
π 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?
π 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?
π 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?
π 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?
π 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?
π 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?
π 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?
π 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?
π 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?
π 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?
π 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?
π 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?
π 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?
π 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?
π 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.