Linux Interview Questions and Answers for experienced

If you are preparing for a DevOps interview or for a Linux administrator, consider this Linux Interview Questions and Answers for the experienced tutorial as your lucky friend, which will help you pass the Certificate or the Linux interview.

Let’s get into this Ultimate Linux Interview Questions and Answers for an experienced guide without further delay.

Join 28 other followers

PAPER-1

Q1. In which directory are Linux logs stored in the Linux file system?

  • Linux log files are stored under /var/log directory which contains system generated and application logs.
/var/log/ directory
/var/log/ directory

Q2. What does the /var/log/dmesg directory contain in the Linux file system?

  • When you Power on Linux machines BIOS calls POST and MBR is loaded. MBR further calls GRUB and finally GRUB calls kernel and kernel gets loaded in memory. While all these process takes place kernel generates lots of messages related to hardware, BIOS, mount file system and stores in /var/log/dmesg directory in the Linux file system which can be viewed using dmesg command.
/var/log/dmesg directory
/var/log/dmesg directory

Q3. What does the /var/log/apt/history.log directory contain in the Linux file system?

  • /var/log/apt/history.log directory contain in the Linux file system provides all the details such as which software or Linux packages were removed, installed or upgraded in the Linux machine. For example when you execute commands like sudo apt update, sudo apt install apcahe2 then all the logs are captured in the /var/log/apt/history.log directory.
/var/log/apt/history.log
/var/log/apt/history.log

Q4. What does the /var/log/auth.log directory contain in the Linux file system?

  • /var/log/auth.log directory contains logs related to the system and user access. Whenever any user log in to the machine or SSH into remote machine to perform any activity all the logs get captured under this file. /var/log/auth.log directory in the Linux file system helps you to find password locked out issues or someone trying to SSH into your machine unnecessarily.
/var/log/auth.log
/var/log/auth.log

Q5. To list all packages in the log file installed using the below command.

cat /var/log/apt/history.log | grep "install"
Listing all the packages in the history.log file
Listing all the packages in the history.log file

Q6. What does the /var/log/kern.log directory contain in the Linux file system?

  • /var/log/kern.log directory provides the information related to kernel warnings, Kernel error messages and Kernel events to the Linux system.
/var/log/kern.log
/var/log/kern.log

Q7. What does the /var/log/Syslog directory in the Linux file system?

  • /var/var/log/Syslog directory provides the in-depth information about your system, application, kernel warnings, Kernel error messages and Kernel events etc. and stores logs. If you are unable to find information in any other files then Syslog directory is your last resort.
/var/log/syslog
/var/log/syslog

Q8. What does the /var/log/apport.log directory contain in the Linux file system?

  • /var/log/apport.log directory provides the in-depth information about the system crash, reports access related issues and OS related failures.
/var/log/apport.log directory
/var/log/apport.log directory
  • If you wish you can configure to schedule these logs in the /etc/logrotate.d/apport directory.
/etc/logrotate.d/apport directory
/etc/logrotate.d/apport directory

Q9. What does the /var/log/ufw.log directory contain in the Linux file system?

  • /var/log/ufw.log directory provides the in-depth information about firewall and network connectivity in the Linux machine.

Q10. What does the /var/log/daemon.log directory contain in the Linux file system?

  • /var/log/daemon.log directory provides the information logged by the various background daemons running in the Linux machine.

Q11. What does the /var/log/apache2/access.log directory contain in the Linux file system?

  • /var/log/apache2/access.log directory contains information logged by apache2 web server. As soon as you install apache2 using the apt install apache2 command you will see this access.log gets created in the Linux machine.
/var/log/apache2/access.log directory
/var/log/apache2/access.log directory

Q12. What does the /var/log/dpkg.log directory contain in the Linux file system?

  • /var/log/dpkg.log directory provides the information related to package installation and similar to /var/log/apt file in the Linux machine.

Q13. Why “.” files are not included in the ls command in the Linux file system?

  • The reason is the configuration files are less likely to be accessed or not accessed at all in the Linux machine.

Q14. Explain the File permissions of the below file in the Linux file system?

