Quiz: Advanced File Operations
Test your understanding of symbolic links, hard links, and advanced file concepts.
1. What is a symbolic link (symlink)?
- A compressed version of a file
- A pointer that references another file or directory by path
- A backup copy of a file
- An encrypted file
Show Answer
The correct answer is B. A symbolic link is a special file that contains a reference (path) to another file or directory. It's like a shortcut in Windows. If the original file is deleted, the symlink becomes "broken" and points to nothing.
Concept Tested: Symbolic Links
2. How do you create a symbolic link?
- cp -s source link
- ln -s target linkname
- link target linkname
- symlink target linkname
Show Answer
The correct answer is B. The ln -s command creates a symbolic link. For example, ln -s /path/to/original linkname creates a symlink called "linkname" pointing to the original file. The -s flag is essential—without it, you create a hard link instead.
Concept Tested: Ln Command, Symbolic Links
3. What is the key difference between a symbolic link and a hard link?
- Hard links are larger files
- Symbolic links point to paths; hard links point to the same inode
- Hard links only work on Windows
- Symbolic links are encrypted
Show Answer
The correct answer is B. A symbolic link stores a path to the target file. A hard link points to the same inode (data on disk) as the original—they're essentially two names for the same file. Deleting the original doesn't affect hard links, but breaks symbolic links.
Concept Tested: Hard Links, Symbolic Links, Inodes
4. What is an inode?
- An internet connection node
- A data structure storing file metadata and disk location
- A type of network cable
- An input device
Show Answer
The correct answer is B. An inode is a data structure on disk that stores metadata about a file (permissions, owner, timestamps, size) and pointers to the actual data blocks. Every file has an inode, and hard links share the same inode.
Concept Tested: Inodes
See: Chapter 6 - Inodes
5. Which command shows inode numbers for files?
- ls -l
- ls -i
- stat -i
- inode
Show Answer
The correct answer is B. The ls -i command displays the inode number for each file. You can combine it with other options like ls -li for long format with inodes. The stat command also shows inode information along with other file details.
Concept Tested: Inodes, Ls Command
6. Can you create a hard link to a directory?
- Yes, always
- No, hard links to directories are not allowed
- Only as root user
- Only for empty directories
Show Answer
The correct answer is B. Hard links to directories are not allowed in Linux (except for . and .. which the system manages). This prevents circular references that could break the file system. Use symbolic links instead to create directory shortcuts.
Concept Tested: Hard Links
7. What happens to a symbolic link when the original file is deleted?
- The symlink is automatically deleted
- The symlink still contains the data
- The symlink becomes a "dangling" or broken link
- The symlink converts to a hard link
Show Answer
The correct answer is C. When the target of a symbolic link is deleted, the symlink becomes "dangling" or broken—it still exists but points to nothing. Attempting to access it results in a "No such file or directory" error. ls -l often shows broken links in red.
Concept Tested: Symbolic Links
8. What command displays detailed file information including inode, permissions, and timestamps?
- info
- details
- stat
- file
Show Answer
The correct answer is C. The stat command displays comprehensive information about a file including inode number, size, blocks, access/modify/change times, permissions in multiple formats, and more. It's more detailed than ls -l.
Concept Tested: Stat Command
9. What does the file command do?
- Creates a new file
- Determines the type of a file by examining its contents
- Lists all files in a directory
- Compresses a file
Show Answer
The correct answer is B. The file command examines a file's contents (not just its extension) to determine what type of file it is. For example, file image.dat might reveal it's actually a JPEG image, regardless of its extension.
Concept Tested: File Command
10. Why might you prefer a symbolic link over a hard link?
- Symbolic links are faster
- Symbolic links can cross file systems and link to directories
- Hard links don't work in Linux
- Symbolic links use less disk space
Show Answer
The correct answer is B. Symbolic links can link to files on different file systems (partitions) and can link to directories—hard links cannot do either. Symbolic links are more flexible but break if the target is moved or deleted.
Concept Tested: Symbolic Links, Hard Links