60 Linux Interview Questions

60 linux interview questions

Alright, how are you, folks? This article will show you 60 most common Linux interview questions. These 60 questions will cover SSH, file permissions, automation, services, networking, redirection, process, and system monitoring.

Here we go.

Question 1: What is the use of echo command?

Answer: The echo command displays the string on a terminal when it is passed to it as an argument.

echo Hello World!

Question 2: How to check the computer or hostname in Linux?

Answer: Use hostname or hostnamectl commands.

Question 3: How to check the current user in Linux terminal?

Answer: whoami

Question 4: How to check your current path/directory you are working in?

Answer: You can use pwd (print working directory)

Question 5: Explain the difference between relative and absolute paths.

Answer: The relative path starts from your current working directory while the absolute path starts from the root directory.

Example of relative path:

cd log/

Example of absolute path:

cd /var/log

Question 6: Which command is to be used to create a file in Linux?

Answer: touch, vim, nano etc

Question 7: How will you edit an existing file in Linux server?

Answer: Use any editor like nano, vim, etc.

nano abc.txt

Question 8: How to rename a file in Linux?

Answer: Use mv command.

mv <original file name> <New file name>

Question 9: How to search for a string in a file?

Answer: Use grep command.

grep “string you want to search” <filename>
grep “good” xyz.txt

Question 10: Difference between grep and egrep?

Answer: Both search for a string from a given file. With egrep, you can specify multiple strings.

egrep “good|bye“ xyz.txt

Question 11: How can you read a file without using cat command?

Answer: Using less, more, nano, etc.

Question 12: What is the advantage of using less command?

Answer: We can easily read big files. Forward and backward search is easy. Navigation from top to bottom is easy.

Question 13: How to check a file’s permission?

Answer: ls -l

Question 14: How to check the IP of your Linux server?

Answer: Using ip addr and ifconfig commands.

Question 15: How to read top 5 lines of a file?

Answer: Use head command.

head -5 xyz.txt

Question 16: How to read the last 5 lines of a file?

Answer: Using tail command.

tail -5 xyz.txt

Question 17: How to list hidden files?

Answer: Use –a switch along with ls

ls -la

Question 18: How to see all the recently used commands?

Answer: Use history command

Question 19: What is root?

Answer: Root is an admin or super user and has all privileges.

Question 20: What is inode and how to find it for a file?

Answer: inode or index node is a unique identifier assigned to a file.

ls -li xyz.txt

Question 21: Which command can you use for finding files on a Linux system?

Answer: find and locate commands are used to find files on a Linux system.

locate xyz.txt
find /var/log/ -name xyz.txt

Question 22: Command for counting words and lines?

Answer: wc

wc xyz.txt

Question 23: How can you combine two commands? Or what is pipe used for?

Answer: You can combine two commands using | operator.

cat xyz.txt | wc

Question 24: How to view the difference between two files?

Answer: using diff command

diff file1 file2

Question 25: What is the use of shred command?

Answer: Shred command is used to permanently delete a file (file becomes unable to recover).

shred -u filename

Question 26: How to check system architecture info?

Answer: Using lscpu

lscpu

Question 27: How to combine two files?

Answer: Using cat command

cat file1 file2
cat abc.txt xyz.txt

Question 28: How can you find the type of file?

Answer: file command

file filename

Question 29: How to sort the content of a file?

Answer: sort command

sort file_name

Question 30: Different ways to access a Linux server remotely?

Answer: Using tools and terminals like putty, bash cmd etc

Question 31: What are different types of permission for file in Linux?

Answer: read (r), write (w), and executeable (x).

Question 32: How to check the permissions given to a file?

Answer:

ls -l file_name

Question 33: Which permission allows a user to run an executable file (script)?

Answer: Executable (x)

Question 34: How to write the output of a command in a file?

Answer: Using > operator

command > file-name

Question 35: How to write something in a file without deleting the existing content?

Answer: We can append the file using >> operator

Question 36: How to redirect an error of a command into a file?

Answer: To redirect an error to a file, use need to use 2> operator

Question 37: How to automate any task or script?

Answer: Using cron jobs

Question 38: How to check scheduled jobs?

Answer: crontab -l

Question 39: What is the meaning of this cron job? * * * * *

Answer:*minute (0-59) *hour(0-23) *day of the month (1-31) * month (1-12) * day of the week (0-6)

Question 40: If your cron job didn’t work, How would you check?

Answer:

Check system time.

Check crontab entry

Check /var/log/messages

Question 41: What is a daemon?

Answer: It is a service that runs in the background even automatically at boot time.

Example: Chronyd, httpd, sshd

Question 42: How to check if a service is running or not?

Answer: systemctl status service-name

systemctl status ssh

Question 43: How to start/stop any service?

Answer: To start a service, run:

systemctl start service-name

To stop a service, run:

systemctl stop service-name

Question 44: How to check for free disk space?

Answer: Run, df -h

Question 45: How to check the size of a directory’s content?

Answer: Use du -h

du -h /var/log/

Question 46: How to check CPU usage for a process?

Answer: Use top command

Question 47: What is a process in linux?

Answer: It is an instance of a running program.

Question 48: How to check if a process/application is running or not?

Answer:

ps -ef | grep <process or application name>

Question 49: How to stop or terminate a running process?

Answer: Using kill command

kill pid

Question 50: Difference between kill and kill -9?

Answer: kill -9 will terminate a program forcefully.

Question 51: How to check if a IP/server is accessible or not?

Answer: Use ping command.

Question 52: Which command to use to get info about ports?

Answer: We can use netstat command.

netstat -tln

Question 53: How to check open port on Linux system?

Answer:

netstat -putan | grep port-number

Question 54: How to check network interfaces in Linux?

Answer: Use ifconfig command

Question 55: Difference between telnet and SSH?

Answer: SSH is secure.

Question 56: Which service should be running on server to allow you to connect remotely?

Answer: sshd or ssh

Question 57: What is SSH?

Answer: SSH or secure shell is a protocol which allows to access a server remotely.

Question 58: Why it is called as secure shell?

Answer: Because the communication between server and client is encrypted.

Question 59: What is default port for SSH?

Answer: 22

Question 60: Which command is used to access a Linux system from a terminal or another Linux server?

Answer:

ssh user@ip