Unit 3: Linux File System and File Management - Subjective Questions
CSE105 — Creative Engineering Workshop • Practice Questions with Detailed Answers
20 questions
Explain the Linux File System Hierarchy and describe why Linux follows a single-rooted, tree-like structure.
The Linux File System Hierarchy is a standardized, tree-like structure defined by the Filesystem Hierarchy Standard (FHS). Unlike Windows, which uses separate drive letters (C:, D:), Linux organizes everything under a single root directory denoted by /.
Key characteristics:
- Single-rooted: Every file and directory descends from the root (
/), forming one unified tree. - Everything is a file: Devices, directories, and processes are represented as files.
- Hierarchical: Directories can contain subdirectories and files, creating parent-child relationships.
- Mount points: Additional storage devices are attached (mounted) into the existing tree rather than given separate drive letters.
Why this structure is used:
- Provides a consistent and predictable layout across different Linux distributions.
- Simplifies administration and scripting since paths are standardized.
- Makes it easy to mount and integrate new devices seamlessly.
This unified approach improves portability, maintainability, and clarity of the system.
Describe the Root Directory Structure in Linux and list at least six top-level directories with their purposes.
The Root Directory (/) is the topmost directory in the Linux file system from which all other directories branch out.
Important top-level directories:
/bin— Essential user command binaries (e.g.,ls,cp,cat) needed for basic operation./sbin— System binaries used mainly by the administrator (e.g.,fdisk,reboot)./etc— System-wide configuration files./home— Personal directories for regular users./usr— User programs, libraries, and documentation./var— Variable data such as logs, mail, and spool files./tmp— Temporary files (often cleared on reboot)./lib— Shared libraries required by binaries in/binand/sbin.
Significance:
- Every directory has a well-defined role, promoting organization.
- The root directory should not be cluttered with user files.
- Only the superuser (root) typically has permission to modify critical directories.
Distinguish between the /bin and /sbin directories in Linux with suitable examples.
Both /bin and /sbin store executable binary programs, but they differ in who uses them and what they do.
/bin (User Binaries):
- Contains essential commands available to all users.
- Needed for basic system operation, even in single-user mode.
- Examples:
ls,cp,mv,cat,pwd,echo.
/sbin (System Binaries):
- Contains commands used mainly for system administration.
- Typically require superuser (root) privileges.
- Examples:
fdisk,ifconfig,reboot,shutdown,mkfs.
Key difference table:
| Aspect | /bin |
/sbin |
|---|---|---|
| Users | All users | Mostly root/admin |
| Purpose | General commands | System maintenance |
| Example | ls, cp |
reboot, fdisk |
In short, /bin serves everyday tasks while /sbin handles administrative and system-level operations.
Explain the purpose of the /etc, /var, and /tmp directories with examples of files they may contain.
These three directories serve distinct roles in managing configuration and data.
/etc (Configuration Files):
- Stores system-wide configuration files and startup scripts.
- Contains text-based, editable settings.
- Examples:
/etc/passwd,/etc/fstab,/etc/hostname,/etc/ssh/sshd_config.
/var (Variable Data):
- Holds files whose content changes frequently during system operation.
- Examples:
/var/log— system logs/var/mail— user mailboxes/var/spool— print and mail queues/var/cache— cached application data
/tmp (Temporary Files):
- Stores temporary files created by programs and users.
- Contents are usually deleted on reboot.
- Writable by all users but with restricted deletion (sticky bit).
Summary:
/etc→ configuration/var→ dynamic/variable data/tmp→ short-lived temporary data
Compare the /usr and /opt directories. What kinds of software are stored in each?
Both directories store software, but they differ in the type of software and how it is organized.
/usr (Unix System Resources):
- Contains user applications, libraries, and documentation installed as part of the distribution.
- Read-only for most users; managed by the package manager.
- Subdirectories:
/usr/bin— non-essential user binaries/usr/lib— libraries for/usr/bin/usr/share— architecture-independent data/usr/local— locally compiled software
/opt (Optional Software):
- Reserved for third-party or add-on software packages.
- Each application is usually placed in its own subdirectory (e.g.,
/opt/google/chrome). - Keeps large, self-contained applications separate from system files.
Comparison:
| Aspect | /usr |
/opt |
|---|---|---|
| Content | Distribution software | Third-party software |
| Organization | Shared subdirs | Self-contained per app |
| Managed by | Package manager | Vendor/manual install |
Thus, /usr holds standard system software while /opt isolates optional vendor applications.
Define Absolute Path and Relative Path. Distinguish between them with suitable examples.
In Linux, a path specifies the location of a file or directory in the file system.
Absolute Path:
- Specifies the location starting from the root directory (
/). - Always begins with
/. - Independent of the current working directory.
- Example:
/home/user/documents/file.txt
Relative Path:
- Specifies the location relative to the current working directory.
- Does not begin with
/. - Uses special symbols:
.→ current directory..→ parent directory
- Example: If in
/home/user, thendocuments/file.txtrefers to/home/user/documents/file.txt.
Comparison:
| Aspect | Absolute Path | Relative Path |
|---|---|---|
| Starts with | / (root) |
Current directory |
| Length | Usually longer | Usually shorter |
| Depends on CWD | No | Yes |
Conclusion: Absolute paths are unambiguous but longer, while relative paths are shorter and depend on your current location.
Explain the pwd and cd commands. How are they used for navigating the Linux file system?
Both commands are fundamental for navigation in the Linux file system.
pwd (Print Working Directory):
- Displays the full absolute path of the current directory.
- Helps the user identify their present location.
- Example:
$ pwd
/home/user/documentscd (Change Directory):
- Used to move between directories.
- Common usages:
cd /etc→ move to an absolute pathcd documents→ move using a relative pathcd ..→ move to the parent directorycd ~orcd→ move to the home directorycd -→ switch to the previous directory
Example workflow:
$ pwd
/home/user
$ cd documents
$ pwd
/home/user/documents
$ cd ..
$ pwd
/home/userTogether, pwd tells you where you are and cd lets you move around the file system.
Describe the ls command and explain at least five commonly used options with examples.
The ls command lists the contents of a directory (files and subdirectories).
Basic usage:
$ ls
file1.txt file2.txt documentsCommon options:
-
-l(long format): Displays detailed information — permissions, owner, size, date.
bash
$ ls -l
-rw-r--r-- 1 user user 1024 Sep 25 10:00 file1.txt -
-a(all): Shows hidden files (those beginning with.).
bash
$ ls -a
. .. .bashrc file1.txt -
-h(human-readable): Shows sizes in KB, MB, GB (used with-l).
bash
$ ls -lh -
-R(recursive): Lists contents of subdirectories recursively. -
-t(time): Sorts files by modification time (newest first). -
-r(reverse): Reverses the sort order.
Combined example:
$ ls -alhThis lists all files (including hidden) in long, human-readable format. ls is essential for inspecting directory contents.
Explain the mkdir and rmdir commands. How do they create and remove directories? Include examples of creating nested directories.
These commands manage the creation and removal of directories.
mkdir (Make Directory):
-
Creates one or more new directories.
-
Basic usage:
bash
$ mkdir projects -
Create multiple directories:
bash
$ mkdir dir1 dir2 dir3 -
-poption (parents): Creates nested directories, and does not error if they exist.
bash
$ mkdir -p projects/2026/january
This creates the entire path in one command.
rmdir (Remove Directory):
-
Removes empty directories only.
-
Basic usage:
bash
$ rmdir projects -
-poption: Removes nested empty directories.
bash
$ rmdir -p projects/2026/january
Important note:
rmdirfails if the directory is not empty.- To remove non-empty directories,
rm -ris used instead.
Thus, mkdir builds directory structures while rmdir cleans up empty ones.
Explain the touch and cat commands. Describe the multiple uses of the cat command with examples.
touch Command:
- Primarily used to create empty files.
- Also used to update the timestamp (access/modification time) of existing files.
- Examples:
bash
$ touch newfile.txt # creates an empty file
$ touch file1 file2 file3 # creates multiple files
cat (Concatenate) Command:
A versatile command with several uses:
-
Display file contents:
bash
$ cat file.txt -
Create a file and add content:
bash
$ cat > file.txt
Hello World
(Ctrl+D to save) -
Append content to a file:
bash
$ cat >> file.txt
Additional line -
Concatenate multiple files:
bash
$ cat file1.txt file2.txt -
Combine files into a new file:
bash
$ cat file1.txt file2.txt > merged.txt -
Number lines using
-n:
bash
$ cat -n file.txt
Summary: touch creates/updates files, while cat displays, creates, appends, and joins file contents.
Explain the cp, mv, and rm commands with their important options and examples.
These commands handle copying, moving/renaming, and deleting files and directories.
cp (Copy):
-
Copies files and directories.
bash
$ cp source.txt destination.txt -
-r(recursive): Copies directories and their contents.
bash
$ cp -r dir1 dir2 -
-i(interactive): Prompts before overwriting.
mv (Move / Rename):
-
Moves files or renames them.
-
Move a file:
bash
$ mv file.txt /home/user/documents/ -
Rename a file:
bash
$ mv oldname.txt newname.txt -
Does not require
-rfor directories.
rm (Remove):
-
Deletes files and directories permanently.
bash
$ rm file.txt -
-r(recursive): Deletes directories and contents.
bash
$ rm -r folder -
-f(force): Deletes without prompting. -
-i(interactive): Prompts before each deletion.
Caution: rm -rf is powerful and irreversible — use with extreme care as there is no recycle bin.
Explain the su command in Linux. How does it help in switching users, and what is the difference between su and su -?
The su (Substitute User / Switch User) command allows a user to switch to another user account within the current session, most commonly to the root (superuser) account.
Basic usage:
-
Switch to root:
bash
$ su
Password: -
Switch to a specific user:
bash
$ su username
Difference between su and su -:
su(without hyphen):- Switches the user but retains the current environment (variables, working directory).
su -(with hyphen, alsosu -l):- Starts a login shell with the target user's full environment (home directory, PATH, profile settings).
Example:
$ su - root # loads root's complete environmentKey points:
- Requires the target user's password.
- Switching to root grants full administrative privileges.
- Use
exitto return to the original user.
Thus, su - is generally preferred when full administrative environment access is needed.
What is the use of the clear and history commands? Explain how the command history can be reused efficiently.
clear Command:
-
Clears the terminal screen, removing all previous output.
-
Provides a clean workspace but does not delete command history.
-
Usage:
bash
$ clear -
Keyboard shortcut:
Ctrl + L.
history Command:
-
Displays a numbered list of previously executed commands.
-
Usage:
bash
$ history
1 ls
2 cd documents
3 pwd -
Show last N commands:
bash
$ history 5
Reusing history efficiently:
-
!n— Runs the command at line number n.
bash
$ !2 # re-runs 'cd documents' -
!!— Repeats the last command. -
!string— Runs the most recent command starting with string. -
Ctrl + R— Reverse search through history interactively. -
history -c— Clears the command history.
Summary: clear tidies the screen while history tracks and enables quick reuse of past commands.
Explain the find command in detail. Describe how it can be used to search files by name, type, and size with examples.
The find command searches for files and directories in a directory hierarchy based on various criteria. It is powerful and highly flexible.
General syntax:
find [path] [expression]Searching by name:
$ find /home -name "file.txt" # exact name
$ find . -iname "*.txt" # case-insensitive, wildcardSearching by type:
$ find /home -type f # files only
$ find /home -type d # directories onlySearching by size:
$ find . -size +100M # larger than 100 MB
$ find . -size -1k # smaller than 1 KBSearching by modification time:
$ find . -mtime -7 # modified in last 7 daysExecuting actions on results:
$ find . -name "*.tmp" -exec rm {} \; # delete matched filesKey points:
- Searches recursively through subdirectories.
- Combines multiple conditions using operators.
- Extremely useful for automation and system administration.
Thus, find is one of the most powerful search tools in Linux.
Explain the tree command for directory visualization. How is it useful and what are some of its common options?
The tree command displays the contents of a directory in a hierarchical, tree-like format, making the structure easy to visualize.
Basic usage:
$ tree
.
├── documents
│ ├── file1.txt
│ └── file2.txt
└── projects
└── code.pyWhy it is useful:
- Provides a clear visual representation of nested directories.
- Easier to understand than repeated
lscommands. - Displays parent-child relationships at a glance.
Common options:
-
-d— Show directories only (no files).
bash
$ tree -d -
-L n— Limit display to n levels deep.
bash
$ tree -L 2 -
-a— Include hidden files. -
-f— Print the full path prefix for each file. -
-h— Show file sizes in human-readable form.
Note: tree may need to be installed separately (e.g., sudo apt install tree).
Summary: tree is an excellent tool for quickly visualizing and documenting directory structures.
Distinguish between the du and df commands. Explain their purpose and important options with examples.
Both commands relate to disk usage but operate at different levels.
du (Disk Usage):
- Reports the disk space used by files and directories.
- Examples:
bash
$ du folder # usage of a directory
$ du -h folder # human-readable sizes
$ du -sh folder # summary (total) size only
$ du -h --max-depth=1 # usage of subdirectories one level deep
df (Disk Free):
- Reports the total, used, and available space on mounted file systems.
- Examples:
bash
$ df # disk space of all filesystems
$ df -h # human-readable format
$ df -h /home # space for a specific mount
Comparison:
| Aspect | du |
df |
|---|---|---|
| Focus | Files/directories | Filesystems |
| Reports | Space used by items | Overall disk free/used |
| Common option | -sh |
-h |
Summary: Use du to find what is consuming space and df to check overall disk availability.
Explain the significance of the /home and /lib directories in Linux.
/home Directory:
- Contains the personal directories of all regular (non-root) users.
- Each user gets a subdirectory named after their username.
- Example:
/home/john,/home/mary
- Example:
- Stores user-specific data: documents, downloads, configuration files (dotfiles like
.bashrc). - Users have full control over their own home directory.
- The root user's home is separate — it is
/root, not under/home.
/lib Directory:
- Contains essential shared libraries needed by the binaries in
/binand/sbin. - These libraries are similar to
.dllfiles in Windows. - Also contains kernel modules (e.g.,
/lib/modules). - Examples of contents:
- Shared object files (
.so) - System startup libraries
- Shared object files (
Comparison:
| Directory | Purpose | Users |
|---|---|---|
/home |
Personal user data | Regular users |
/lib |
Shared system libraries | System programs |
Summary: /home stores user data while /lib provides critical libraries that keep essential programs running.
Write short notes on any five basic file management commands in Linux, explaining their syntax and one example each.
Below are five essential file management commands:
1. touch — Create empty files / update timestamps
- Syntax:
touch filename - Example:
bash
$ touch report.txt
2. cp — Copy files or directories
- Syntax:
cp source destination - Example:
bash
$ cp report.txt backup.txt
3. mv — Move or rename files
- Syntax:
mv source destination - Example:
bash
$ mv report.txt final_report.txt
4. rm — Remove files or directories
- Syntax:
rm [options] filename - Example:
bash
$ rm backup.txt
5. cat — Display or create file contents
- Syntax:
cat filename - Example:
bash
$ cat report.txt
Summary: These commands (touch, cp, mv, rm, cat) form the foundation of everyday file management in Linux, enabling users to create, copy, move, delete, and view files efficiently.
Illustrate with an example how absolute and relative paths can be used together with commands like cd, cp, and ls to navigate and manage files. Describe a complete practical scenario.
This scenario demonstrates combining paths with common commands in a practical workflow.
Initial situation: The user is at /home/user and wants to organize project files.
Step 1 — Check current location (using pwd):
bash
$ pwd
/home/user
Step 2 — Create a project structure (relative path):
bash
$ mkdir -p projects/website/images
Step 3 — Navigate using a relative path:
bash
$ cd projects/website
$ pwd
/home/user/projects/website
Step 4 — List contents:
bash
$ ls
images
Step 5 — Copy a file using an absolute source and relative destination:
bash
$ cp /home/user/logo.png images/
Here /home/user/logo.png is an absolute path and images/ is a relative path.
Step 6 — Move up using .. (relative):
bash
$ cd ..
$ pwd
/home/user/projects
Step 7 — Return home using absolute path:
bash
$ cd /home/user
Key observations:
- Absolute paths (
/home/user/logo.png) work from anywhere. - Relative paths (
images/,..) depend on the current directory. - Combining both makes navigation and file management efficient and flexible.
This integrated approach reflects real-world Linux usage.
Explain what happens internally when you use the read command in a shell, and describe its typical use in scripts with an example.
The read command is used to take input from the user (or standard input) and store it in one or more variables. It is widely used in shell scripts for interactive input.
Basic syntax:
read variable_nameHow it works internally:
- The shell pauses execution and waits for the user to type input.
- Input is read until the Enter key (newline) is pressed.
- The typed value is assigned to the specified variable.
- If multiple variables are given, the input is split by whitespace among them.
Example 1 — Basic input:
$ echo "Enter your name:"
$ read name
$ echo "Hello, $name"Example 2 — Multiple variables:
$ read first last
John Doe
$ echo "$first and $last"Useful options:
-
-p— Display a prompt.
bash
$ read -p "Enter age: " age -
-s— Silent input (for passwords).
bash
$ read -s -p "Password: " pass
Summary: The read command enables interactive input in the shell, making scripts dynamic and user-friendly.
Explain the Linux File System Hierarchy and describe why Linux follows a single-rooted, tree-like structure.
The Linux File System Hierarchy is a standardized, tree-like structure defined by the Filesystem Hierarchy Standard (FHS). Unlike Windows, which uses separate drive letters (C:, D:), Linux organizes everything under a single root directory denoted by /.
Key characteristics:
- Single-rooted: Every file and directory descends from the root (
/), forming one unified tree. - Everything is a file: Devices, directories, and processes are represented as files.
- Hierarchical: Directories can contain subdirectories and files, creating parent-child relationships.
- Mount points: Additional storage devices are attached (mounted) into the existing tree rather than given separate drive letters.
Why this structure is used:
- Provides a consistent and predictable layout across different Linux distributions.
- Simplifies administration and scripting since paths are standardized.
- Makes it easy to mount and integrate new devices seamlessly.
This unified approach improves portability, maintainability, and clarity of the system.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →