Here some of the basic Linux interview question which will help us to pass L1 interview also will help to improve our basic skill in Linux.
1. How to know which ports are listening from your IP address?
# nmap -sT -O your-ip-address
2. How to grep an exact match?
# grep -w infrafile.txt
3. How to reverse grep matches?
# grep -v infrafile.txt
4. How to know which service name is what port?
Assuming port 443
# cat /etc/services | grep -w 443
5. How to get the first 10 lines of a file?
# head -10 infrafile.txt
6. How to get the last 10 lines of a file?
# tail -10 infrafile.txt
7. How to get the first column of a file?
# awk ‘{print $1}’ infrafile.txt
8. How to get the first and second columd of a file?
# awk ‘{print $1 ” ” $2}’ infrafile.txt
9. How to get the first column of a file having consistent field separator pattern?
Field separator character patterns is /
# awk -F/ ‘{print $1}’ infrafile.txt
10. How to get the second column of a file having consistent field separator pattern?
# awk -F/ ‘{print $2}’ infrafile.txt
11. How to show contents of a text file?
# cat infrafile.txt
12. How to show contents of text file pausing ever page or one screenful at a time?
# more infrafile.txt
# less infrafile.txt
13. What is the big difference between more and less?
less linux command has much more extensive enhancements compared with more.
You can also scroll up interactively via control keystrokes using less while the other one does not allow you to do that.
less does not need to read the entire file to buffer when showing a screenful content of a file and furthermorel less is faster than more on accessing big filesize.
14. How do you delete all numbers and digits from contents of a file?
# tr -d [:digit:] < infrafile.txt
15. How do you sort contents of a text file in descending order?
# sort -r infrafile.txt
16. How do you create a file using touch (without opening it interactively for writing)?
# touch infrafile.txt
17. How do you change the date of all files in one folder?
# touch *
18. How do you create a file using tee?
# tee infrafile.txt
and start typing, press
19. How do you query currently installed package offline from your system?
# rpm -qa sendmail
20. How do you query packages for something-like package ?
# rpm -qa | grep sendmail
# rpm -qa *sendmail*
21. What files comes with a something package?
# rpm -qa postfix*
# rpm -ql postfix-2.4.3-2.fc7
22. What is this something package?
# rpm -qi postfix-2.4.3-2.fc7
23. Where does rpm stores its rpm database?
# cd /var/lib/rpm
# ls -la __*
24. How to mount CD drive after inserting the disk?
# mount /dev/cdrom /mnt/CD
25. How to know if fedora detects your Nokia N70 via USB?
# lsusb
26. How to change system date ?
# date -s “December 25 2007 01:01:01″
27. How to know your free base memory and other memory / swap statistics ?
# free
28. How to show disk space usage of your filesystem in human readable form?
# df -ah
29. How to get the top 10 of your mbox mail users?
# cd /var/spool/mail
# ls -lS | head -10
30. How to find process ID of a running service like httpd?
# pidof httpd
31. How to locate a binary file, command source and its man pages?
# whereis ping
32. How to find the location of a executable file that could have been executed when entered from a prompt?
# which ping
33. How to download ISO or any file from web using command line?
# wget -c www.google.com/infrafile.txt
# wget -c ftp://google.com/google.ISO
34. How to transfer file via ssh?
# scp -c infrafile.txt user@remote-hostname
35. How to transfer files that has been only changed from one host to another without taking comparison?
# rsync -avz remoteserver:/home/remotefolder /home/localfolder
36. How to transfer your identity.pub into a remote machine’s authorized_keys?
# ssh-copy-id -i identity-rsa-dsa.pub user@remote-hostname
37. How to know who you are in a shell?
# whoami
38. How to get more real-time view linux process stats and info?
# top
39. How to issue a continuous trace route to a host?
# mtr host-ip-addres
40. How to trace route without resolving IP address?
# mtr –no-dns hostname
41. What is another text-based alternative to chkconfig?
# ntsysv
42. How to list out current cron jobs?
# crontab -l
43. How to get the CPU time?
# clock
44. How to set date and time from NTP server?
# ntpdate 0.fedora.pool.ntp.org
45. How to show current system path?
# set | grep PATH
46. How to list out currently loaded kernel modules?
# lsmod
47. How to know the total days of your system without reboot?
# uptime
48. How to get a system bootstrapped from redhat network?
# /usr/bin/go-rhn.sh
49. How to see current running user jobs?
# jobs
50. How to edit text files from terminal?
# vi infrafile.txt
# nano infrafile.txt
# joe infrafile.txt
# vim infrafile.txt
# pico infrafile.txt (if pico is installed - Pico is a trademark of the University of Washington)
# tee vv
51. How to you change file ownership and chown files recursively?
# chown user:user folder -R
52. How to view queued mail in sendmail or postfix?
# mailq
53. How to show which alternative binary program does your machine executes first?
# alternatives –display program-name
54. How to create public/private rsa key pair?
# ssh-keygen
55. How to log out from your current shell ssh connection?
# Ctrl+D
If you are using sudo
# exit ; exit
56. How to load a particular kernel modules?
# modprobe modulename
57. How to remove a module from kernel?
# rmmod modulename
58. How to show all loaded kernel modules?
# lsmod
59. What is the configuration file and configuration directory for modprobe?
# cd modprobe.d
# cat /etc/modprobe.conf
60. How to check if cooling mode of your machine is active?
# cat /proc/acpi/thermal_zone/THRM/cooling_mode
61. How to show thermal temperature of a machine based from acpi?
# cat /proc/acpi/thermal_zone/THRM/temperature
62. Alternatively, how to view a JPG image from command line alternatively?
# jiv filename.jpg
63. How to sort a file in reverse mode?
# sort -r file.txt
64. How to close your current windows in one keystroke?
# Ctrl+F4
65. How to list out all detected HAL devices?
# lshal
66. How to extract files from Microsoft’s cabinet archives (.cab)?
# cabextract
67. How do to have two eyes following the mouse from screen?
# xeyes
68. How to lock your screen in Gnome using root?
# yum -y install xlockmore
# xlock -mode swarm -count 1
69. How to probe for the modules needed for your hardware monitoring chips to work?
# sensors-detect
70. How to basically build rpm binary package (.rpm) from spec file?
# rpmbuild –ba specfile
(make sure you have the complete build tools and tar ball package in place)
71. How to follow current growth of a log the same way like tail -f ?
# tailf /dir/log filename
72. How to tail 2 or more file in one shot in a single screen?
# yum -y install multitail
# multitail /var/log/file1 /var/log/file2 /var/log/file3
73. How to make a file immutable?
# chattr +i file1
74. How to suid root a file?
# chmod 4755 file
75. How to manage authentication, firewall, network configuration and system service in single screen interface?
# setup
76. How to check mail for your currently logged in user?
77. How to cut and paste inside a CLI terminal using the mouse without X?
# service gpm start
78. How to replace / delete a character from a string value?
# cat infrafile.txt
a
b
c
# tr ‘a’ ‘Z’ < infrafile.txt
Z
b
c
70. How to create symbolic link of file named linkme?
cd to desired folder where to put the softlink file
# cd /var/www/html
# ln -s /home/myhome/linkme
80. How to create and update new system users in batch mode?
# newusers inputfile.txt
# cat inputfile.txt
user1:password1:1001:1001::/home/user1:/bin/false
user2:password2:1002:1002::/home/user2:/bin/bash
user3:password2:1003:1003::/home/user3:/sbin/nologin
81. How to show which system group a user belongs to?
# groups username
82. How to create a new group?
# groupadd newgroupname
83. How to delete an existing group?
# groupdel newgroupname
84. How to delete a user account including user’s home folder files and mail spool?
# userdel -r username
85. Alternatively, how to show currently logged in users?
# users
86. How to unmount CD drive?
# umount /dev/cdrom
87. How to add user account in one shot?
# useradd -d /home/user1 user1 -c “User1 User1″ -s /bin/false -G groupname -p cryptpassword
88. How to transfer file via ssh?
# scp -C file1 user@remote-host:user-folder-destination
89. How to transfer and syncronize files/folder between two machines?
# rync -avz files1 user@remote-host:user-folder-destination
90. How to add more system path to current PATH values?
# export PATH:$PATH:/your-new-path:/another-path
91. Alternatively, how to print current login name?
# logname
92. How to clear current terminal screen?
# clear
# Ctrl+L
93. How to go to the first character of a long command from CLI terminal?
# Ctrl+A
44. How to turn on all swap file specifed from /etc/fstab?
# swapon -a
95. How to pause between command execution?
Ex. 3 seconds
# sleep 3
96. How to show detailed Perl version?
# perl -V
97. How to show current spamassassin version?
# spamassassin -V
98. How to get the numeric identifier of current host?
# hostid
99. How to list file and directory contents in a tree-like format?
cd to desired folder
# tree
100. How to show quick history of commands by root?
# history
Nice blog. Keep updating..
ReplyDeleteLinux Online Training
linux online course
Linux Online Training in Hyderabad
Linux Online Training in Bangalore
Linux Online Training in Chennai