May 18, 2024

Part-9: Basic 10 Linux Interview Questions and Answers

In this article, we’ve included 9th set of 10 basic Linux Interview Questions and detailed answers that will help candidates prepare for the Linux interview and get the best job in the IT industry.

These Linux interview questions and answers will be useful for both freshers and experienced professionals at any level.

Some of the questions are for advanced Linux professionals, however, beginners or fresher can easily understand the answers and explanations described below.

Q.1) What are filters in Linux?

Linux filters are set of commands that take input from standard input or other commands (stdin) and perform some operations and write the specific results to standard output (stdout). It uses combination of ‘pipes’ and ‘filters’ to perform this action.

For example, the passwd file contains each users information as a single line with 7 fields, and if you want to filter certain fields of a specific user, it can be done with Linux filter command called ‘cut’.

grep 'linuxgeek' /etc/passwd | cut -d':' -f3,7

1000:/bin/bash

List of frequently used Linux filter commands:

  • cut
  • less
  • head
  • tail
  • sed
  • find
  • grep
  • cut
  • awk
  • sort
  • uniq
  • tee
  • wc

Q.2) What is redirection in Linux?

Redirection is a feature in Linux that allows you to change standard input/output devices when executing a command. The basic workflow of any Linux command is to read the standard input (stdin) and write the result to the standard output (stdout).

  • stdin – It’s standard input and the device is the keyboard.
  • stdout – It’s standard output and the device is the screen.

We can change the standard workflow input/output of any Linux command using the below redirection:

  • Output redirection
  • Input redirection
  • Error redirection

Q.3) What are environment variables in Linux?

Environment variables are variables that can affect the way running processes will behave on a system. Variables are a set of dynamic named values that are available system-wide, which are used by processes launched in shells. You can create, edit, save, and delete environment variables as needed.

For example, your home directory is set as an environment variable when you log in and you can check that as shown below:

echo $HOME

/home/linuxgeek

To define environment variables for system-wide, use the following files.

  • /etc/environment
  • /etc/profile

To define environment variables for user specific, use the following files.

  • ~/.bash_profile
  • ~/.bashrc

You can lists all of the environment variables by running the below command:

env

LIBVA_DRIVER_NAME=iHD
LS_COLORS=no=00:fi=00:di=01;.....
HOSTTYPE=x86_64
XAUTHLOCALHOSTNAME=LinuxGeek
LESSCLOSE=lessclose.sh %s %s
XKEYSYMDB=/usr/X11R6/lib/X11/XKeysymDB
XDG_MENU_PREFIX=gnome-
LANG=en_US.UTF-8
WINDOWMANAGER=/usr/bin/gnome
LESS=-M -I -R
MANAGERPID=2064
DISPLAY=:0
JAVA_ROOT=/usr/lib64/jvm/jre-11-openjdk
HOSTNAME=LinuxGeek

The printenv Linux command is used to list a specific environment variable or all of them.

printenv LANG

en_US.UTF-8

Q.4) What are shell variables in Linux?

Shell variables are variables set by the shell that only affect the current shell. These shell variables are required for the shell to function properly. Each shell such as zsh and bash, has its own set of shell variables.

The ‘$PATH’ variable determines where the shell searches for commands to execute. To check path variables, run:

echo $PATH

/home/linuxgeek/bin:/usr/local/bin:/usr/bin:/bin:/home/linuxgeek/.local/bin

Q.5) What is Linux fstab file?

The ‘/etc/fstab’ (aks filsystem table) file is a system configuration file that contains all available disk partitions and their options. The /etc/fstab file is used by the operating system to mount static filesystem during boot.

cat /etc/fstab

UUID=0067495e-d692-4012-92ab-1f456f7308d8  /                       btrfs  defaults                      0  0
UUID=0067495e-d692-4012-92ab-1f456f7308d8  /var                    btrfs  subvol=/@/var                 0  0
UUID=0067495e-d692-4012-92ab-1f456f7308d8  /usr/local              btrfs  subvol=/@/usr/local           0  0
UUID=0067495e-d692-4012-92ab-1f456f7308d8  /tmp                    btrfs  subvol=/@/tmp                 0  0
UUID=0067495e-d692-4012-92ab-1f456f7308d8  /srv                    btrfs  subvol=/@/srv                 0  0
UUID=0067495e-d692-4012-92ab-1f456f7308d8  /root                   btrfs  subvol=/@/root                0  0
UUID=0067495e-d692-4012-92ab-1f456f7308d8  /opt                    btrfs  subvol=/@/opt                 0  0
UUID=0067495e-d692-4012-92ab-1f456f7308d8  /home                   btrfs  subvol=/@/home                0  0
UUID=0067495e-d692-4012-92ab-1f456f7308d8  /boot/grub2/x86_64-efi  btrfs  subvol=/@/boot/grub2/x86_64-efi  0  0
UUID=0067495e-d692-4012-92ab-1f456f7308d8  /boot/grub2/i386-pc     btrfs  subvol=/@/boot/grub2/i386-pc  0  0
UUID=0067495e-d692-4012-92ab-1f456f7308d8  /.snapshots             btrfs  subvol=/@/.snapshots          0  0
UUID=f88b1f01-5b84-4dba-ad38-0a2fcfdf37c3  swap                    swap   defaults                      0  0

