10 Interview Questions and Answers on Linux Commands


Linux is an open-source operating system that has gained popularity over the years. Linux commands are essential in managing the system and its resources. If you are looking for a job that requires Linux skills, you might be asked interview questions about Linux commands. This article aims to provide you with some common Linux command questions and answers to help you prepare for your interview.

What is the command to create a new file in Linux?

The command to create a new file in Linux is "touch". The "touch" command is a versatile and widely used command in Linux that allows users to create new files with ease. The basic syntax for the "touch" command is as follows −

touch [options] filename

For example, to create a new file called "example.txt", you would simply run the following command in your Linux terminal −

touch example.txt

The "touch" command is not only used for creating new files, but it can also be used to modify the timestamps of existing files, change file permissions, and more, depending on the options and parameters used.

What is the command to display the system information in Linux?

The command to display system information in Linux varies depending on the specific distribution you are using. Here are some commonly used commands −

  • uname − This command displays basic information about the Linux system, such as the kernel version, machine hardware name, and operating system name.

  • lsb_release − This command displays information about the Linux distribution, including the distribution name, release number, and codename.

  • cat /etc/os-release − This command displays detailed information about the Linux distribution from the /etc/os-release file, including the distribution name, version, and ID.

  • lscpu − This command displays information about the CPU(s) installed in the Linux system, including the number of cores, architecture, and clock speed.

  • free − This command displays information about the system's memory usage, including total memory, used memory, and free memory.

  • df − This command displays information about the disk space usage on Linux file systems, including the total disk space, used space, and available space.

What is the command to display the list of running processes in Linux?

The command to display the list of running processes in Linux is ps. The ps command provides information about the current processes running on a Linux system. By default, it displays a snapshot of the current processes in a tabular format, showing information such as process ID (PID), terminal associated with the process, CPU usage, memory usage, and more.

Here are some commonly used options with the ps command to display process information in different formats −

  • ps aux − Displays a detailed list of all running processes with full information, including processes from all users (a), with a user-oriented format (u), and including processes not attached to a terminal (x).

  • ps -ef − Displays a list of all running processes in a full format (f), with detailed information, including the parent process ID (PPID) and session ID (SID).

What is the command to display the disk space usage in Linux?

The command to display disk space usage in Linux is df. The df command stands for "disk free" and provides information about the disk space usage on a Linux system, including information about file systems, disk partitions, and mounted file systems.

Here are some commonly used options with the df command to display disk space usage in different formats −

  • df -h − Displays disk space usage in a human-readable format (h), where sizes are shown in "Gigabytes" (GB), "Megabytes" (MB), or "Kilobytes" (KB), depending on the size.

  • df -T − Displays disk space usage along with the file system type (T), showing the type of file system (such as ext4, NTFS, etc.) for each mounted file system.

  • df -i − Displays the disk space usage along with the number of inodes (i), which are data structures used to represent files and directories in a file system. This option can be useful for checking the number of available inodes on a file system.

What is the command to display the memory usage in Linux?

The command to display memory usage in Linux is free. The free command provides information about the system's memory usage, including total available memory, used memory, free memory, and memory used for buffers and cache.

Here are some commonly used options with the free command to display memory usage in different formats −

  • free − Displays memory usage in kilobytes (KB) by default, showing total, used, and free memory, as well as memory used for buffers and cache.

  • free -h − Displays memory usage in a human-readable format (h), where sizes are shown in "Gigabytes" (GB), "Megabytes" (MB), or "Kilobytes" (KB), depending on the size.

What is the command to display the network information in Linux?

The command to display network information in Linux is ip. The ip command provides comprehensive information about network interfaces, IP addresses, routing tables, and other network-related settings on a Linux system. It is a more modern and powerful replacement for the deprecated ifconfig command.

Here are some commonly used options with the ip command −

  • ip addr − Displays information about all active network interfaces, including their IP addresses, MAC addresses, and other network-related settings.

  • ip addr show <interface> − Displays information about a specific network interface, where <interface> is the name of the network interface, such as "eth0" for Ethernet interface or "wlan0" for wireless interface.

  • ip link − Displays information about network interfaces, including their state (up or down), MAC addresses, and other details.

  • ip route − Displays the routing table, which shows the routes that packets take to reach different destinations on the network.

What is the command to display the routing table in Linux?

The command to display the routing table in Linux is ip route. The ip route command provides information about the routes that packets take to reach different destinations on the network. It shows the destination network addresses, gateway IP addresses, and other routing-related information.

Here are some commonly used options with the ip route command −

  • ip route − Displays the routing table, showing the routes for all network destinations.

  • ip route show <network> − Displays the routing information for a specific network destination, where <network> is the network address or IP address of the destination.

  • ip route show default − Displays the default gateway or default route, which is the route used for packets with unknown or unmatched destination IP addresses.

What is the command to display the process status in Linux?

The command to display the process status in Linux is "ps." For example, if you want to display the status of a process with a specific process ID, you can type "ps -p <process ID>" in the terminal. This command will display the status of the process, including the process state, CPU usage, and memory usage.

What is the command to display the process tree in Linux?

The command to display the process tree in Linux is "pstree." For example, if you want to display the process tree of a process with a specific process ID, you can type "pstree <process ID>" in the terminal. This command will display the process tree, including the parent and child processes of the specified process.

What is the command to check the system uptime in Linux?

The command to check the system uptime in Linux is "uptime." For example, if you want to check the system uptime, you can type "uptime" in the terminal. This command will display the system uptime, including the current time, the duration of the uptime, and the number of users currently logged in.

Conclusion

In conclusion, Linux commands are essential in managing the system and its resources. If you are preparing for a job interview that requires Linux skills, it is essential to have a good understanding of the basic Linux commands. In this article, we have covered some common Linux command questions and answers to help you prepare for your interview. Keep in mind that the examples provided in this article are just the basics of the commands, and there are many options and variations to each command. It is essential to continue learning and exploring the Linux commands to become proficient in using them.

Updated on: 27-Apr-2023

315 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements