Most Frequently Asked Linux Interview Questions Part 1

https://www.coolcoder.in/2015/07/most-frequently-asked-linux-interview.html
1. What is the difference between installing and upgrading a package with rpm, i.e. rpm -ivh vs rpm -Uvh ?
The general form of an rpm install command is
The general form of an rpm upgrade command is
rpm {-i|--install} [install-options] PACKAGE_FILEThis installs a new package.
The general form of an rpm upgrade command is
rpm {-U|--upgrade} [install-options] PACKAGE_FILEThis upgrades or installs the package currently installed to a newer version. This is the same as install, except all other version(s) of the package are removed after the new package is installed.
2. How do you check network usage by each process in Linux?
You can do this with the help of a tool called Nethogs. Nethogs monitors traffic going to/from a machine, per process.
3. How do you check recently updated or installed packages in Linux?
To list all packages, sorted by install date, latest first
rpm -qa --lastCheck the yum logs to list recent yum operations.
cat /var/log/yum.logUse the yum history command to list all the recent yum operations.
yum history
4. What is Inode? Why there is no file name in the Inode information?
An Inode is a data structure that stores the following information about a file:
- Size of file
- Device ID
- User ID of the file
- Group ID of the file
- The file mode information and access privileges for owner, group and others
- File protection flags
- The timestamps for file creation, modification etc
- link counter to determine the number of hard links
- Pointers to the blocks storing file's contents
5. Is it possible to enable/disable CPU cores on runtime in Linux? If yes, how?
To list current cpu/cores in the system:
# cd /sys/devices/system/cpu # ls -lSample output:
total 0 drwxr-xr-x 4 root root 0 Mar 2 10:00 cpu0 drwxr-xr-x 4 root root 0 Jan 10 08:00 cpu1 drwxr-xr-x 4 root root 0 Jan 10 08:00 cpu2 drwxr-xr-x 4 root root 0 Jan 10 08:00 cpu3To logically turn off any cpu:
echo 0 > /sys/devices/system/cpu/cpu3/onlineTo logically turn on any cpu:
echo 1 > /sys/devices/system/cpu/cpu6/onlineTo verify, run the following commands:
# cat /sys/devices/system/cpu/online # cat /sys/devices/system/cpu/offline
6. How will you differentiate iptables from tcpwrappers?
Tcpwrapper is
- implemented in User space of Linux which means it provides host level security
- works on Application layer
- only applicable to xinetd (?) based services.
- implemented in Kernel space for Linux which means it provides kernel level security
- work on Internet layer but you can extend its functionality to Application layer by using different modules
- with iptables you can restrict access to any ports / protocols or services.
7. How do you exclude certain package(s) while updating all packages with yum?
To exclude single package:
yum --exclude=pkg1\* update yum -x 'pkg1*' updateTo exclude multiple packages:
yum --exclude=pkg1\* --exclude=pkg2\* update yum -x 'pkg1*' -x 'pkg2*' update
8. There are times when files are deleted but space still remains occupied on the file system. So, how to recover free space on deleted files?
Deleting the filename doesn't actually delete the file. Some other process(es) might be holding the file open, causing it not to be deleted; restart or kill that process to release the file. But, that cannot be true for production servers most of the times.
In such case,check with lsof if there are files held open, space will not be freed until they are closed.
In such case,check with lsof if there are files held open, space will not be freed until they are closed.
/usr/sbin/lsof | grep deletedwill show you the deleted files that are still held open. simply kill the file/process to free up space.
9. Differentiate between swap file and swap partition.
- In case of swap file, its easy to resize the swap space while its difficult in case of swap partition.
- Its easy to recover swap filesystem in case of swap partition than swap file.
- One swap partition can be used for multiple OS, but that's not case with swap file.
- Swap file takes very less space, while swap partition requires a separate partition.
- Swap filesystem is fragmented in case of swap files while less fragmented in case of swap partition.
10. What are the different ways to set account expiry date for any user?
usermod -e 2010-10-10 user chage -E 2010-10-10 user useradd user -e 2010-10-10