Chapter 8: Unix and Linux Operating Systems (Set-8)
In Linux, which command shows the full path to the current user’s home directory variable quickly
A echo $PATH
B echo $SHELL
C echo $USER
D echo $HOME
Explanation: $HOME stores the path of the user’s home directory. Using echo $HOME quickly confirms where personal files and user configuration are stored, which helps when writing scripts and paths.
Which command prints the list of directories searched when you run commands by name
A echo $HOME
B echo $SHELL
C echo $PATH
D echo $LANG
Explanation: $PATH contains directories searched for executables. If a command is “not found,” checking PATH helps confirm whether the program folder is included and whether shell environment is correct.
Which command prints the current shell name or path using an environment variable
A echo $HOME
B echo $SHELL
C echo $USER
D echo $PWD
Explanation: $SHELL usually stores the user’s login shell path, such as /bin/bash. It helps confirm which shell environment is expected, especially when scripts behave differently under different shells.
Which command prints the current working directory using an environment variable
A echo $OLDPWD
B echo $HOME
C echo $PATH
D echo $PWD
Explanation: $PWD holds the current working directory path. It is useful in scripts for building full paths and confirming where commands are running without calling external tools.
Which variable stores the previous directory used before the last cd operation
A OLDPWD variable
B HOME variable
C PATH variable
D SHELL variable
Explanation: $OLDPWD stores the previous working directory. It supports cd – behavior and helps scripts or users quickly return to the last location after moving to a new folder.
Which command lists file permissions for a specific file without listing the whole directory
A chmod -l file
B ls -l filename
C stat -l file
D cat -l file
Explanation: ls -l filename shows permissions, owner, group, size, and time for that file only. It is a quick way to check access and troubleshoot permission errors.
In Linux, which command displays detailed file metadata including inode, timestamps, and permission bits
A file command
B type command
C name command
D stat command
Explanation: stat shows detailed metadata like inode number, access/modify/change times, and exact permission bits. It is useful when you need more details than ls -l provides.
Which command shows inode numbers along with filenames in a directory listing
A ls -a
B ls -h
C ls -i
D ls -t
Explanation: ls -i displays inode numbers. Inodes uniquely identify files within a filesystem, and checking them helps confirm hard links, detect duplicate names, and debug file reference issues.
Which command searches for files by name under a directory path and supports filters like type and size
A locate command
B find command
C grep command
D whereis command
Explanation: find searches the filesystem in real time and supports conditions like name, type, size, and time. It is accurate and powerful for cleanup, audits, and administration tasks.
Which command requires an updated database and provides very fast filename searching
A find command
B grep command
C ps command
D locate command
Explanation: locate searches a prebuilt index of paths, making it very fast. Since it uses a database, results may be outdated until the database is refreshed, unlike live scanning.
Which command prints the path that will be used for an executable command based on PATH order
A command -v
B file -v
C whereis -v
D grep -v
Explanation: command -v name shows how the shell resolves a name, including whether it is a built-in or external path. It helps debug PATH conflicts and alias issues.
Which command searches manual page descriptions for a keyword like “compression”
A man command
B info command
C apropos command
D help command
Explanation: apropos searches man page short descriptions. It helps find relevant commands when you don’t remember the name but know the task, such as searching for “archive” tools.
In Linux, which command shows a file’s contents with line numbers for easier reference
A cat command
B nl command
C less command
D head command
Explanation: nl numbers lines and prints the file. This helps during debugging, editing instructions, and referencing exact lines in logs or configuration files without opening an editor.
Which command prints only the unique lines after sorting to remove duplicates properly
A uniq | sort
B cat | uniq
C grep | uniq
D sort | uniq
Explanation: uniq removes only adjacent duplicates, so sorting first groups identical lines together. Then uniq can remove duplicates reliably, useful for unique lists like usernames or IPs.
Which command prints a sorted list in reverse order without changing file content
A sort -r
B sort -u
C sort -n
D sort -k
Explanation: sort -r reverses the sorting order. It is useful when you want descending lists, such as newest entries after sorting or reverse alphabetical order, without modifying the original file.
Which command sorts numbers correctly instead of treating them as plain text
A sort -r
B sort -n
C sort -u
D sort -h
Explanation: sort -n compares fields as numbers. Without it, “100” may appear before “20” due to text ordering. This option ensures numeric values are sorted correctly.
Which command shows the first N lines of a file when used with the -n option
A tail -n
B wc -n
C head -n
D cut -n
Explanation: head -n 20 file shows the first 20 lines. It is useful for previews, checking file headers, and inspecting early log entries without opening the entire file.
Which command shows the last N lines of a file when used with the -n option
A head -n
B tail -n
C less -n
D cut -n
Explanation: tail -n 50 file prints the last 50 lines. It is very useful for logs where the most recent events are at the end, helping quick troubleshooting.
Which command follows a log file live and prints new lines as they are appended
A head -f
B grep -f
C sort -f
D tail -f
Explanation: tail -f tracks a file and prints new lines as they appear. It helps monitor services in real time, especially during restarts and debugging when logs update continuously.
Which signal is commonly used to request a program to reload configuration without stopping
A SIGKILL signal
B SIGSTOP signal
C SIGHUP signal
D SIGINT signal
Explanation: SIGHUP is often used to tell daemons to reload configuration files. Many services interpret it as “reload,” allowing changes without full restart, though behavior depends on the program.
Which key combination sends SIGINT to stop a foreground command safely
A Ctrl+Z
B Ctrl+C
C Ctrl+R
D Ctrl+D
Explanation: Ctrl+C sends an interrupt signal to the foreground process, usually stopping it. It is the standard way to cancel a running command without closing the terminal or killing the session.
Which key combination suspends a running foreground process and returns control to shell
A Ctrl+C
B Ctrl+D
C Ctrl+R
D Ctrl+Z
Explanation: Ctrl+Z stops the foreground process and places it in the job list. You can resume it using fg for foreground or bg to continue it in background.
Which command resumes the most recently stopped job in the foreground
A bg command
B jobs command
C fg command
D kill command
Explanation: fg brings a stopped job back to the foreground so it can interact with the terminal. It is useful after suspending a process with Ctrl+Z during multitasking.
Which command shows background and stopped jobs associated with the current shell session
A jobs command
B ps command
C top command
D who command
Explanation: jobs lists job control tasks for the current shell, including background and stopped programs. It helps manage them using fg, bg, or kill without searching system-wide.
Which operator connects command output to another command input in a pipeline
A > operator
B < operator
C & operator
D | operator
Explanation: The pipe operator passes standard output of one command as standard input to the next. It enables powerful chains like filtering logs, extracting columns, and sorting results efficiently.
Which redirection overwrites a file with command output
A >> operator
B > operator
C 2> operator
D < operator
Explanation: > redirects standard output to a file and overwrites existing content. It is useful for saving output but risky if used on important files because it replaces the file contents.
Which redirection appends output to an existing file without deleting old content
A > operator
B < operator
C >> operator
D | operator
Explanation: >> adds output to the end of a file, keeping existing lines. It is commonly used for logs and reports where you want to keep historical results.
Which redirection sends a file as input to a command that reads from standard input
A < operator
B > operator
C >> operator
D | operator
Explanation: < redirects a file into standard input. This lets commands read from a file as if the text were typed, supporting automation and repeatable processing without manual input.
Which command changes the group owner of a file for shared access management
A chown command
B chmod command
C umask command
D chgrp command
Explanation: chgrp changes group ownership. This is useful when multiple users in a group need access to shared files, as group permissions control who can read or modify data.
Which command changes both owner and group using user:group format
A chgrp user:group
B chown user:group
C chmod user:group
D usermod user:group
Explanation: chown user:group file sets both owner and group in one command. It’s common when deploying services so files are owned by a service account and accessible to a group.
31) Which directory commonly stores vendor-provided systemd service unit files on many systems
A /etc/systemd/system
B /home/systemd/system
C /tmp/systemd/system
D /usr/lib/systemd/system
Explanation: Vendor unit files are commonly stored in /usr/lib/systemd/system. Local overrides and custom units are typically placed in /etc/systemd/system, keeping admin changes separate from packaged unit files.
Which directory is typically used for local overrides and custom systemd unit files
A /usr/lib/systemd/system
B /var/systemd/system
C /etc/systemd/system
D /tmp/systemd/system
Explanation: /etc/systemd/system is used for administrator-provided units and override files. This keeps local changes safe from being overwritten during package upgrades to vendor unit files.
Which command shows whether a systemd service is running and shows recent log lines
A systemctl status
B systemctl enable
C systemctl list-units
D systemctl get-default
Explanation: systemctl status service shows active state, recent logs, and error messages. It is a key command for diagnosing service failures and confirming whether configuration changes applied correctly.
Which systemctl command starts a service immediately without changing boot behavior
A systemctl enable
B systemctl start
C systemctl mask
D systemctl daemon-reload
Explanation: systemctl start service launches the service now. It does not make it start at boot. For boot-time start, you use systemctl enable separately.
Which command enables a systemd service so it starts automatically at boot
A systemctl start
B systemctl status
C systemctl reload
D systemctl enable
Explanation: systemctl enable service configures the service to start during system boot. It creates the required links or configuration so the service runs automatically after reboot.
Which command reloads systemd unit definitions after editing unit files
A systemctl reload
B systemctl restart
C systemctl daemon-reload
D systemctl reenable
Explanation: After editing unit files, systemctl daemon-reload reloads systemd configuration so changes are recognized. Without it, systemd might continue using the old unit file definitions.
Which command displays logs stored by systemd journal for the current boot only
A journalctl -u
B journalctl -b
C journalctl -f
D journalctl -k
Explanation: journalctl -b shows logs from the current boot session. It is useful for troubleshooting startup problems and service failures that occurred since the last reboot.
Which journalctl option continuously follows new log entries like tail -f
A journalctl -b
B journalctl -u
C journalctl -n
D journalctl -f
Explanation: journalctl -f follows the systemd journal in real time, similar to tailing a log file. It helps watch service behavior live while starting, stopping, or debugging.
Which command checks active listening ports and sockets using modern tooling
A cat command
B ss command
C du command
D ps command
Explanation: ss shows socket information, including listening ports and established connections. It is often used to confirm whether a service is listening and to troubleshoot network connection issues.
Which file typically stores allowed SSH public keys for passwordless authentication
A known_hosts file
B ssh_config file
C authorized_keys file
D shadow file
Explanation: authorized_keys in ~/.ssh lists public keys permitted to log in. If the server sees a matching key, it can authenticate without a password, improving security and automation.
Which file stores known host fingerprints to warn about SSH server identity changes
A authorized_keys file
B sshd_config file
C resolv.conf file
D known_hosts file
Explanation: known_hosts stores host keys for servers you have connected to. If a host key changes unexpectedly, SSH warns you to prevent man-in-the-middle attacks or accidental connections to wrong servers.
Which command prints kernel messages and hardware events from the kernel ring buffer
A dmesg command
B history command
C last command
D who command
Explanation: dmesg shows kernel messages like device detection, driver warnings, and boot-time events. It is especially useful for diagnosing hardware issues and understanding why devices fail to load.
Which directory is recommended for locally installed software separate from distro packages
A /usr/bin
B /usr/local
C /etc/local
D /var/local
Explanation: /usr/local is meant for locally compiled or manually installed software. Keeping custom programs here reduces conflicts with package-managed files and makes upgrades cleaner.
Which directory often stores optional vendor applications installed outside standard package locations
A /sbin directory
B /bin directory
C /opt directory
D /proc directory
Explanation: /opt is commonly used for optional third-party software. Vendors may install applications here so they remain separate from core OS paths, helping organization and reducing risk during system updates.
Which file contains local host-to-IP mappings that can override DNS resolution
A /etc/resolv.conf
B /etc/fstab
C /etc/shadow
D /etc/hosts
Explanation: /etc/hosts maps hostnames to IP addresses locally. It can be used for testing and troubleshooting because it may resolve names even if DNS is down or misconfigured.
Which file commonly defines DNS servers used for name resolution on many systems
A /etc/hosts
B /etc/resolv.conf
C /etc/hostname
D /etc/profile
Explanation: /etc/resolv.conf lists DNS servers and search domains. Many systems generate it automatically. Wrong entries can cause hostname resolution failures even when network connectivity exists.
Which command calculates a SHA-256 checksum for verifying file integrity
A md5sum command
B cksum command
C sha256sum command
D sum command
Explanation: sha256sum generates a SHA-256 hash for a file. Comparing it to a trusted checksum helps confirm downloads are not corrupted or tampered, improving security during software installation.
Which command creates a compressed gzip file from a single file
A gzip command
B tar command
C zip command
D rsync command
Explanation: gzip compresses a single file and produces a .gz file. It is often used with tar archives, but alone it is still useful for compressing logs and large text files.
Which command bundles many files into one archive, often combined with gzip compression
A zip command
B tar command
C cat command
D grep command
Explanation: tar creates a single archive containing many files and directories. When combined with gzip, it produces common backups like .tar.gz, preserving directory structure and file permissions.
Which command schedules repeated jobs based on time patterns, such as daily backups
A ssh service
B sudo service
C cron service
D init service
Explanation: Cron runs scheduled tasks at defined times using crontab entries. It supports daily, weekly, or custom schedules, making it ideal for automated backups, cleanup scripts, and routine maintenance.