Interview

10 Linux Ubuntu Interview Questions and Answers

Prepare for your next interview with our comprehensive guide on Linux Ubuntu, featuring common questions and detailed answers to boost your confidence.

Linux Ubuntu is a popular open-source operating system known for its stability, security, and user-friendly interface. It is widely used in various environments, from personal desktops to enterprise servers, and is favored for its robust performance and extensive community support. Ubuntu’s versatility and compatibility with a wide range of software make it an essential skill for IT professionals.

This article provides a curated selection of interview questions designed to test your knowledge and proficiency with Linux Ubuntu. By familiarizing yourself with these questions and their answers, you can confidently demonstrate your expertise and readiness for roles that require strong Linux skills.

Linux Ubuntu Interview Questions and Answers

1. Describe the purpose of the /etc, /var, and /home directories in the file system hierarchy.

In Linux Ubuntu, the file system hierarchy is organized to separate different types of files and data. The /etc, /var, and /home directories each serve distinct purposes:

  • /etc: This directory contains system-wide configuration files and shell scripts used to boot and initialize the system. It includes configuration files for system services, network settings, and user authentication. For example, /etc/passwd contains user account information, and /etc/hosts contains static IP address mappings.
  • /var: The /var directory is used for variable data files that are expected to grow in size. This includes log files, spool files, and temporary files. For instance, /var/log contains system log files, and /var/spool contains print jobs and mail queues. The data in this directory is dynamic and changes frequently.
  • /home: This directory is where user home directories are located. Each user on the system has a subdirectory under /home where they can store personal files, configuration settings, and application data. For example, the home directory for a user named “john” would be /home/john.

2. Write a command to update the package list and upgrade all installed packages using APT.

To update the package list and upgrade all installed packages using APT in Linux Ubuntu, use:

sudo apt update && sudo apt upgrade -y
  • sudo: Runs the following commands with superuser (root) privileges.
  • apt update: Updates the package list, fetching information on the newest versions of packages and their dependencies.
  • &&: Ensures the second command runs only if the first command is successful.
  • apt upgrade -y: Upgrades all installed packages to their latest versions. The -y flag automatically answers “yes” to any prompts, allowing the upgrade process to proceed without manual intervention.

3. How would you add a new user named john and add him to a group called developers?

To add a new user named john and add him to a group called developers in Linux Ubuntu, use the useradd and usermod commands:

sudo useradd john
sudo usermod -aG developers john

4. How do you display the disk usage of the /home directory in a human-readable format?

To display the disk usage of the /home directory in a human-readable format in Linux Ubuntu, use the du command with the -h option:

du -sh /home
  • du stands for “disk usage.”
  • -s provides a summary of the total disk usage.
  • -h makes the output human-readable.

5. How do you enable and allow incoming SSH connections through the firewall using ufw?

To enable and allow incoming SSH connections through the firewall using ufw on a Linux Ubuntu system, follow these steps:

  • Enable the ufw firewall.
  • Allow incoming SSH connections.
  • Enable the firewall to start on boot.

Example commands:

sudo ufw enable
sudo ufw allow ssh
sudo ufw status

6. Write commands to start, stop, and check the status of the Apache service.

To manage the Apache service on a Linux Ubuntu system, use the following commands:

To start the Apache service:

sudo systemctl start apache2

To stop the Apache service:

sudo systemctl stop apache2

To check the status of the Apache service:

sudo systemctl status apache2

7. Write a simple shell script that prints “Hello, World!” to the terminal.

To write a simple shell script that prints “Hello, World!” to the terminal, create a file with a .sh extension and include:

#!/bin/bash
echo "Hello, World!"

To execute the script, give it execute permissions and then run it:

chmod +x script_name.sh
./script_name.sh

8. How would you schedule a cron job to run a script located at /home/user/backup.sh every day at 2 AM?

To schedule a cron job in Linux Ubuntu, use the crontab command. Cron jobs are scheduled tasks that run at specified intervals. To schedule a script located at /home/user/backup.sh to run every day at 2 AM, add the following line to your crontab file:

0 2 * * * /home/user/backup.sh

To edit the crontab file, use:

crontab -e

9. Write a shell script that takes a filename as an argument and counts the number of lines in the file.

To write a shell script that takes a filename as an argument and counts the number of lines in the file, use the wc (word count) command. The wc -l option specifically counts the number of lines.

Here is a simple shell script:

#!/bin/bash

if [ $# -eq 0 ]; then
    echo "No filename provided"
    exit 1
fi

filename=$1

if [ ! -f "$filename" ]; then
    echo "File not found!"
    exit 1
fi

line_count=$(wc -l < "$filename")
echo "The file '$filename' has $line_count lines."

10. How do you search for and install a specific package using APT?

To search for and install a specific package using APT in Linux Ubuntu, use the following commands:

1. To search for a package:

sudo apt search <package_name>

2. To install a package:

sudo apt install <package_name>

Example:

sudo apt search vim
sudo apt install vim
Previous

15 Salesforce Commerce Cloud Interview Questions and Answers

Back to Interview
Next

10 Google Workspace Interview Questions and Answers