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.
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.
/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/passwd
contains user account information, and /etc/hosts
contains static IP address mappings.
/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
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
.
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.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
/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.ufw
?To enable and allow incoming SSH connections through the firewall using ufw
on a Linux Ubuntu system, follow these steps:
ufw
firewall.Example commands:
sudo ufw enable sudo ufw allow ssh sudo ufw status
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
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
/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
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."
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