Unit1 - Subjective Questions
CSE325 • Practice Questions with Detailed Answers
Differentiate between the Linux Kernel and a Linux Distribution. Why are there so many different Linux distributions?
Linux Kernel:
The kernel is the core component of the operating system. It acts as a bridge between the software and the hardware. It manages system resources like CPU, memory, and I/O devices.
Linux Distribution (Distro):
A distribution is the kernel combined with a collection of software utilities, package management systems, desktop environments, and libraries required to make the OS usable for a specific purpose (e.g., Ubuntu, Fedora, Arch).
Why so many distributions?
- Purpose: Different distros target different needs (e.g., Kali for security, Ubuntu for desktops, RHEL for enterprise servers).
- Philosophy: Some prioritize stability (Debian Stable), while others prioritize bleeding-edge software (Arch).
- Package Management: Differences in how software is installed (APT vs. RPM).
- Open Source Nature: Since Linux is open source (), anyone can modify and repackage it.
Explain the Linux File System Hierarchy (FHS). Describe the purpose of the following directories: /bin, /etc, /var, /home, and /root.
The Filesystem Hierarchy Standard (FHS) defines the directory structure and directory contents in Linux distributions.
/bin(User Binaries): Contains essential command binaries that need to be available in single-user mode (e.g.,ls,cp,cat). These are usable by all users./etc(Configuration Files): Contains system-wide configuration files and shell scripts used to boot the system. No binaries should be placed here (e.g.,/etc/passwd,/etc/ssh/sshd_config)./var(Variable Data): Contains files to which the system writes data during the course of its operation. This includes logs (/var/log), mail queues, and print spools./home(User Home Directories): Contains the home directories for all non-root users. Example:/home/student./root(Root Home Directory): The home directory for the root user. It is separate from/hometo ensure the root user can login even if the/homepartition fails.
Compare and contrast the Debian family and the Red Hat family of Linux distributions. Include their package managers and default file formats.
| Feature | Debian Family | Red Hat Family |
|---|---|---|
| Popular Distros | Ubuntu, Kali, Mint, Debian | RHEL, Fedora, CentOS, AlmaLinux |
| Package Manager | apt (Advanced Package Tool), apt-get |
dnf (Dandified YUM), yum, rpm |
| Package Format | .deb |
.rpm (Red Hat Package Manager) |
| Philosophy | Often focuses on community-driven development and user-friendliness (Ubuntu). | Often focuses on enterprise stability, standards, and commercial support (RHEL). |
| Configuration | Uses /etc/network/interfaces or Netplan for networking. |
Historically used /etc/sysconfig/network-scripts. |
Both families use the same Linux kernel but differ significantly in infrastructure and management tools.
Explain the concept of File Permissions in Linux. How is the octal representation calculated? If a file has permissions -rwxr-xr--, what does this signify?
Linux file permissions control who can read, write, or execute a file. They are divided into three categories: User (Owner), Group, and Others.
Permission Types:
- Read (r): Value = 4
- Write (w): Value = 2
- Execute (x): Value = 1
Octal Calculation:
The permissions are represented as a 3-digit number. For example, if permissions are (Read+Write+Execute):
Analyzing -rwxr-xr--:
- User (
rwx): (Full permissions). - Group (
r-x): (Read and Execute only). - Others (
r--): (Read only).
The octal equivalent is 754. This means the owner can do anything, the group members can read/execute, and the public can only read.
Describe the difference between Hard Links and Soft (Symbolic) Links with the help of commands.
Hard Links:
- A hard link is a direct reference to the physical data (inode) on the disk.
- If the original file is deleted, the data remains accessible via the hard link.
- Cannot link across different filesystems.
- Command:
ln target_file link_name
Soft (Symbolic) Links:
- A soft link is a special file that points to the path of another file (like a shortcut in Windows).
- If the original file is deleted, the soft link becomes broken (dangling).
- Can link across different filesystems and to directories.
- Command:
ln -s target_file link_name
Key Distinction: Hard links share the same Inode number; Soft links have their own Inode number pointing to the original path.
What is I/O Redirection in Linux? Explain the usage of standard input, standard output, and standard error with examples.
I/O Redirection allows the user to change the input/output sources of commands.
1. Standard Output (stdout, File Descriptor 1):
Redirects the output of a command to a file instead of the terminal screen.
>(Overwrite):ls > file.txt(Writes list to file.txt, erasing previous content).>>(Append):echo "Hello" >> file.txt(Adds to the end of the file).
2. Standard Input (stdin, File Descriptor 0):
Takes input from a file rather than the keyboard.
<:wc -l < file.txt(Counts lines in the file).
3. Standard Error (stderr, File Descriptor 2):
Redirects error messages.
2>:gcc code.c 2> errors.log(Saves compilation errors to errors.log).
Piping (|): connect stdout of one command to stdin of another. E.g., ls | grep "lab".
Discuss Process Management in Linux. Explain the purpose of ps, top, and kill commands.
A process is an executing instance of a program. Linux assigns a unique Process ID (PID) to every process.
1. ps (Process Status):
Displays a snapshot of currently running processes.
ps: Shows processes for the current shell.ps aux: Shows all running processes for all users with detailed info.
2. top (Table of Processes):
Provides a dynamic, real-time view of running processes. It displays system summary (CPU/Memory usage) and a list of tasks managed by the Linux kernel.
3. kill:
Used to send a signal to a process, usually to terminate it.
kill <PID>: Sends SIGTERM (15) allowing the process to close gracefully.kill -9 <PID>: Sends SIGKILL (9) which forces the process to stop immediately.
Explain the structure of the /etc/passwd and /etc/shadow files. Why is /etc/shadow necessary?
/etc/passwd:
Contains user account information. It is readable by all users.
Format: username:x:UID:GID:Comment:Home_Directory:Default_Shell
- The 'x' in the second field indicates the password is stored in the shadow file.
/etc/shadow:
Contains secure user account information, specifically encrypted passwords and password aging info. It is readable only by root.
Format: username:Encrypted_Password:Last_Changed:Min_Days:Max_Days:Warn:Inactive:Expire
Necessity:
In early Unix, hashed passwords were stored in /etc/passwd. Since /etc/passwd must be readable by everyone (to map UIDs to names), this allowed brute-force attacks on the hashes. Moving hashes to /etc/shadow improves security by restricting access to root only.
How do you manage Users and Groups in Linux? Discuss the commands useradd, usermod, groupadd, and passwd.
1. useradd:
Used to create a new user.
- Example:
useradd -m -s /bin/bash john -m: Creates a home directory.-s: Specifies the default shell.
2. usermod:
Used to modify an existing user account.
- Example:
usermod -aG sudo john -aG: Appends the user to a secondary group (e.g., sudo group).
3. groupadd:
Creates a new group.
- Example:
groupadd developers
4. passwd:
Used to change or set a user's password.
passwd: Changes current user's password.passwd john: (Root only) Changes John's password.
Differentiate between sudo and su commands. What is the role of the /etc/sudoers file?
su (Switch User):
- Allows you to switch to another user account (default is root).
- Requires the password of the target account (e.g., the root password).
- Command:
su -(Login as root with root's environment variables).
sudo (SuperUser DO):
- Allows a permitted user to execute a command as the superuser or another user.
- Requires the password of the current user (not root), provided the user is authorized.
- Tracks commands executed in logs.
Role of /etc/sudoers:
- This file controls which users or groups are allowed to run
sudocommands and what privileges they have. - It should only be edited using the
visudocommand to prevent syntax errors that could lock out administrative access.
What is a Package Manager? Explain the difference between High-level (e.g., apt, yum) and Low-level (e.g., dpkg, rpm) package management tools.
Package Manager:
A collection of software tools that automates the process of installing, upgrading, configuring, and removing computer programs for a computer's operating system in a consistent manner.
Low-level Tools (dpkg, rpm):
- Work directly with the package files (
.debor.rpm) on the local disk. - Do not resolve dependencies automatically. If a package requires Library X,
dpkgwill simply fail and tell you Library X is missing. - Usage:
dpkg -i package.deb.
High-level Tools (apt, yum/dnf):
- Work with repositories (remote servers).
- Handle dependency resolution. If you install a package, the tool checks what else is needed, downloads all dependencies, and installs them in the correct order.
- They utilize the low-level tools in the background.
- Usage:
apt install firefox.
Explain the significance of Repositories in Linux Package Management. How does apt update differ from apt upgrade?
Repositories:
A repository is a centralized storage location (usually a server) containing software packages. Linux systems verify the authenticity of packages using GPG keys. The list of repositories is stored in /etc/apt/sources.list (for Debian/Ubuntu).
apt update:
- This command does not install or upgrade any packages.
- It downloads the latest package lists/metadata from the repositories defined in sources.list.
- It updates the local database so the system knows which packages have newer versions available.
apt upgrade:
- This command actually installs the newer versions of the packages.
- It looks at the local database (updated by
apt update) and upgrades currently installed packages to their latest versions.
Describe the usage and output of the following command line utilities: ls, cd, mkdir, rm, cp, and mv.
ls(List): Lists directory contents. Options:-l(long format with permissions),-a(all files including hidden).cd(Change Directory): Navigates the directory tree.cd ..moves up one level;cd ~moves to home.mkdir(Make Directory): Creates new folders.mkdir -p dir1/dir2creates parent directories if they don't exist.rm(Remove): Deletes files.rm -rdeletes directories recursively;rm -fforces deletion without prompt.cp(Copy): Copies files/dirs.cp source dest. Usecp -rfor directories.mv(Move): Moves files or renames them.mv oldname newnamerenames;mv file /path/moves.
What is Grep? Explain its usage with Regular Expressions (Regex). Give an example to find lines containing "Error" in a log file.
Grep (Global Regular Expression Print):
A command-line utility used for searching plain-text data sets for lines that match a regular expression.
Usage with Regex:
^: Matches start of a line.$: Matches end of a line..: Matches any single character.
Example:
To find lines containing the word "Error" (case-insensitive) in syslog:
grep -i "Error" /var/log/syslog
To find lines starting with "Error":
grep "^Error" /var/log/syslog
Explain the concept of Dependency Hell in the context of Linux software installation. How do modern package managers solve this?
Dependency Hell:
This term refers to the frustration arising when installing software packages that have specific requirements (dependencies) on other software libraries.
- Problem A: Package X needs Library Y (v1.0), but Package Z needs Library Y (v2.0).
- Problem B: Installing a package requires a library, which requires another library, creating a long chain of manual installations.
- Problem C: Removing a library breaks other applications relying on it.
Solution by Modern Package Managers (APT/DNF):
- Metadata: They maintain a database of all packages and their specific version requirements.
- Resolution Algorithms: When a user requests an install, the manager calculates the complete tree of dependencies.
- Automation: It automatically downloads and installs all requisite libraries in the correct order.
- Conflict Detection: It warns the user if an installation will break existing packages.
Discuss the purpose and syntax of the chmod and chown commands. How would you change the owner of a file to 'user1' and the group to 'group1'?
chmod (Change Mode):
Used to change the access permissions (read, write, execute) of file system objects.
- Syntax:
chmod [permissions] [filename] - Example:
chmod 755 script.sh(Owner: rwx, Group: rx, Others: rx).
chown (Change Owner):
Used to change the file owner and group ownership.
- Syntax:
chown [owner]:[group] [filename] - Example:
chown user1:group1 file.txt
Scenario Answer:
To change owner to 'user1' and group to 'group1' for a file named data.txt:
sudo chown user1:group1 data.txt
What are Universal Package Managers? Compare Snap and Flatpak with traditional package managers like APT.
Universal Package Managers:
Systems designed to distribute applications across different Linux distributions regardless of the underlying libraries or OS version. They bundle the application with all its dependencies.
Comparison (Snap/Flatpak vs. APT):
- Isolation (Sandboxing): Snaps and Flatpaks run in isolated environments (sandboxes), improving security. APT packages run with standard system privileges.
- Dependencies:
- APT: Relies on system-wide shared libraries. Saves space but can cause version conflicts.
- Snap/Flatpak: Bundle their own libraries. Uses more disk space but eliminates dependency hell.
- Updates: Universal managers often allow automatic background updates directly from the software vendor, bypassing the distro maintainers.
- Portability: A single Snap/Flatpak works on Ubuntu, Fedora, and Arch, whereas a
.deb(APT) file generally only works on Debian-based systems.
Explain the process of Compiling Software from Source in Linux. What are the typical steps involved (e.g., ./configure, make, make install)?
Compiling from source means converting human-readable source code (usually C/C++) into binary executable code specifically for the user's hardware.
Typical Steps (The GNU Build System):
- Download & Extract: Download the 'tarball' (e.g.,
.tar.gz) and extract it usingtar -xzvf file.tar.gz. ./configure:- This script checks the local system environment for dependencies (compilers, libraries).
- It generates a
Makefiletailored to the system.
make:- This command reads the
Makefileand compiles the source code into binary object files and executables. - This is the most time-consuming step.
- This command reads the
sudo make install:- Copies the compiled binaries and config files to the appropriate system directories (e.g.,
/usr/local/bin). - Requires root privileges.
- Copies the compiled binaries and config files to the appropriate system directories (e.g.,
What is the Root User? Why is it advised not to log in as root for daily tasks?
Root User:
The root user (UID 0) is the superuser in Linux. It has unlimited privileges and can perform any operation, including modifying system files, changing permissions, and deleting critical OS components.
Why avoid root for daily tasks:
- Accidental Damage: A simple typo (e.g.,
rm -rf /instead ofrm -rf ./) can wipe the entire operating system without warning. - Security: If a malware or virus runs under the root account, it gains total control over the system. Running as a standard user limits the damage malware can do.
- Audit Trail: Using
sudologs actions, whereas logging in as root directly often obscures who performed an action in a multi-admin environment.
Define Archiving and Compression in Linux. Explain the usage of the tar command for creating and extracting archives.
Archiving: Combining multiple files into a single file (e.g., for backup or transfer). It does not necessarily reduce size.
Compression: Reducing the size of a file using algorithms (e.g., gzip, bzip2).
The tar (Tape Archive) Command:
Combines both archiving and compression.
-
Creating a Compressed Archive:
- Command:
tar -czvf archive_name.tar.gz /path/to/directory -c: Create.-z: Compress using Gzip.-v: Verbose (show progress).-f: Filename follows.
- Command:
-
Extracting an Archive:
- Command:
tar -xzvf archive_name.tar.gz -x: Extract.- It restores the files to the current directory.
- Command: