Tech Interview Series (DevOps) Part 1: Linux
A series of technical interview questions brought to you by DevOps Engineers.
Linux is popular among other individuals in Tech because (in simple terms) it is fast and powerful. If you want to be a well-grounded DevOps/Cloud Engineer or even a Linux System Admin, these are some of the most underrated commands yet so powerful — you can test your Linux skills here. I have lately been conducting many interviews and here are some or close to some of the interview questions I would ask an individual to test their Linux knowledge.
Note: I aim to create an ongoing knowledge/technical articles — aiming to begin with questions on hands-on commands rather than open-ended questions. Also, note, there are multiple answers to these questions or methods to solve the problem.
List of Questions:
How to get your current IP address?
How to list all open ports of your machine?
How to list all open files on your machine?
How to list all the network connections?
How to get the version of your kernel or which UNIX distribution you are using?
How to check for free disk space?
How to check the CPU usage of a specific process?
How to check if a Linux service is running?
How to mount a device on your machine?
How can I find out more about a specific command in Linux?
Answers:
How to get your current IP address?
Usually, you would use
ifconfig
, then scroll down through the output and get the inet, inet6 under eth0 for Ubuntu. (Since I’m on OSx, I would look for “en0”)There is also another option you can use, the command is
ip
.ip addr show eth0
orip addr show en0
Note: The IP command is not available on all machines.
2. How to list all open ports of your machine?
To check all open ports on your machine, use the
netstat
command. The output can be quite long so in order to limit this, we can use a flag, to list the UDP and TCP ports only.For Ubuntu & other Linux distros:
netstat-tulpn
For other UNIX distros (macOS):
netstat -anvp TCP | grep “LISTEN”
3. How to list all open files (for a process) on your machine?
This is quite a simple one but in order to see which files & directories are open, you can run
lsof
. Running this command will list many open files/directoriesTo be more specific, you may use these flags:
Find processes by name:lsof -c processsname
Find processes by PID:lsof -p 819
4. How to list all the network connections on your machine?
To list all the network connections of your machine, you can use the
netstat link
command.
5. How to get the version of your kernel or which UNIX distribution you are using?
To get the kernel version, you can simply use the
uname -a
. This will display the details of your OS
Another open-source tool you can use is
neofetch
6. How to check for free disk space?
You can check all disk space usage using the
df
command. So that it’se easier to read, you may add the flag-h
.So you would run
df -h
7. How to check the CPU usage of a specific process?
you may use the ps aux command to list all the processes — to look for something more specific, pipe it with the grep command. Like so:
ps aux | grep “process_name”
Alternatively, you can use the command
top
for a nicer view.
8. How to check if a Linux service is running?
Most Linux distros would use an old command which is
systemd
Another option would be the
systemctl
command, which is relatively newer.You may use it with these flags:
systemctl <option> <service_name>
9. How to mount a device on your machine? & list all the mounts on your device?
To list all the mounts on your machine, you would run
ls /mnt
To mount a device, you may use the
mount
commandFor example:
mount /dev/sda2 /mnt
— where /dev/sda2 would be the device
10. How can I find out more about a specific command in Linux?
A very crucial command that is underestimated as not all of us will know what every single Linux command out there can do.
So to save yourself the hassle, run
man <command_name>
Some of these commands are really handy, not just in interviews, but also in real-life debugging scenarios. I really hope you have learnt more about these Linux commands and how powerful they can be. Please do share and support to help me write more articles on this knowledge series.
Until then, keep learning! 😀