Linux Interview Questions with Answers for Fresher

This tutorial presents the collection of Linux interview questions with answers for fresher. This collection includes Linux interview questions from basic topics such as commands and configuration files. Each question is explained with detailed answer.

Which file stores users’ login information in a standalone Linux system?

The file /etc/passwd stores users’ login information. Historically this file used to store all login information. Due to security reasons, later password information was moved in a separate file /etc/shadow. Now both files are used to authenticate the login access.

How /etc/passwd file is formatted and what information it contains?

Each line in /etc/passwd file represents an individual user account and contains following seven fields separated by colons (:).

  • Username
  • password
  • UID (User ID)
  • GID (Group ID)
  • User description
  • User’s home directory
  • User’s login shell

/etc/passwd file field

Which file the who command uses to display the logged-in users’ information?

The who command uses the /var/run/utmp file to display the logged-in users’ information.

What is the use of the apropos command?

The apropos command usually used to obtain the information from manual pages.

Which command provides information about the recent user login?

The lastlog command provides information about the recent user login.

Which option is used with ls command to view the hidden files?

The –a option is used with ls command to list the hidden files.

Which option is used with ls command for recursive directory listing?

For recursive directory listing, the –R option is used with ls command.

How will you display system load averages without using the uptime command?

The w command also provides information about system load averages.

Which command is used to view the line number and word count in a given file?

The wc command is used to view the line number and word count in a given file.

Which file the last command uses to prepare the report?

The last command uses /var/log/wtmp file to prepare the report.

What kind of information does section 5 provide in manual pages?

The section 5 of manual pages provides information about configuration files.

Which command provides information about unsuccessful user login attempts?

The lastb command provides the detail of unsuccessful user login attempts.

How will you know the absolute path of current working directory?

The pwd command prints the absolute path of current working directory.

How will you know who is currently logged-in in system?

To view the currently logged-in users, the who command is used.

Which switch is used with tar command to preserve the SELinux context while archiving the files?

The --selinux switch is used with tar command to preserve the SELinux contexts.

A user doesn’t know what a command does and how to use it, in that situation what help option he should use?

He can use info command. The info command displays the tutorial of a command.

Which sub-ls commands are used to view the pci, usb and cpu information?

The lspci, lsusb and lscpu commands are used to view the pci, usb and cpu information respectively.

You have just installed a RHEL linux and want to connect it with remote server, which utility you can use for this purpose?

You can use SSH (Secure Shell) utility for this purpose. For remote connectivity, SSH is the default utility in RHEL. Both SSH Server and SSH Client packages are installed during the standard installation of RHEL.

What is the difference between a command option and a command argument?

A command option is used to modify the default behavior of a command while a command argument is used to set the target on which a command works. Let’s take an example of ls command which is used to list the contents of a directory.

command option argument

Without any options and arguments it prints the name of files and folders from current directory.

command without any option and argument

If we use -l option with this command, the command prints the detailed information about files and folders.

command with option

If we use /home/sanjay argument with this command, it prints the contents of /home/sanjay directory instead of current directory.

command with argument

Which file stores users’ passwords in Linux?

The /etc/shadow file stores users’ password.

How /etc/shadow file is formatted and what information it contains?

Each line in /etc/shadow file represents an individual user account and contains following nine fields separated by colons (:).

  • Username
  • Encrypted password
  • Date of last password change
  • Minimum required days between password changes
  • Maximum allowed days between password changes
  • Number of days in advance to display password expiration message
  • Number of days after password expiration to disable the account
  • Account expiration date
  • Reserve field

/etc/shadow file

Which field connects the /etc/passwd file and the /etc/shadow file?

The username field connects /etc/passwd file and the /etc/shadow file. In both files, this field represents login name and stores the exactly same information. When a new user account is created, both files are updated simultaneously.

A value (!) is stored in password field of a user account in /etc/shadow file. What does it mean?

A value (!) represents a blank password. If this value is stored in the password field of a user account, it means user account is locked and can’t be logged-in.

What is epoch in Linux?

In Linux, the date 1 January 1970 is known as epoch. This date is used as a starting date or day in calculation by several commands and configuration files such as /etc/shadow. For example, a user changed his password on 25 June 2018 then the number of days 17707 will be used in the last change password field of /etc/shadow file.

Which command will you use to calculate the number of days from 1 January 1970 to current date?

expr $(date +%s) / 86400

Which command is used to change the password?

The passwd command is used to change the password.

That’s all for this tutorial. If you have any suggestion, comment or feedback about this collection of Linux interview questions with answer for fresher, please let me know. If you like this tutorial, please don’t forget to share it.

ComputerNetworkingNotes Networking Interviews Linux Interview Questions with Answers for Fresher