Chapter 8: Unix and Linux Operating Systems (Set-9)
When you need to search inside many files under a directory tree for a word like “error”, which approach is most suitable
A cat all files
B ls -R option
C grep -R option
D pwd -R option
Explanation: grep -R pattern dir searches recursively through files in subdirectories. It is widely used for scanning logs or source code and quickly finding where specific text appears.
Which grep option inverts the match and prints only lines that do NOT contain the pattern
A grep -v option
B grep -n option
C grep -i option
D grep -c option
Explanation: grep -v selects non-matching lines. It is useful for filtering out noise, like removing comment lines or excluding known harmless messages from logs during troubleshooting.
Which grep option prints only the count of matching lines rather than the lines themselves
A grep -l option
B grep -c option
C grep -r option
D grep -s option
Explanation: grep -c reports how many lines match in each file. It helps measure frequency, such as counting how many error lines appear in a log without printing all results.
Which grep option prints only filenames that contain a match, not the matching lines
A grep -n option
B grep -i option
C grep -o option
D grep -l option
Explanation: grep -l lists file names where a match exists. It helps quickly identify which configuration or log files include a keyword so you can open only relevant files.
Which command searches for a string in files but also supports regular expressions for flexible matching
A grep tool
B cat tool
C tar tool
D mv tool
Explanation: grep supports fixed strings and regular expressions. This allows flexible searching like matching patterns, anchors, and character classes, making it powerful for log analysis and configuration checks.
In Linux file viewing, which command is best to view compressed .gz logs without manual decompression
A gzcat command
B cat -z
C zcat command
D unzip cat
Explanation: zcat prints the contents of gzip-compressed files to standard output. It allows quick viewing and searching of compressed logs using pipes without creating a decompressed copy.
Which utility rotates and manages log files automatically on many Linux systems
A logrotate tool
B journalctl tool
C sysctl tool
D rsync tool
Explanation: logrotate manages log growth by rotating, compressing, and removing old logs based on rules. It prevents disks from filling due to logs and keeps log history organized automatically.
Which Linux file contains the main logrotate configuration on many systems
A /var/logrotate.conf
B /etc/logrotate.d
C /var/logrotate.d
D /etc/logrotate.conf
Explanation: /etc/logrotate.conf contains global logrotate settings and often includes additional rules from /etc/logrotate.d. It defines how logs are rotated and how long backups are kept.
Which directory commonly stores per-service logrotate rule snippets
A /etc/rotate.d
B /var/logrotate.d
C /etc/logrotate.d
D /usr/logrotate.d
Explanation: /etc/logrotate.d typically holds individual configuration files for services like nginx or syslog. This modular approach keeps log rotation rules organized per application.
Which command shows the currently running processes in a detailed full-screen interactive view and allows sorting
A top command
B ps command
C who command
D df command
Explanation: top updates live and shows CPU, memory, load, and process lists. It helps identify resource-hungry processes quickly and can sort or filter processes during diagnosis.
To list processes sorted by memory usage for a quick snapshot, which command is most suitable
A df -h command
B du -sh command
C who command
D ps aux –sort=-%mem
Explanation: ps aux –sort=-%mem sorts processes by memory usage (highest first). It’s useful for quick diagnosis without an interactive tool, and can be combined with head to show top results.
Which command reads a text file and outputs only selected columns based on whitespace by default
A awk tool
B cut tool
C paste tool
D join tool
Explanation: awk processes text by fields and can print specific columns, apply conditions, and format output. It is powerful for parsing logs and command output beyond simple delimiter-based tools.
Which tool is commonly used to do simple stream edits like replacing text patterns in output
A tar tool
B ping tool
C sed tool
D ln tool
Explanation: sed is a stream editor that can substitute, delete, or transform lines. It is widely used in pipelines and scripts to edit output without opening files in an editor.
When a script must stop immediately if a command fails, which exit code meaning is most commonly treated as success
A Exit code 1
B Exit code 0
C Exit code 2
D Exit code 127
Explanation: By convention, exit code 0 means success in Unix/Linux. Non-zero values signal errors. Scripts check $? or use shell settings to stop when a command returns failure.
Which exit code commonly indicates “command not found” in many shells
A Exit code 127
B Exit code 0
C Exit code 2
D Exit code 255
Explanation: Many shells return 127 when a command cannot be found in PATH. This helps identify missing packages or incorrect PATH settings during troubleshooting and automation scripting.
In Bash scripting, which operator tests if a file exists and is a regular file
A -d test
B -x test
C -r test
D -f test
Explanation: [ -f file ] is true when the path exists and is a regular file. It is used in scripts to ensure expected input files exist before reading or processing them.
Which test operator checks whether a path exists and is a directory
A -f test
B -s test
C -d test
D -n test
Explanation: [ -d path ] checks for a directory. Scripts use it before changing into a folder or creating directories only when missing, preventing errors and improving reliability.
Which test operator checks if a file is executable by the current user
A -x test
B -r test
C -w test
D -f test
Explanation: [ -x file ] returns true if the file is executable for the current user. It helps scripts confirm a program can run before calling it, avoiding permission failures.
Which command changes the default permissions for new files by masking bits, not granting them
A chmod command
B umask command
C chown command
D chgrp command
Explanation: umask subtracts permissions from defaults. It does not directly set final permissions; it blocks certain bits so newly created files and directories start with safer access settings.
Which default permission is typically created for new regular files before umask is applied
A 777 default
B 755 default
C 666 default
D 644 default
Explanation: New files generally start from 666 (rw-rw-rw-) and then umask removes bits. New directories often start from 777. This model helps apply consistent security defaults.
Which default permission is typically used as the base for new directories before umask
A 777 default
B 666 default
C 700 default
D 600 default
Explanation: New directories are commonly created with base permissions 777 (rwxrwxrwx) before umask is applied. Umask then removes bits to produce safer default directory access.
Which permission combination is required to list directory contents with ls successfully
A Write + execute
B Read + write
C Read only
D Read + execute
Explanation: Read permission allows listing entries, and execute allows accessing the directory. Without execute, you cannot access names properly even if read is set, so both are needed for listing reliably.
Which permission is required to create or delete files inside an existing directory
A Read + execute
B Read only
C Write + execute
D Execute only
Explanation: Creating or deleting entries in a directory requires write permission, and execute permission is needed to traverse the directory. Without execute, write alone is not enough for directory entry changes.
Which command changes file permissions by applying a numeric mode like 640
A chmod 640
B chown 640
C chgrp 640
D umask 640
Explanation: chmod 640 file sets owner to read/write, group to read, others to none. Numeric modes provide a clear way to set exact permissions and are common in scripts and admin work.
Which octal permission best matches “owner full, group read, others none” for a file
A 744 mode
B 740 mode
C 700 mode
D 640 mode
Explanation: 740 equals owner 7 (rwx), group 4 (r–), others 0 (—). This grants full access to the owner, read-only to group, and no access to others, suitable for sensitive tools.
Which command creates a compressed tar archive and names the output file with -f
A tar -xzf
B tar -tzf
C tar -czf
D tar -rzf
Explanation: tar -czf archive.tar.gz folder creates (-c) a tar archive, compresses with gzip (-z), and writes to a named file (-f). It is common for backups.
Which tar option extracts a gzip-compressed archive named with -f
A tar -xzf
B tar -czf
C tar -tzf
D tar -uzf
Explanation: tar -xzf file.tar.gz extracts (-x) a gzip-compressed archive (-z) from the specified file (-f). It restores files and folders while keeping structure.
Which command lists files inside a gzip-compressed tar archive without extracting
A tar -xzf
B tar -czf
C tar -lzf
D tar -tzf
Explanation: tar -tzf archive.tar.gz lists (-t) contents of a gzip tarball (-z) from a file (-f). It helps verify what’s inside before extraction.
When a service fails to start due to configuration errors, which command shows the most direct status and last logs together
A systemctl status
B systemctl enable
C systemctl list-units
D systemctl get-default
Explanation: systemctl status service shows whether the service is active, recent log lines, and errors. It is often the first command used when troubleshooting failed service startups.
Which journalctl option shows only kernel messages, similar to kernel log view
A journalctl -b
B journalctl -u
C journalctl -k
D journalctl -f
Explanation: journalctl -k filters the journal to kernel messages. It is useful for diagnosing driver issues, hardware problems, and boot-time warnings without mixing in user-space logs.
Which command checks detailed distribution name and version on most modern Linux systems
A cat /etc/profile
B cat /etc/os-release
C cat /etc/fstab
D cat /etc/hosts
Explanation: /etc/os-release contains standardized distro identification fields. It helps determine which package manager and paths apply, which is important because commands and file locations differ across distributions.
Which package tool installs a .deb file directly on Debian-based systems
A dpkg -i
B apt -i
C yum -i
D rpm -i
Explanation: dpkg -i package.deb installs a local Debian package file. If dependencies are missing, you may need to run apt to fix them, but dpkg is the direct installer.
Which command removes a package on Debian-based systems while keeping configuration files
A apt purge
B dpkg -i
C dpkg -S
D apt remove
Explanation: apt remove uninstalls the package but usually keeps configuration files. This is useful when you might reinstall later and want to preserve settings, unlike purge which removes configs.
Which command removes a package and also deletes its configuration files on Debian systems
A apt remove
B apt update
C apt purge
D apt upgrade
Explanation: apt purge removes the package and associated config files. It is useful for a clean reset when configuration is corrupted or when you want to fully remove all settings.
On RPM systems, which command installs or upgrades a local RPM package file
A rpm -Uvh
B rpm -qa
C rpm -qi
D rpm -ql
Explanation: rpm -Uvh file.rpm upgrades or installs a package with progress output. It works on local RPM files but may not resolve dependencies like higher-level tools (yum/dnf) do.
Which tool is commonly preferred for remote backups because it copies only differences and preserves metadata
A mv tool
B rm tool
C cat tool
D rsync tool
Explanation: rsync transfers only changed parts of files, saving time and bandwidth. It can preserve permissions and timestamps, and works well over SSH, making it ideal for backup automation.
Which command checks open ports and listening services using the legacy net-tools package
A netstat command
B ping command
C grep command
D top command
Explanation: netstat is a classic tool for showing network connections and listening ports. Many systems now recommend ss, but netstat remains common in older setups and exam basics.
Which file stores SSH server configuration that controls root login and port settings
A /etc/ssh/ssh_config
B ~/.ssh/config
C /etc/ssh/sshd_config
D ~/.ssh/known_hosts
Explanation: sshd_config controls SSH server behavior, including authentication, allowed users, and port. Editing it properly improves security, such as disabling root login and enforcing key-based authentication.
Which tool edits /etc/sudoers safely and checks syntax before saving
A nano tool
B visudo tool
C chmod tool
D usermod tool
Explanation: visudo prevents sudoers mistakes by locking the file and validating syntax. This avoids breaking sudo access, which could lock administrators out of required privileges on servers.
Which command shows a file’s ownership and permissions for troubleshooting “Permission denied” quickly
A ls -l
B pwd -P
C cat -n
D who -a
Explanation: ls -l shows owner, group, and permission bits. Permission problems usually relate to these fields, so checking them first helps decide whether chmod, chown, or group membership changes are needed.
Which command lists block storage devices like disks and partitions in a readable tree format
A lsof command
B lsmod command
C pstree command
D lsblk command
Explanation: lsblk shows disks, partitions, and mount points in a tree view. It helps identify which device corresponds to a filesystem, useful during mounting, troubleshooting, and storage management.
Which command displays UUIDs of partitions, helpful for stable /etc/fstab entries
A dfid command
B uuidgen command
C blkid command
D mountid command
Explanation: blkid shows partition UUIDs and filesystem types. Using UUIDs in /etc/fstab keeps mounts stable even if device names like /dev/sdb change due to hardware order differences.
Which Linux file shows currently mounted filesystems and mount options in a quick readable list
A /proc/mounts
B /etc/fstab
C /var/mounts
D /etc/mounts
Explanation: /proc/mounts reflects current mounts and options in real time. It is useful for confirming what is mounted now, while /etc/fstab shows intended mounts at boot.
Which command checks filesystem type and label information for a device partition
A lsblk command
B blkid command
C df command
D du command
Explanation: blkid reports filesystem type, label, and UUID for block devices. This helps identify partitions accurately, which is critical when configuring mounts or diagnosing wrong filesystem issues.
Which command starts a one-time job to run at a specified time without cron repetition
A cron command
B anacron command
C at command
D nohup command
Explanation: at schedules a command to run once at a specified time. It is useful for delayed tasks like restarting a service later, without creating a repeating cron schedule.
Which Linux feature runs scheduled jobs even if the system was off at the scheduled time, on many desktops
A anacron tool
B cron tool
C ssh tool
D sudo tool
Explanation: anacron is designed for systems that are not always running. It runs missed daily, weekly, or monthly jobs when the system next boots, unlike cron which requires the system to be on.
Which tool checks and repairs ext filesystem inconsistencies, typically used on unmounted partitions
A chkntfs tool
B mount tool
C lsblk tool
D fsck tool
Explanation: fsck checks and repairs filesystem errors, often for ext filesystems. It is usually run on unmounted partitions to avoid corruption, making it important for recovery after crashes.
Which tool schedules disk checking automatically at boot based on mount count or time
A tune2fs tool
B tar tool
C chmod tool
D grep tool
Explanation: tune2fs can adjust ext filesystem parameters, including how often automatic checks occur. It helps ensure periodic integrity checks, improving reliability and preventing silent corruption from going unnoticed.
When troubleshooting boot issues, which single-user recovery mode target is commonly used on systemd systems
A multi-user.target
B graphical.target
C rescue.target
D reboot.target
Explanation: rescue.target provides a minimal environment for repair with essential services. It is used to fix broken configs, reset passwords, or repair filesystems when normal boot fails.
Which mode provides the most minimal emergency shell with very few services for deep recovery
A rescue.target
B emergency.target
C graphical.target
D multi-user.target
Explanation: emergency.target gives a very minimal shell, often without networking, to repair serious problems. It is used for deep recovery when even rescue mode is too heavy or fails to start.