Unit1 - Subjective Questions
CSE325 • Practice Questions with Detailed Answers
Explain the architecture of the Linux Operating System with a neat diagrammatic representation.
The Linux architecture consists of several layers that interact with each other to manage hardware resources and run applications. The main components are:
- Hardware Layer: The physical devices (CPU, RAM, HDD, Peripherals).
- Kernel: The core component of the OS. It interacts directly with the hardware and provides low-level services to the upper layers. Its functions include:
- Process Management
- Memory Management
- Device Drivers
- System Calls
- Shell: An interface (command-line interpreter) that takes inputs from the user and sends them to the kernel for execution. Examples: bash, zsh, sh.
- System Libraries (glibc): Special functions or programs used by application software or system utilities to access the kernel's features.
- System Utilities & User Applications: The upper layer comprising utility programs (compilers, editors) and user applications (web browsers, media players).
Flow: User Shell/Application System Calls Kernel Hardware.
Differentiate between the Debian and Red Hat Linux distribution families with examples.
Linux distributions are generally categorized based on their package management systems and lineage. The two most dominant families are:
| Feature | Debian Family | Red Hat Family |
|---|---|---|
| Primary Distros | Debian, Ubuntu, Kali Linux, Linux Mint | RHEL (Red Hat Enterprise Linux), Fedora, CentOS, AlmaLinux |
| Package Format | .deb (Debian Software Package) |
.rpm (Red Hat Package Manager) |
| Low-level Tool | dpkg |
rpm |
| High-level Tool | apt (Advanced Package Tool), apt-get |
yum (Yellowdog Updater), dnf (Dandified YUM) |
| Configuration | Uses /etc/network/interfaces or Netplan for networking. |
Historically used /etc/sysconfig/network-scripts/. |
| Target Audience | Widely used for desktops (Ubuntu) and servers. | Dominant in enterprise server environments. |
Describe the Filesystem Hierarchy Standard (FHS) in Linux. Explain the purpose of /bin, /etc, /var, /home, and /root.
The Filesystem Hierarchy Standard (FHS) defines the directory structure and directory contents in Linux distributions to ensure compatibility.
/(Root): The top-level directory containing all other directories./bin(User Binaries): Contains essential command binaries that need to be available in single-user mode (e.g.,ls,cp,cat,bash)./etc(Configuration Files): Contains system-wide configuration files and shell scripts used to boot the system. No binary files exist here (e.g.,/etc/passwd,/etc/fstab)./var(Variable Data): Contains files that are expected to grow in size, such as system logs (/var/log), spool files, and temporary mail files./home(User Home Directories): Contains personal directories for regular users (e.g.,/home/john)./root(Root Home Directory): The home directory for the root (superuser), separate from/hometo ensure access even if the/homepartition fails.
Explain the concept of File Permissions in Linux. How would you calculate the octal value to set a file's permission to rwxr-xr--?
Linux file permissions determine who can read, write, or execute a file. Permissions are defined for three categories: User (Owner), Group, and Others.
Permission Types:
- Read (): Value = 4
- Write (): Value = 2
- Execute (): Value = 1
- No Permission (): Value = 0
Calculation for rwxr-xr--:
- User (Owner)
rwx: - Group
r-x: - Others
r--:
Result: The octal value is 754.
Command: chmod 754 filename
Distinguish between Hard Links and Soft Links (Symbolic Links) with respect to inode numbers and file deletion.
Hard Links:
- A hard link is a direct reference to the physical data on the disk (the inode).
- Inode: Both the original file and the hard link share the same Inode number.
- Deletion: If the original file is deleted, the data remains accessible via the hard link as long as at least one link exists.
- Limitation: Cannot link across different file systems or partitions.
- Command:
ln target_file link_name
Soft Links (Symbolic Links):
- A soft link is a special file that points to the path of another file (like a shortcut in Windows).
- Inode: The soft link has a different Inode number than the original file.
- Deletion: If the original file is deleted, the soft link becomes 'broken' or 'dangling' and points to nothing.
- Flexibility: Can link across different file systems.
- Command:
ln -s target_file link_name
Explain the significance of the following commands: pwd, mkdir, rmdir, and man.
-
pwd(Print Working Directory):- Displays the absolute path of the current directory the user is operating in.
- Example:
/home/student/lab1
-
mkdir(Make Directory):- Used to create new directories.
- Flag:
mkdir -p dir1/dir2creates a parent directory structure if it doesn't exist.
-
rmdir(Remove Directory):- Used to remove empty directories. If a directory contains files, this command will fail (use
rm -rinstead).
- Used to remove empty directories. If a directory contains files, this command will fail (use
-
man(Manual):- Provides the system reference manuals for commands, configurations, and system calls.
- Usage:
man lsopens the manual page for the list command.
What are Wildcards in Linux? Explain the usage of *, ?, and [] with examples.
Wildcards are special characters used in shell commands to match patterns of filenames or paths.
-
*`` (Asterisk): Matches zero or more** characters.
- Example:
ls *.txtlists all files ending with .txt. - Example:
rm data*removes all files starting with 'data'.
- Example:
-
?(Question Mark): Matches exactly one character.- Example:
ls file?.txtmatchesfile1.txt,fileA.txt, but notfile10.txt.
- Example:
-
[](Brackets): Matches a range or a specific set of characters.- Example:
ls file[1-3].txtmatchesfile1.txt,file2.txt, andfile3.txt. - Example:
ls [Aa]*lists files starting with either 'A' or 'a'.
- Example:
Describe the mechanism of I/O Redirection and Piping in Linux using operators >, >>, <, and |.
Linux shells allow changing the standard input (stdin), standard output (stdout), and standard error (stderr).
-
Output Redirection (
>):- Redirects stdout to a file, overwriting the file content.
- Example:
ls > filelist.txt(Writes directory contents to filelist.txt).
-
Append Redirection (
>>):- Redirects stdout to a file, appending to the end of the file without overwriting.
- Example:
echo "New Line" >> notes.txt.
-
Input Redirection (
<):- Feeds the content of a file into a command as stdin.
- Example:
sort < unsorted.txt.
-
Pipe (
|):- Takes the stdout of the command on the left and passes it as stdin to the command on the right.
- Example:
ls -l | grep "Jan"(Lists files, then filters lines containing "Jan").
Explain the structure and purpose of the /etc/passwd and /etc/shadow files.
1. /etc/passwd:
- Contains essential user account information. It is readable by all users.
- Format:
username:x:UID:GID:Comment:Home_Directory:Default_Shell - Fields:
username: Login name.x: Placeholder for the password (stored in shadow).UID: User ID number (0 is root).GID: Group ID number.Home_Directory: Path to user's home (e.g.,/home/user).
2. /etc/shadow:
- Stores encrypted password data and password aging information. It is readable only by the root user for security.
- Format:
username:Encrypted_Password:Last_Change:Min_Days:Max_Days:Warn:Inactive:Expire - Key Fields:
Encrypted_Password: Hash of the password.Last_Change: Date of last password change.Max_Days: Days before password change is required.
Compare the commands useradd and adduser. What are the steps performed by the system when a new user is created?
Comparison:
useradd: A low-level binary command available on most Linux distros. It creates the user but often requires manual flags to create home directories (-m) or set shells (-s). It does not ask for a password by default.adduser: A high-level Perl/Shell script (common in Debian/Ubuntu) that acts as a friendly wrapper arounduseradd. It automatically creates home directories, copies skeleton files, and prompts for a password interactively.
Steps during User Creation:
- A new entry is added to
/etc/passwd. - A new entry is added to
/etc/shadow. - A new group is often created in
/etc/group(User Private Group scheme). - The home directory is created (usually in
/home/username). - Default configuration files (
.bashrc,.profile) are copied from/etc/skelto the new home directory.
How are groups managed in Linux? Explain the commands groupadd, usermod, and gpasswd.
Groups allow multiple users to share permissions for files or resources.
-
groupadd:- Creates a new group definition in the system.
- Syntax:
sudo groupadd developers
-
usermod:- Used to modify user attributes, including group membership.
- Adding user to a group:
sudo usermod -aG developers john-a: Append (prevents removing user from other groups).-G: Secondary groups.
-
gpasswd:- Tool to administer
/etc/groupand/etc/gshadow. It can define group administrators and members. - Usage:
gpasswd -a user group(Adds user),gpasswd -d user group(Deletes user).
- Tool to administer
What is the Sudo mechanism? Explain the purpose of the /etc/sudoers file and the visudo command.
Sudo (SuperUser DO):
- It allows a permitted user to execute a command as the superuser (root) or another user, as specified by the security policy.
- It provides an audit trail (logging) of commands executed with elevated privileges.
/etc/sudoers:
- This is the configuration file that defines which users or groups have sudo privileges and what commands they can run.
- Typical entry:
root ALL=(ALL:ALL) ALL
visudo:
- This command is used to edit the
/etc/sudoersfile safely. - It locks the file against simultaneous edits.
- It performs a syntax check before saving. If the syntax is wrong, it prevents saving, which avoids locking the admin out of the system (a broken sudoers file can prevent
sudofrom working).
Explain the usage of chown and chgrp commands with appropriate syntax.
These commands manage file ownership in Linux.
-
chown(Change Owner):- Changes the user ownership of a file or directory.
- It can also change the group simultaneously.
- Syntax:
chown [OPTIONS] USER[:GROUP] FILE - Example 1 (User only):
chown alice report.txt(Sets 'alice' as owner). - Example 2 (User and Group):
chown alice:staff report.txt(Owner 'alice', Group 'staff'). - Recursive:
chown -R alice /var/www/html(Changes ownership for directory and contents).
-
chgrp(Change Group):- Changes only the group ownership of a file.
- Syntax:
chgrp [OPTIONS] GROUP FILE - Example:
chgrp developers project.c.
What is a Package Manager in Linux? Differentiate between Low-level and High-level package tools.
Package Manager:
A software tool that automates the process of installing, upgrading, configuring, and removing computer programs. It maintains a database of software dependencies and version information.
Differences:
| Feature | Low-Level Tools | High-Level Tools |
|---|---|---|
| Examples | dpkg (Debian), rpm (Red Hat) |
apt (Debian), yum/dnf (Red Hat) |
| Function | Installs a single package file present locally on the disk. | Downloads packages from remote repositories and installs them. |
| Dependency Resolution | Does not resolve dependencies. Fails if dependencies are missing. | Automatically resolves and installs required dependencies. |
| Input | Takes a file path (e.g., package.rpm). |
Takes a package name (e.g., firefox). |
Explain the concept of Repositories in Linux Package Management. How do you update the repository list in Ubuntu/Debian?
Repositories:
- A repository (repo) is a centralized storage location (usually a server on the internet) where software packages are stored and retrieved for installation.
- Linux distributions maintain official repositories containing thousands of verified and compatible software packages.
- Users can also add third-party repositories (like PPAs in Ubuntu) to install software not found in official sources.
Updating Repository List (Debian/Ubuntu):
- The list of repositories is stored in
/etc/apt/sources.listand the/etc/apt/sources.list.d/directory. - Command:
sudo apt update - Function: This command downloads the package lists (metadata) from the repositories defined in sources.list. It does not upgrade the software; it only updates the local database of available packages and versions so the system knows if updates are available.
Define the purpose of the tar command. Explain the flags -c, -x, -v, -f, and -z.
The tar (Tape ARchive) command is used to combine multiple files into a single archive file (often called a tarball) for easier storage or distribution. It can also compress files.
Flags:
-c(Create): Creates a new archive.-x(Extract): Extracts files from an archive.-v(Verbose): Displays the progress (lists files being processed) in the terminal.-f(File): Specifies the filename of the archive. This must be the last flag usually, followed immediately by the filename.-z(Gzip): Filters the archive through gzip compression (creates.tar.gz).
Examples:
- Create:
tar -cvzf backup.tar.gz /home/user/data - Extract:
tar -xvzf backup.tar.gz
Discuss the process of managing software using RPM and YUM. List commands to install, remove, and update packages.
RPM (Red Hat Package Manager): The low-level format and tool.
- Install:
rpm -ivh package_name.rpm(i=install, v=verbose, h=hash marks for progress). - Upgrade:
rpm -Uvh package_name.rpm. - Remove:
rpm -e package_name(e=erase). - Query:
rpm -qa(Query all installed packages).
YUM (Yellowdog Updater, Modified): The high-level tool handling dependencies.
- Install:
yum install package_name(Downloads from repo, handles dependencies). - Update:
yum update package_name(Updates specific package) oryum update(Updates system). - Remove:
yum remove package_name. - Search:
yum search keyword.
Explain the utility of grep command with Regular Expressions. Explain options -i, -r, and -v.
grep (Global Regular Expression Print):
It searches for a specific pattern of characters (string) within a file or stream of text and outputs the lines that contain the match.
Common Options:
-i(Ignore Case): Performs a case-insensitive search.- Example:
grep -i "error" log.txtmatches "Error", "ERROR", "error".
- Example:
-r(Recursive): Searches all files in a specific directory and its subdirectories.- Example:
grep -r "function_name" /home/project/src.
- Example:
-v(Invert Match): Selects lines that do not contain the pattern.- Example:
grep -v "#" config.txt(Displays lines that are not comments).
- Example:
Regex Example: grep "^Start" file.txt (Matches lines beginning with "Start").
Describe the ps and top commands for process management. How can you terminate a process using CLI?
1. ps (Process Status):
- Displays a snapshot of current running processes.
- Common Flags:
ps auxorps -ef. - Output: Shows PID (Process ID), User, CPU usage, Memory usage, and the command that started the process.
2. top (Table of Processes):
- Displays a real-time, dynamic view of running processes.
- It updates every few seconds and allows sorting by CPU or Memory usage interactively.
Terminating a Process:
killCommand: Sends a signal to a process to terminate it.- Syntax:
kill [SIGNAL] PID - Graceful Stop:
kill -15 PID(SIGTERM - default). - Force Kill:
kill -9 PID(SIGKILL - used if process is unresponsive). - Example: If Firefox has PID 1234,
kill -9 1234forces it to close.
What are Environment Variables in Linux? How do you view and set them? Explain the PATH variable.
Environment Variables:
Dynamic named values that can affect the way running processes will behave on a computer. They are part of the environment in which a process runs.
Managing Variables:
- View all:
printenvorenv. - View specific:
echo $VARIABLE_NAME. - Set (Temporary):
export MY_VAR="value"(Lasts only for current shell session). - Set (Permanent): Add the export command to
~/.bashrcor~/.profile.
The PATH Variable:
- It is an ordered list of directory paths separated by colons (
:). - When a user types a command (e.g.,
lsorpython), the shell searches through these directories in order to find the executable file. - Example:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin.