The Ultimate Linux Admin MCQ Quiz: Test Your Command-Line Knowledge

Language: Linux

1. How do you find the IP address of your system?

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?

  • A) ifconfig
  • B) ip a
  • C) netstat -i
  • D) route

Correct 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

 

2. How do you grant a user superuser (root) privileges?

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?

  • A) Editing the /etc/passwd file directly.
  • B) Adding the user to the root group.
  • C) Adding the user to the sudo or wheel group.
  • D) Setting the user's UID to 0.

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

 

3. How do you find all files named 'config.txt' in the '/etc/' directory?

You need to locate a specific configuration file, config.txt, somewhere within the /etc/ directory. Which command would you use to find this file?

  • A) grep config.txt /etc/
  • B) locate config.txt
  • C) find /etc/ -name "config.txt"
  • D) which config.txt

Correct 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"

 

4. How do you check the disk space usage of a file system?

You suspect a server is running out of disk space. Which command provides a human-readable summary of disk usage for all mounted filesystems?

  • A) du -h
  • B) df -h
  • C) free -h
  • D) ls -l

Correct 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

 

5. How do you install a software package on a Debian/Ubuntu-based system?

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?

  • A) yum install nginx
  • B) pacman -S nginx
  • C) apt-get install nginx
  • D) dnf install nginx

Correct 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

 

6. How do you view the last 20 lines of a log file in real-time?

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?

  • A) cat /var/log/app.log
  • B) head -n 20 /var/log/app.log
  • C) tail -n 20 -f /var/log/app.log
  • D) less /var/log/app.log

Correct 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
Back to List