The /etc/fstab contains the ‘six’ fields separated by a 'space' or 'tab':

  • Device
  • Mount point
  • File system type
  • Options
  • Backup operation
  • File system check order

Q.6) What is Linux passwd file?

The ‘/etc/passwd’ is a plain text file that contains information for all user accounts on the system. Each line in /etc/passwd represents a single user with 'seven' fields.

grep linuxgeek /etc/passwd

linuxgeek:x:1000:100:linuxgeek:/home/linuxgeek:/bin/bash

All fields are separated by a colon '(:)' symbol and the file can only be modified by users with root or sudo privileges but everyone can read the file.

  • Username
  • Password
  • User ID (UID)
  • Group ID (GID)
  • User ID Info (GECOS)
  • Home directory
  • Command/shell

Q.7) What is Linux shadow file?

The ‘/etc/shadow’ file stores actual password in encrypted format for user’s account with additional information related to user password such as user name, last password change date, password expiration values, etc,.

sudo grep linuxgeek /etc/shadow
[sudo] password for root:

linuxgeek:$6$PshpA15WH/zD$fVe/k0sr/qaLPrktzFPSZhp7wB46/1LpRvlJptrb8owFcmg9Mzd3F1ai6E9g9EQSy/khFwWvam2PxCW8V0Amy0:18674:0:99999:7:::

The /etc/shadow file contain every user details as a single line with 'nine' fields, each fields separated by colon (:). It’s a text file and readable only by the root user.

Q.8) What is Linux file permissions

Linux is a multi-user operating system that can be accessed by multiple users at once. Therefore, file permission has implemented to prevent users from accessing each other’s files.

Linux file permissions are divided into three classes such as user owner, group, and others, and these permissions comes with nine characters. Each file in Linux is owned by a user and group. A user is the owner of the file, and group is the one to which the user belongs to.

Listing Directory Contents in Linux

Ownership of Linux files:

ClassDescription
UserA user is the owner of the file. The person who has created a file become its owner.
GroupLinux groups are a mechanism to manage a collection of Linux system users. Every one in the group will have the same access permissions to the file. It is the foundation of Linux security and access.
OthersThe others permissions apply to all other users on the system.

Linux File Permissions:

Permissionon the Fileon the Directory
Read (4)Read permission allow users to open and read a file. The read permission on a directory allow users to lists its content.
Write (2)Write permission allow users to modify the contents of a file.The write permission on a directory allow users to add, remove and rename files on it.
Execute (1)This permission allow users to execute a file and get a results, it’s typically a bash script file. The execute permission on a directory allow users to navigate to inside the directory.

Q.9) What is Access Control Lists (ACL) in Linux

ACL stands for Access Control List (ACL) which provides an additional and more flexible permissions mechanism for file systems. It is designed to assist with UNIX file permissions. It allows you to set permissions to individual users or groups even if these do not correspond to the original owner or the owning group. ACL can be easily managed by setfacl & getfacl commands.

What is setfacl?

The setfacl stands for ‘set file access control lists’. It is used to set Access Control Lists (ACLs) for files and directories.

To set ACL for a file, run:

sudo setfacl -m u:linuxgeek:rwx /etc/apache2/apache2.conf

What is getfacl?

The getfacl stands for ‘get file access control lists’, which is used to view Access Control Lists (ACLs) for files and directories. It displays, the file name, owner & group of the file, and ACL permissions (user, group, other & default).

To check ACL values for a file, run:

getfacl /etc/apache2/apache2.conf

# file: etc/apache2/apache2.conf
# owner: root
# group: root
user::rw-
user:linuxgeek:rwx

group::r--
mask::rwx
other::r--

Q.10) What is vim editor in Linux

Vim is one of the most popular and powerful text editor that widely used by Linux administrators and developers.

It’s highly configurable text editor which enables efficient text editing. This is an updated version of the vi editor, which is already installed on most Unix systems.

It comes with many features like multi level undo, multi windows and buffers, syntax highlighting, command line editing, file name completion, visual selection.

To open a file with vim, run:

vim file_name

What are the different types of modes used in vim?

  • Command Mode: By default you will placed in command mode when you launch the vim. This mode is used for editing operations such as cut, copy, paste, delete, move, replace, select, remove, navigation, save, and exit.
  • Insert Mode: Insert mode is used to edit, update, delete, and append text in the file.
  • Execute Mode: It executes commands in Vim

Conclusion

In this guide, we’ve included the most frequently asked 9th set of 10 basic Linux Interview Questions and detailed answers for your reference purpose and we hope it will be very useful.

If you have any questions or feedback, feel free to comment below.

Leave a Reply

%d bloggers like this: