Popular Linux Interview Questions

Hello there! Linux is one of the most desirable skills in the job market today and after giving over 20 interviews I have come up with a cheat sheet which I personally use and may come in handy for your test or interview. Recruiters are interested in understanding the depth of your knowledge so I have tried to cover important topics like inodes, hard/soft links, LVM to name a few in this article. And now without any further ado, ladies and gentlemen I present Popular Linux Interview Questions! *pff*

🍕Explain sticky bit in linux

Sticky bit is a permission bit that is set on a file or a directory such that only the owner of the file/directory and the root user can rename or delete the file/directory. Details about the sticky bits can be found under the /temp folder.

Enable sticky bit- chmod +t file_name/directory_name

Disable sticky bit- chmod -t file_name/directory_name

🍕What are inodes?

Inode is a data structure that describes a file/directory in linux system by storing metadata about the files. Inodes store information like size of the file, device id, UID, GID, mode (ie permissions), timestamps and pointer to the actual data. In short, inodes store every information about the file except the actual data and the name of the file.

The name of the file is stored separately along with the inode number, this way it can be linked to the metadata representing the file.

By default, inodes per filesystem = 1 inode per 16,384 bytes of filesystem..

Inode related commands-

df -i …gives information about inodes

stat file_name …can be used to view full information about inodes

find . -inum 100056 …can be used to find a file associated with a particular inode in the current directory (note: 100056 is an example, substitute it with the desired inode number)

ln file_A file_B …can be used to link file A to file B, therefore both files will have same inode number

🍕What are hard links?

Hard links are nothing but copies of the actual file with same inode number. In case the user decides to delete a particular file, they will have to delete all hard links associated with it.

Following command can be used to create hard links-

ln actual_filename tobe_hardlink_filename

🍕What are soft links?

Soft links, also known as symbolic links act as a pointer to the actual file. You can imagine soft links as shortcuts in Windows system.

Following command can be used to create soft links-

ln -s actual_filepath tobe_softlink_filename

Interestingly, hard links can be converted into soft links by using the following command-

ln -P filename hardlink_of_actualfile

🍕Where can the information about cron and anacron files be found in linux?

Cron/anacron file for the system can be found under /etc/cron.d

Cron/anacron file for the user can be found under /var/spool/cron/crontab

🍕How to view CPU information?

CPU information like architecture, model, threads, cache can be viewed under /proc/cpu/info or by using the command lscpu

🍕How to view open processes in linux?

Open processes in linux can be viewed under /proc directory or by using the following commands-

ps -ef

top

htop

atop

pgrep

pstree

🍕How to use the SCP command?

Secure copy, commonly known as SCP is used for securely copying files from local host to remote host and vice versa.

Copy files from local to remote host- scp file.txt username@host-ip: /remote/directory/

Copy files from remote to local host- scp -r username@host-ip: /remote/directory /local/directory

🍕What is the default permission of a new file?

By default the permission for a new file is set to 644, meaning, user will have read as well as write access whereas group and other will only have read permission. Linux will try to set 666 as the default permission for any newly created file but will end up setting it to 644 as the umask value is 0022 (Therefore, 666 – 022 = 644)

🍕How to check memory information in linux?

Memory information can be found under the /proc/meminfo directory and by using the following commands-

free -m

vmstat

top

htop

🍕How to reboot a linux system?

Linux systems can be rebooted by CTRL-ALT-DEL or by using simple commands such as-

reboot

reboot -f

restart

shutdown -r

🍕How to detect a hidden file?

The commands ls or ls -l can be used for listing files/directories in a linux system. But to list all files/directories along with the hidden files, use command ls -a. Also, hidden files are preceded by a dot.

Example- .codejammies

🍕How to find disk space taken by a particular folder?

This can be found by checking disk utilization, du -sh

🍕How to append file_A to file_B?

file_A can be appended to file_B by using two output redirection symbols. Example- cat file_A >> file_B

🍕Find the file named codejammies in your linux system

sudo find / -name codejammies -type f

Here / represents root directory and f represents file. If you are looking for a directory, use d instead of f.

🍕What is nohup?

nohup is command used for ignoring any hang ups, upon using this command system will not stop the process irrespective of errors or interruptions.

Example- nohup command OR nohup command &

The & let the process to run in the background.

🍕What is the ideal swap partition size?

In linux, ideally the swap partition size is twice the amount of physical memory present on the system. In cases where this is not possible, the minimum size of swap partition should be equivalent to the amount of physical memory on the system.

🍕Display physical volumes- pvs OR pvdisplay

🍕Display volume groups- vgs OR vgdisplay group_name

🍕Display logical volume (LVM) information- lvs OR lvsdisplay lv_name

🍕List partition types on a linux system- lsblk

🍕List partitions on a linux system- fdisk -l /dev/sda OR fdisk -l | grep /dev/sd

🍕Create a physical volume- pvcreate /dev/sdc

🍕Remove a physical volume- pvremove /dev/sdc

🍕Create a new volume group- vgcreate codejammies /dev/sdc

🍕Rename a volume group- vgrename codejammies codejammy

🍕Remove a volume group- vgremove codejammy

🍕Extend a volume group- vgextend codejammies /dev/sdc

🍕Remove a physical volume from the volume group- vgreduce codejammies /dev/sdc

🍕Create a logical volume- lvcreate -n lv_codejammies

🍕Create a logical volume of a specific size- lvcreate -n lv_codejammies -L4G vg_codejammies

🍕Add space to a filesystem- lvextend /dev/vg_codejammies/lv_codejammies -L+1000M -r

🍕Reduce size of filesystem- lvreduce /dev/vg_codejammies/lv_codejammies -L1000M -r

Linux articles are incomplete without kill signals, so I will be doing a separate article on the same. Hope you enjoyed the read, take it easy!🍹

One Comment Add yours

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 )

Google photo

You are commenting using your Google 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