Language: Linux
As a Linux administrator, you're often asked to find the IP address of a machine to enable network communication. Which of the following commands is the most modern and preferred way to do this on a current Linux distribution?
ifconfigip anetstat -irouteCorrect Answer: B) ip a
Explanation: While ifconfig was used for many years, the ip command from the iproute2 package is the modern standard for network configuration and information retrieval. ip a is a shorthand for ip addr show.
ip a
You need to allow a new user, 'smith', to run commands with superuser privileges. What is the most common and secure method to achieve this?
/etc/passwd file directly.root group.sudo or wheel group.Correct Answer: C) Adding the user to the sudo or wheel group.
Explanation: Directly editing system files or adding users to the root group can be insecure. The standard and safest practice is to add the user to the sudo (on Debian/Ubuntu-based systems) or wheel (on RHEL/CentOS/Fedora-based systems) group. This allows them to execute commands as root using the sudo command, which also logs the command execution for auditing purposes.
# On Debian/Ubuntu based systems
sudo usermod -aG sudo smith
# On RHEL/Fedora based systems
sudo usermod -aG wheel smith
You need to locate a specific configuration file, config.txt, somewhere within the /etc/ directory. Which command would you use to find this file?
grep config.txt /etc/locate config.txtfind /etc/ -name "config.txt"which config.txtCorrect Answer: C) find /etc/ -name "config.txt"
Explanation: The find command is a powerful utility for searching for files and directories based on various criteria like name, size, modification time, and permissions. grep searches for patterns within files, locate uses a pre-built database (and might not be up-to-date), and which only finds executables in the user's PATH.
find /etc/ -name "config.txt"
You suspect a server is running out of disk space. Which command provides a human-readable summary of disk usage for all mounted filesystems?
du -hdf -hfree -hls -lCorrect Answer: B) df -h
Explanation: The df (disk free) command reports filesystem disk space usage. The -h flag makes the output "human-readable" by displaying sizes in powers of 1024 (e.g., K, M, G). The du command, on the other hand, is used to check the disk usage of files and directories.
df -h
You need to install the 'nginx' web server on a server running the latest version of Ubuntu. What is the correct command to do this?
yum install nginxpacman -S nginxapt-get install nginxdnf install nginxCorrect Answer: C) apt-get install nginx
Explanation: apt-get (or its more interactive counterpart, apt) is the command-line tool for handling packages on Debian-based systems like Ubuntu. yum and dnf are used on RHEL-based systems (like CentOS and Fedora), and pacman is the package manager for Arch Linux.
# First, update your package list
sudo apt-get update
# Then, install the package
sudo apt-get install nginx
You are troubleshooting an application and need to monitor its log file, /var/log/app.log, as new entries are being written. Which command will show you the last 20 lines and continue to display new lines as they are added?
cat /var/log/app.loghead -n 20 /var/log/app.logtail -n 20 -f /var/log/app.logless /var/log/app.logCorrect Answer: C) tail -n 20 -f /var/log/app.log
Explanation: The tail command is used to view the end of a file. The -n 20 option specifies that you want to see the last 20 lines, and the -f (follow) option is crucial for watching the file in real-time, as it will output new lines as they are appended to the file.
tail -n 20 -f /var/log/app.log