
Linux Interview Question and Answers
- How do you check available memory in Linux?
- Description: The
freecommand shows the amount of free and used memory in your system. - Example:
free -h-hmakes the output human-readable by using units like MB and GB.
- Description: The
- What are some common Linux distributions?
- Description: Linux distributions are different versions of the Linux operating system, each with unique features and software.
- Examples: Ubuntu, Debian, Fedora, CentOS, Red Hat Enterprise Linux.
- What is a symbolic link?
- Description: A symbolic link is a type of file that acts as a shortcut to another file or directory.
- Example:
ln -s /path/to/original /path/to/symlink- This creates a symlink named
symlinkpointing tooriginal.
- This creates a symlink named
- How do you find files on a Linux system?
- Description: The
findcommand searches for files and directories based on specific criteria. - Example:
find /home/user -name "*.txt"- This searches for all
.txtfiles in the/home/userdirectory.
- This searches for all
- Description: The
- What does the
grepcommand do?- Description:
grepsearches for lines in files that match a given pattern. - Example:
grep "search_term" filename.txt- This finds and displays lines in
filename.txtthat contain “search_term”.
- This finds and displays lines in
- Description:
- How can you start or stop services in Linux?
- Description: Services can be managed using
systemctlin systems withsystemd. - Examples:
systemctl start nginx(starts the nginx service) andsystemctl stop nginx(stops the nginx service).
- Description: Services can be managed using
- What is SSH and how is it used?
- Description: SSH (Secure Shell) provides a secure way to access and manage remote computers over an encrypted connection.
- Example:
ssh user@remote_host- This command connects to
remote_hostusing the usernameuser.
- This command connects to
- How do you check disk usage in Linux?
- Description: The
dfcommand shows how much disk space is used and available on file systems. - Example:
df -h-hprovides human-readable output with sizes in KB, MB, or GB.
- Description: The
- What is the role of the Linux kernel?
- Description: The kernel is the core of the Linux operating system, managing hardware resources and system services.
- How do you change file permissions in Linux?
- Description: The
chmodcommand changes who can read, write, or execute a file. - Example:
chmod 755 filename- This gives the owner full permissions and others read and execute permissions.
- Description: The
- What is the purpose of the
tarcommand?- Description:
taris used to create, extract, and manage archive files. - Example:
tar -cvf archive.tar /path/to/directory- This creates an archive named
archive.tarcontaining the contents of/path/to/directory.
- This creates an archive named
- Description:
- How do you compress and decompress files?
- Description: Use
gzipto compress files andgunzipto decompress them. - Examples:
- Compress:
gzip file.txt - Decompress:
gunzip file.txt.gz
- Compress:
- Description: Use
- What is the purpose of the
crondaemon?- Description:
cronschedules tasks to run automatically at specified times or intervals. - Example: To run a script every day at midnight, you might add
0 0 * * * /path/to/script.shto the crontab.
- Description:
- How do you monitor system processes and resources?
- Description: The
topcommand provides a real-time overview of system processes and resource usage. - Example:
top- Displays a dynamic list of running processes and system resource usage.
- Description: The
- What is a firewall in Linux?
- Description: A firewall controls network traffic based on rules to protect your system from unauthorized access.
- Example: Using
iptablesto block traffic on port 22:iptables -A INPUT -p tcp --dport 22 -j DROP.
- How do you create a new user in Linux?
- Description: The
useraddcommand creates a new user account. - Example:
useradd -m newuser- Creates a new user named
newuserwith a home directory.
- Creates a new user named
- Description: The
- How do you check the system’s IP address?
- Description: The
ip addrcommand shows IP addresses assigned to network interfaces. - Example:
ip addr show- Lists all network interfaces and their IP addresses.
- Description: The
- How do you kill a process in Linux?
- Description: Use
killto terminate processes using their PID, orkillallto terminate by process name. - Examples:
kill 1234(kills the process with PID 1234)killall firefox(kills all processes namedfirefox)
- Description: Use
- What is the purpose of the
iptablescommand?- Description:
iptablesconfigures the Linux kernel firewall to manage network traffic. - Example:
iptables -A INPUT -p tcp --dport 80 -j ACCEPT- Allows incoming traffic on port 80.
- Description:
- How do you mount a filesystem in Linux?
- Description: The
mountcommand attaches a filesystem to a directory, making it accessible. - Example:
mount /dev/sdX1 /mnt- Mounts the filesystem on
/dev/sdX1to the/mntdirectory.
- Mounts the filesystem on
- Description: The
- What does the
rsynccommand do?- Description:
rsyncsynchronizes files and directories between locations efficiently. - Example:
rsync -av /source/ /destination/- Copies files from
/source/to/destination/, preserving attributes.
- Copies files from
- Description:
- How do you view hardware information in Linux?
- Description: The
lshwcommand provides detailed information about your system’s hardware. - Example:
lshw -short- Displays a summary of hardware components.
- Description: The
- What is a shell in Linux?
- Description: The shell is a command-line interface for interacting with the operating system by typing commands.
- Example:
bashis a common shell used in Linux systems.
- How do you check network configuration?
- Description: The
ifconfigcommand (deprecated) andipcommand display network settings. - Example:
ip a- Shows details of all network interfaces.
- Description: The
- What does the
chrootcommand do?- Description:
chrootchanges the root directory for a process, isolating it in a new environment. - Example:
chroot /path/to/newroot /bin/bash- Changes the root directory to
/path/to/newrootand starts a bash shell.
- Changes the root directory to
- Description:
- How do you search recursively for a string in files?
- Description: Use
grepwith the-roption to search for a string in all files within a directory. - Example:
grep -r "search_term" /path/to/directory- Searches for “search_term” in all files under
/path/to/directory.
- Searches for “search_term” in all files under
- Description: Use
- What is the purpose of the
findcommand?- Description:
findsearches for files and directories based on various criteria. - Example:
find /home/user -type f -name "*.jpg"- Finds all
.jpgfiles in the/home/userdirectory.
- Finds all
- Description:
- How do you check CPU usage in Linux?
- Description: Use
top,htop, ormpstatto view CPU usage and process information. - Example:
top- Displays a dynamic, real-time list of processes and CPU usage.
- Description: Use
- How do you check file permissions in Linux?
- Description: Use
ls -lto display file permissions along with other file details. - Example:
ls -l filename- Shows permissions, ownership, and other details of
filename.
- Shows permissions, ownership, and other details of
- Description: Use
- What is the role of the
grepcommand?- Description:
grepsearches for lines in files that match a specified pattern and outputs them. - Example:
grep "error" logfile.txt- Finds and displays lines in
logfile.txtcontaining the word “error”.
- Finds and displays lines in
- Description:
