Linux is a family of free and open-source operating systems based on the Linux kernel. It is used on personal computers, smartphones, embedded systems and it is the leading operating system on servers.
If you are preparing for the interview on system security, Linux system administration, cloud engineer, and such other jobs then this guide on top interview questions on Linux commands can be very helpful. So let’s begin –
Top Linux command interview questions
Q. How will you determine the memory usage on a Linux system?
Ans. There are several ways to determine memory usage on a Linux system. A few commands are given below.
- free command – This is one of the simplest commands use
free -mhere option
-mwill display all the information in megabytes
- top command – Top command displays the list of all the running processes in a dynamic view it also shows the resource utilization on a system. You can run
topin your terminal.
- /proc/meminfo – You can read
/proc/meminfoto display the memory usage on your system. For example –
- vmstat – This command shows memory usage statistics for example –
For more information, you can read a complete article on how to check memory usage in Linux.
Q. What command will be used to display the permissions of a file in Linux?
Ans. There are three kinds of permissions given to a file i.e.
w (write), and
x (execute). We will use
ls command to display the permissions of a file. The full command will be –
ls -l filename
For example –
ls -l hello.c
You can learn how to change file permissions in a detailed article on file permissions.
Q. What are the different modes in the vi editor and how you will switch from one mode to another?
Ans. The vi editor has mainly three modes of operations –
- Command mode – This is the default mode in the vi editor by pressing
Escyou can switch to command mode from insertion mode
- Insertion mode – You need to switch to this mode if you want to start writing by pressing
iyou can enter into the insertion mode
- Ex mode – This is the extension of command mode in vi you need to press
:to enter commands in Ex mode
Q. How permissions are granted in Linux?
Ans. A root user or owner can grant permissions to a file. To grant permissions chmod command is used. The given symbols are used for granting permissions.
+ is used for adding permissions
- is used for denying permissions
The given letters are used to mention that permission is for the user, group, or other and type of permission.
u : user; g: group; o: other; a: all; r: read; w: write; x: execute.
For example –
chmod g-w+x testfile
In the above example write(w) permission will be removed and execute(x) permission will be added for group users.
For more information, you can learn how to change file permissions.
Q. What is the redirection in Linux?
Ans. Redirection is defined as the process of directing data from one output to another or sometimes the output of one command is treated as input to another command.
Linux basically provides three streams in which input and output of the Linux environment are distributed. These are given below –
- Input Redirection: ‘
<’ symbol is used for input redirection and is numbered as (0). Thus it is denoted as STDIN(0).
- Output Redirection: ‘
>’ symbol is used for output redirection and is numbered as (1). Thus it is denoted as STDOUT(1).
- Error Redirection: It is denoted as STDERR(2).
Q. How will you check in which directory you are working in the Linux terminal?
Ans. Linux provides
pwd command which stands for the print current working directory. Executing this command in your terminal will display the full path of the directory where you are currently working.
For example –
This will display output something like this –
Q. Which command you will use to move to the previous directory from the current working directory?
And. The cd (change directory) command is used to change the directory in Linux.
The usage of this command is –
cd – This command will bring you to the home directory
cd path/of/directory – This will change the directory to the given path
cd .. – Will change the current working directory to the previous directory.
cd directory_name – Will change your current working directory to the given directory
To know more usage of cd command you can read using cd command in Linux.
Q. Which key combination you will use to reboot your system?
Ans. In a Linux system pressing Ctrl+Alt+Del will reboot the system without prompting you for confirmation.
Q. What is the grep command in Linux?
Ans. The grep is a command-line utility used to search for a specific pattern in one or more files. It prints all the lines matching with the given pattern on the standard output. Sometimes it becomes more useful when piped with other commands on Linux.
For example –
grep 'warning\|error\|critical' /var/log/syslog
This will search warning, error, and critical words in
Q. How will you terminate an ongoing process in Linux?
Ans. To terminate a running process in your system you need to use the kill command. The syntax of killing a process using the kill command is given.
You can find the process id or PID by using one of the given commands.
Find the process name in the output of the top command OR use –
For example –
Q. Write a command that looks for all files with
.c extension and has the occurrence of string “name” in it.
Ans. The command for this will be –
find ./ -name "*.c" | xargs grep –i "name"
Q. What command you will use to calculate the size of a folder?
Ans. To calculate the size of a folder use the given command –
du –sh folder
For example to calculate the size of the Downloads directory use –
du –sh Downloads
This will display output like given below –
Q. How to append one file to another in Linux?
Ans. To append one file to another in Linux you can use the given command.
Example 1 –
cat file2 >> file 1
The operator >> appends the output of file2 to file1.
Example 2 –
cat file1 file2 > file3
This will append the content of one or more files in file3.
Q. Explain the ls command in Linux?
Ans. The ls command is used to list the files and directories in a Linux terminal. You can customize and get useful output by using the options with the ls command.
If you use the ls command without any arguments this will display the list of all files and directories in your current working directory.
To display the list of files and directories along with the permission that they have used –
You can see the man page of the ls command to know more about the options that can be used with the ls command.
Q. How you will check the hardware information of a Linux system?
Ans. There are several ways to check the hardware information of the system where Linux is installed.
For example, use –
sudo lshw -short
OR use –
You can check a detailed article on how to check Linux system hardware information.
Q. Where tar command is used in Linux?
Ans. The tar command is used to extract and create an archived file.
For example, if you want to extract all the files from the archive named sample.tar.gz, then the command will be:
tar -xvzf sample.tar.gz
Suppose you want to create an archive of all the files stored in the path /home/lalit/ which is the current working directory, then the command will be:
tar -cvzf filename.tar.gz
Q. How to see the list of mounted devices in Linux?
Ans. By running the following command you can see the list of all mounted devices in a Linux system.
$ mount -l
Q. How to find where a file is stored in Linux?
Ans. You can find the location of a file stored in a Linux system by using the given command.
Where sample.txt is the name of the file.
I hope these Linux Interview Questions will be helpful in your interview. You can write your feedback in the comments below.