Chapter 8: Unix and Linux Operating Systems (Set-4)
In Linux file management, which command safely removes a directory and all its contents recursively
A rm -r
B rmdir -r
C deltree now
D erase all
rm -r deletes a directory and everything inside it, including subfolders. It is powerful and dangerous if used on wrong paths, so always double-check the target directory first.
Which command asks for confirmation before each file removal, reducing accidental deletes
A rm -f
B rm -R
C rm -i
D rm -a
rm -i prompts before removing each file. This interactive safety check helps prevent mistakes when deleting multiple items, especially when wildcards could match more files than expected.
In Linux, which rm option forces deletion without prompts, even if files are write-protected
A rm -i
B rm -v
C rm -d
D rm -f
rm -f forces removal by skipping confirmations and ignoring nonexistent files. It can delete write-protected files too, so it should be used carefully in scripts and admin tasks.
When copying directories with all subfolders in Linux, which option is commonly required
A cp -i
B cp -r
C cp -u
D cp -t
cp -r copies directories recursively, including files and subdirectories. Without recursive copying, cp will fail or skip directories, so -r is necessary for folder backups.
Which cp option preserves file timestamps and permissions during copying
A cp -r
B cp -f
C cp -p
D cp -d
cp -p preserves original timestamps, ownership (when possible), and permissions. This is important for backups and deployments where file modes and times must remain unchanged.
In a Linux pipeline, which stream is normally sent through the pipe by default
A Standard error
B Keyboard input
C Kernel output
D Standard output
Pipes connect standard output of one command to standard input of another. Standard error is separate unless redirected, so errors may still appear on the screen even when output is piped.
Which redirection sends error messages into a file instead of showing them on screen
A > redirect
B < redirect
C 2> redirect
D | redirect
2> redirects standard error (file descriptor 2) to a file. This helps capture error logs separately from normal output, useful in troubleshooting and scripting.
Which redirection combines standard output and standard error into the same file in Bash
A 2> file
B &> file
C > file
D < file
&> redirects both standard output and standard error to one file in Bash. It is helpful for capturing complete logs of a command, including success output and error messages.
In Linux permission bits, which special bit on a directory enables shared-file collaboration safely
A SUID bit
B SGID bit
C Exec bit
D Sticky bit
The sticky bit on a directory (like /tmp) allows users to create files but prevents them from deleting others’ files. Only file owners or root can delete their own entries.
Which special permission bit runs an executable with the file owner’s privileges
A Sticky bit
B Read bit
C SUID bit
D SGID bit
SUID makes a program run with the owner’s effective privileges, often root for admin tools. It is powerful and risky, so only trusted binaries should have SUID set.
Which special permission bit on a directory makes new files inherit the directory’s group
A SGID bit
B SUID bit
C Sticky bit
D Umask bit
SGID on a directory ensures newly created files inherit the directory’s group ownership. This supports teamwork by keeping group access consistent for shared project folders.
Which command changes default file creation permissions by modifying a mask value
A chmod command
B chown command
C groups command
D umask command
umask defines which permission bits are removed from newly created files and directories. It helps enforce security defaults, like preventing new files from being world-writable.
In numeric permission calculation, what does digit “7” represent for one class
A rw- permissions
B r-x permissions
C rwx permissions
D r– permissions
In octal permissions, 7 equals 4+2+1, meaning read, write, and execute. It grants full access for that class, such as owner or group, depending on position.
For a regular file, which permission is required to run it as a program
A Execute permission
B Write permission
C Group membership
D Sticky bit
A file must have execute permission to run as a program or script. Without it, the system will refuse execution even if the file content is correct and readable.
Which command shows numeric and symbolic permissions along with file details
A cat command
B echo command
C stat command
D time command
stat displays detailed file metadata such as permissions, owner, timestamps, size, and inode. It is more informative than ls -l for exact permission and time fields.
Which command shows disk usage of a directory in human-readable form
A df -h
B du -sh
C ls -lh
D free -h
du -sh folder gives a summarized, human-readable size of a directory. It helps quickly find large folders during cleanup or storage troubleshooting.
Which df option displays filesystem sizes in human-readable units like GB and MB
A df -i
B df -t
C df -p
D df -h
df -h shows total, used, and available space in readable units. It is the fastest way to check if a disk partition is near full and causing system issues.
When storage issues happen, which df option helps check inode exhaustion
A df -h
B df -a
C df -i
D df -r
df -i shows inode usage. A filesystem can run out of inodes even when space remains, preventing new file creation, especially on systems with many small files.
Which command prints the current shell’s process ID, useful in scripting
A echo $?
B echo
C echo $0
D echo $!
$$ expands to the PID of the current shell. Scripts use it for unique temporary file names and for tracking the running shell process during debugging.
Which Bash variable stores the PID of the most recent background process
A echo $$
B echo $?
C echo $1
D echo $!
$! holds the PID of the last job started in the background. It is useful for monitoring, waiting, or stopping that background process later in a script.
In Linux text processing, which operator anchors a pattern to the start of a line in grep
A ^ symbol
B $ symbol
C * symbol
D | symbol
In regular expressions, ^ matches the start of a line. With grep, it helps find lines that begin with a specific word, such as matching config keys accurately.
Which regex symbol anchors a pattern to the end of a line in grep
A ^ symbol
B ? symbol
C $ symbol
D + symbol
$ matches the end of a line. It is useful when searching for exact endings, such as file extensions or configuration values, reducing false matches in long text files.
Which grep option ignores letter case, matching both upper and lower case
A grep -n
B grep -v
C grep -r
D grep -i
grep -i performs case-insensitive matching. It helps search logs where case may vary, like “Error” and “error,” without needing multiple patterns.
Which grep option shows line numbers along with matching lines
A grep -i
B grep -n
C grep -c
D grep -l
grep -n prints line numbers for matches. This is useful when editing configuration files or code, because it helps jump directly to the matching line for correction.
Which command displays the current working directory of a specific process by PID
A pwd process
B cd /proc
C ls /proc/PID/cwd
D pgrep cwd
In Linux, /proc/PID/cwd is a symbolic link to a process’s current directory. Checking it helps troubleshoot services that run from unexpected paths or cannot find files.
Which /proc file shows command-line arguments used to start a specific process
A /proc/PID/cmdline
B /proc/PID/status
C /proc/PID/meminfo
D /proc/PID/uptime
/proc/PID/cmdline contains the command and arguments used to start the process. It helps confirm service options and detect suspicious or incorrect startup parameters.
Which /proc file commonly summarizes process state, UID, and memory details
A /proc/PID/maps
B /proc/PID/environ
C /proc/PID/fdinfo
D /proc/PID/status
/proc/PID/status provides a readable summary of process information, including state, user IDs, and memory usage. It is helpful for quick diagnostics without specialized tools.
Which command changes ownership recursively for an entire directory tree
A chmod -R
B chgrp -R
C chown -R
D usermod -R
chown -R user dir changes ownership of a directory and all contents. It’s commonly used after copying website files or restoring backups to ensure correct service permissions.
Which command changes permissions recursively for all files under a directory
A chown -R
B chmod -R
C chgrp -R
D passwd -R
chmod -R applies permission changes to a directory and everything inside. It can break access if used wrongly, so it should be used with careful permission planning.
Which command locks a user account by disabling password-based login
A useradd -l
B chmod -l
C chown -l
D passwd -l
passwd -l username locks an account by disabling its password, preventing password login. It’s a security step for inactive users, compromised accounts, or service accounts needing no login.
Which command unlocks a previously locked user account for password login
A passwd -r
B usermod -u
C passwd -u
D chage -u
passwd -u username unlocks the user’s password authentication. It is used after resolving security issues or when a disabled account needs to be re-enabled.
Which command changes the default login shell assigned to a user account
A chsh command
B chmod command
C chown command
D chgrp command
chsh changes a user’s login shell, such as switching from bash to zsh. The allowed shells are usually listed in /etc/shells for security and system consistency.
Which file lists valid login shells allowed for user accounts on many systems
A /etc/profile
B /etc/hosts
C /etc/fstab
D /etc/shells
/etc/shells lists approved shell programs. Tools like chsh often restrict choices to shells in this file to prevent assigning unsafe programs as login shells.
Which file is commonly executed for system-wide environment settings for login shells
A /etc/fstab
B /etc/group
C /etc/profile
D /etc/exports
/etc/profile sets system-wide environment variables for login shells. It may configure PATH and other defaults for all users, helping maintain consistent settings across the system.
Which command reloads systemd manager configuration after editing unit files
A systemctl daemon-reload
B systemctl restart
C systemctl enable
D systemctl isolate
After changing unit files, systemctl daemon-reload reloads systemd configuration so it recognizes updates. Without this step, changes may not take effect until reboot or service reload.
Which command restarts a service to apply new configuration immediately
A systemctl stop
B systemctl enable
C systemctl restart
D systemctl mask
systemctl restart service stops and starts the service again. This applies new configuration and clears some runtime state, making it a common step after editing config files.
Which command reloads configuration without fully stopping a supported service
A systemctl restart
B systemctl enable
C systemctl disable
D systemctl reload
systemctl reload asks a service to reload its configuration without a full restart, if supported. This can reduce downtime, but not all services implement reload behavior.
Which networking command tests if a specific TCP port is reachable on a remote host
A du command
B nc command
C tar command
D ln command
nc (netcat) can check TCP connections, like testing if port 22 is open for SSH. It helps troubleshoot firewalls and service availability beyond simple ping reachability.
Which command lists open network sockets and listening ports on many Linux systems
A ls command
B cd command
C ss command
D wc command
ss shows socket statistics, including listening ports and established connections. It replaces older tools in many systems and helps identify which services are accepting network connections.
Which older command often used to show listening ports has been replaced by ss in many distros
A who command
B chsh command
C mount command
D netstat command
netstat was widely used to display network connections and listening ports. Many modern systems recommend ss instead, but netstat is still a common basic topic.
Which command checks DNS resolution by querying specific DNS servers and records
A dig command
B ps command
C df command
D rm command
dig performs DNS queries and shows detailed responses, including answer sections and query times. It is used to diagnose DNS issues and verify records like A, MX, and TXT.
Which command shows active system processes with CPU and memory in real-time, but can be more user-friendly than top
A pwd command
B htop tool
C tee command
D cat command
htop is an interactive process viewer that improves on top with easier navigation and clearer display. It may need installation, but it’s widely used for monitoring system load.
Which file permission practice is safest for private SSH keys in a user’s home directory
A 644 permission
B 755 permission
C 777 permission
D 600 permission
SSH private keys should be readable and writable only by the owner. Permissions like 600 reduce risk of key exposure. SSH may refuse to use keys if permissions are too open.
Which directory typically stores user SSH configuration and keys
A /etc/ssh folder
B /var/ssh folder
C ~/.ssh folder
D /tmp/ssh folder
The ~/.ssh directory contains user SSH files like id_rsa, authorized_keys, and config. Keeping correct permissions here is important to prevent unauthorized access or login failures.
Which file in ~/.ssh allows public keys to authenticate without passwords
A known_hosts file
B authorized_keys file
C shadow file
D hosts file
authorized_keys lists public keys allowed to log in for that user. When a matching private key is presented, SSH can authenticate without password, improving security and automation.
Which file in ~/.ssh stores fingerprints of previously connected SSH hosts
A authorized_keys file
B passwd file
C known_hosts file
D group file
known_hosts stores SSH host keys to detect changes and prevent man-in-the-middle attacks. If a server’s key changes unexpectedly, SSH warns the user before connecting.
Which command verifies integrity of a downloaded file by comparing a checksum value
A chmod command
B mkdir command
C ps command
D sha256sum command
sha256sum computes a SHA-256 hash. Comparing it to the provided checksum confirms the file wasn’t corrupted or altered, which is important for safe software downloads and backups.
In Linux archives, which command lists contents of a tar archive without extracting
A tar -t
B tar -x
C tar -c
D tar -p
tar -t shows the list of files inside an archive. This helps verify what will be extracted and ensures you are working with the correct backup before unpacking it.
Which tar option extracts files from an archive to the filesystem
A tar -c
B tar -t
C tar -x
D tar -p
tar -x extracts files from a tar archive. It’s often combined with other options like gzip handling. Always confirm the archive contents to avoid overwriting important files.
Which command displays a Linux system’s current runlevel-style target on systemd systems
A systemctl status
B systemctl list
C systemctl enable
D systemctl get-default
systemctl get-default shows the default systemd target, like graphical or multi-user. It helps confirm whether the system boots into GUI or text mode, useful for server and desktop setups.