drwxr-xr-x   2     sam sam 4096 2015-05-16 17:07 Documents
  • d is a filetype (directory) however it can also have - which represents a file or c that represents character device and finally b represents block device
  • rwxr-xr-x are the permissions of user, group and others respectively where r is read, w is write and x is execute permission. User has rwx permissions, group has r-x permissions and others have r-x permissions.
    • r represents read permission and it has 4 octal value.
    • w represents write permission and it has 2 octal value.
    • x represents execute permission and it has 1 octal value.
    • u represents user, g represents group , o represents others and a represents all( user, group and others)
  • l is the number of links that a file contains.
  • sam is the owner of the file that is documents is owned by the user sam. Group contains multiple users and sam user is part of the sam group which is his primary group.
  • 4096 is the size of the file.
  • 2015-05-16 17:07 displays when was file last accessed.
  • Documents is the file name

Q15. Explain the chmod command practically to change the permissions on the file in the Linux file system?

Chmod: To change the permissions on the file using the chmod command. Let’s learn how to work with the chmod command.

  • chmod a-w file.txt – Subtracting the write permission from all user, group and others.
  • chmod u+rwx file.txt – Adding the read, write and execute permission for user.
  • chmod g-r file.txt – Subtracting the read permission from group
  • chmod 666 file.txt – Granting the read and write access to all user, group and others
  • chmod 714 file.txt
    • Granting the read, write and execute permissions to user.
    • Granting the execute permission to group.
    • Granting the read and write access to others.

Q16. Explain the umask command practically in the Linux file system? Linux file system?

The umask command works like a filter that masks your permissions.

  • 0 represents that it has all the permissions ie. read, write and execute
  • 7 represents no permissions that means it masks all the actual values.
  • UMASK 037 will create a file with -rwxr—– permissions
  • UMASK 000 will create a file with -rwxrwxrwx permissions
  • UMASK 222 will create a file with -r-x-r-x-r-x

Q17. How to check the file type of a file using the file command.

file name_of_the_file
check the filetype of a file
check the filetype of a file

Q18. How to check the permissions of the file using the getfacl command.

 getfacl name_of_the_file
getfacl command
getfacl command

Q19. How to set the permissions of the file using the setfacl command.

# Setting rwx permission for user sam on name_of_the_file
setfacl -m u:sam:rwx name_of_the_file

Q20. Explain all the below Linux commands?

  • Find command in linux: find command in linux search files and directories according to conditions. For example find all .mp3 files that are greater than 10MB and delete them using one single command.
find / -type f -name *.mp3 -size +10M -exec rm{} \;
  • gzip command in linux: gzip command in linux compresses the file size
gzip file_name
  • chattr command in linux: chattr command in linux helps to alter attributes of files but only with root user. For Ex: make directory(+i) and sub files(-R) immutable.
chattr -R +i  temp/
  • Chown command in linux: Chown command in linux allows to change the owner of a file or directory.
chown -R tomat:tomcat /opt
  • mkfs command in linux: mkfs command in linux allows to create a file system.
mkfs.ext2 ~/tmp.img
  • unzip command in linux: unzip command in linux extracts all files from specified ZIP achieves.
unzip myfile.zip
  • mount command in linux: mount command allows to mount the Linux file systems to a directory.
mount  /dev/sda1 media/usb
  • dd command in linux: dd command in linux copies a file, converts and then formats according to the operands.
# Backup the MBR partitioned system, where size is 512b, "if" is input source and "of" is output file.
sudo dd if=/dev/sda bs=512 count=1 of=mbr.img
  • fdisk command in linux: fdisk command in linux stands for Format disk which allows you to create, view, resize, delete and change the partitions on a hard drive.
fdisk /dev/sda
  • sort command in linux: sort command in linux helps in sorting the lines of text files or arranging them.
sort -o output.txt file.txt
  • swap command in linux: swap command in linux is used when the amount of physical RAM memory is full. When a Linux system runs out of RAM, inactive pages are moved from the RAM to the swap space
  • tar command in linux: tar command in linux which stands for Tape Archive is used to compress files which is known as tarball.
tar cjvf abc.tar.gz directory1
  • uniq command in linux: uniq command in linux filters or removes repeated lines in a file.
# -c option specifies how many uniq lines were removed
uniq -c file.txt

Join 28 other followers

Conclusion

In this ultimate guide, you had a chance to revise everything, such as the Linux file system, Linux commands, and Linux log files that you need to know to pass and crack the Linux interview.

Now that you have sound knowledge of Linux and are ready for your upcoming interview.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s