Welcome back to our Linux Interview Questions series on Tecmint! After laying a strong foundation in the first article, we’re here with 15 more carefully chosen questions and answers to help you improve your Linux skills and feel more confident during interviews.

Keep in mind: these questions aren’t taken directly from real interviews, but they cover important concepts that every Linux learner should understand. Think of them as useful tools to help you learn step-by-step and build a solid knowledge base.

Let’s get started!

Q1: Which command is used to record a user login session into a file?

The script command records a user’s terminal session, capturing everything typed and displayed between the start and exit of the script.

Example usage:

script my-session-record.txt

Script started, file is my-session-record.txt

exit
Script done, file is my-session-record.txt

You can then view the session log by opening my-session-record.txt with any text editor.

Record a User Login Session
Record a User Login Session

Q2: How can you view kernel log messages in Linux?

The dmesg command prints the kernel ring buffer, which contains boot messages and hardware-related logs.

dmesg | less
View Kernel Log Messages
View Kernel Log Messages

Q3: Which command shows the Linux kernel release version?

Use uname -r to display the kernel release string.

uname -r

6.8.0-59-generic

Other useful uname options:

  • -v: Kernel version
  • -m: Machine hardware name
  • -n: Network node hostname
  • -o: Operating system

Q4: How do you identify the type of a file in Linux?

The file command inspects a file and tells you its type, which is useful to confirm whether a file is binary, script, text, or something else.

file /bin/bash

Sample Output:

/bin/bash: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=2f77b36371c214e11670c7d9d92727e9a49f626b, for GNU/Linux 3.2.0, stripped

Q5: Which command locates the binary, source, and man page files for a command?

The whereis command locates the binary, source, and manual files related to a command.

whereis ls

ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz

Q6: Which files are executed by default when a user logs into a shell?

When a user logs into a shell, files like .bash_profile, .profile, and .bashrc in the user’s home directory are executed to set up the shell environment.

Specifically, .bash_profile (or .profile on some systems) is typically run for login shells, and .bashrc is executed for non-login interactive shells.

Q7: What is the purpose of the /etc/resolv.conf file?

The /etc/resolv.conf file is used to configure DNS (Domain Name System) settings for the system. It specifies the nameservers the system should use to resolve domain names into IP addresses.

Each line typically begins with the keyword nameserver, followed by the IP address of a DNS server.

nameserver 8.8.8.8
nameserver 8.8.4.4

This file is read by the system’s resolver libraries during hostname resolution, which may be dynamically updated by network management tools like NetworkManager or dhclient.

Q8: How do you create a symbolic (soft) link in Linux?

To create a symbolic (soft) link in Linux, use the ln -s command. A symbolic link acts as a shortcut that points to another file or directory and can even span across different filesystems.

ln -s [target_file_or_directory] [link_name]

For example.

ln -s /etc/httpd/conf/httpd.conf httpd.original.conf

In this example, httpd.original.conf becomes a symbolic link pointing to the original Apache configuration file. If the target file is moved or deleted, the symbolic link becomes broken.

Q9: Is the pwd command an alias for passwd?

No, the pwd command is not an alias for passwd command.

  • pwd stands for Print Working Directory, and it displays the absolute path of the current directory you’re working in.
  • passwd is a completely different command used to change the password of a user account.

Example usage:

pwd
/home/user

passwd
Changing password for user

Q10: How do you check PCI device information in Linux?

The lspci command is used to list all PCI (Peripheral Component Interconnect) devices in the system, along with details such as the device type, vendor, and model.

This is especially useful for identifying hardware components like network cards, graphics cards, and storage controllers.

lspci

To get more detailed information, you can use:

lspci -v
List PCI Device Information
List PCI Device Information

Q11: What does the chmod command do, and how is it used?

The chmod (change mode) command is used to modify the access permissions of files and directories in Linux using symbolic notation (e.g., u+x) or octal notation (e.g., 755).

In octal notation, each digit represents a set of permissions:

  • 7 = read (4) + write (2) + execute (1)
  • 5 = read (4) + execute (1)
  • 0 = no permissions

Example:

chmod 755 script.sh

Q12: What is the difference between su and sudo commands?

  • su (substitute user) allows you to switch to another user account, usually the root user.
  • sudo (superuser do) lets you execute a single command with elevated privileges without switching users.

The sudo command uses your own password for authentication and relies on the permissions configured in the /etc/sudoers file to determine allowed commands.

Q13: How do you view running processes in Linux?

You can use the ps command to get a snapshot of current running processes, or top and htop for a real-time, interactive view.

ps aux
top
htop

htop is an enhanced, user-friendly alternative to top (may need to be installed separately).

Q14: What is the purpose of the cron daemon?

The cron daemon is used to schedule and execute repetitive tasks (called cron jobs) automatically at specified times and dates. These jobs are defined in crontab files.

Example crontab entry: This runs a backup script every day at 2 AM:

0 2 * * * /usr/local/bin/backup.sh

Q15: How do you find the disk usage of files and directories in Linux?

The du (disk usage) command is used to estimate the space used by files and directories.

du -sh /var/log
  • -s (summary) shows only the total size for the specified directory.
  • -h (human-readable) displays the size in a readable format (e.g., KB, MB, GB).
Conclusion

Mastering these questions will solidify your Linux fundamentals and help you approach interviews with confidence. Stay tuned as we continue this series, exploring more advanced Linux topics, system administration, and scripting.

Keep practicing, stay curious, and happy Linux learning!

Similar Posts