Continuing from the previous set, here are more essential Linux questions and topics that commonly arise in interviews, with practical use cases, troubleshooting tips, and best practices.
Q13: What is an inode in Linux?
Answer:
An inode is a data structure containing metadata about a file, like permissions and ownership:
ls -i # Show inode numbers
stat filename # Show detailed inode info
find / -inum [inode_number] # Find files with same inode
Use Case: Understand file structure and manage disk space.
Gotchas: Running out of inodes can lead to storage issues despite free space.
Q14: How do you check CPU utilization in Linux?
Answer:
top/htop # Real-time system monitoring
mpstat # CPU-specific statistics
vmstat # Virtual memory statistics
perf/sar # System activity reporter
Best Practice: Use htop
for interactive monitoring.
Advanced Use Case: For detailed analysis, consider perf
or sar
.
Troubleshooting: Look for processes with high CPU in top
and investigate as needed.
Example Use Case:
# Check CPU usage every 2 seconds
top -b -n 1 | grep "Cpu(s)"
# Monitor specific process
top -p $(pgrep process_name)
Q15: What are the differences between the top and htop commands?
Answer:
top: Basic system monitor.
htop: Enhanced features:
- Color output
- Vertical/horizontal scrolling
- Tree view
- Mouse support
When to Use Which:
top # Quick system check, available everywhere
htop # Detailed analysis, process management
Q16: What is a mount in Linux, and how do you create one?
Answer:
Mount connects storage devices to filesystem:
# Basic mount
mount /dev/sdb1 /mnt/data
# With specific options
mount -o rw,user /dev/sdb1 /mnt/data
# Automatic mount (in /etc/fstab)
/dev/sdb1 /mnt/data ext4 defaults 0 2
Common Use Cases – Mounting network shares:
mount -t nfs server:/share /local/mount
mount -t cifs //server/share /local/mount
Q17: How do you troubleshoot live logs in Linux?
Answer:
# Follow log in real-time
tail -f /var/log/syslog
# Multiple logs simultaneously
tail -f /var/log/syslog /var/log/auth.log
# With grep
tail -f /var/log/syslog | grep --line-buffered "error"
Advanced Use Case – Monitoring multiple services:
# Using multitail
multitail /var/log/nginx/access.log -I /var/log/mysql/error.log
Q18: What is the sed command in Linux?
Answer:
Stream editor for text manipulation:
# Replace text
sed 's/old/new/g' file
# Delete lines
sed '/pattern/d' file
# Insert text
sed '2i\new line' file
Gotchas: Use caution with -i
(in-place editing), as it overwrites files.
Practical Applications:
# Configuration file updates
sed -i 's/debug=false/debug=true/' config.ini
# Batch file renaming
for f in *.txt; do
sed -i 's/error/warning/' "$f"
done
Q19: What is the awk command in Linux?
Answer:
Pattern scanning and text processing:
# Print specific columns
awk '{print $1, $3}' file
# Sum numbers
awk '{sum += $1} END {print sum}' file
# Filter rows
awk '$3 > 100' file
Use Case: Ideal for data extraction and reporting from logs or CSV files.
Advanced Usage: Use awk
for complex filtering or field calculations.
Gotchas: Understand file delimiters, especially with non-standard formats.
Real-world Use Cases:
# Log analysis
awk '$9 >= 400' access.log # Find HTTP errors
# Resource monitoring
ps aux | awk 'NR>1{sum += $3} END {print "CPU%: " sum}'
Q20: What are the grep and egrep commands in Linux?
Answer:
Search for patterns in text files:
grep pattern file # Basic search
egrep "pat1|pat2" file # Extended regex
grep -r pattern dir # Recursive search
Use Case: Quickly find log entries, error messages, or configuration lines.
Gotchas: By default, grep
is case-sensitive. Use -i
for case-insensitive matches.
Common Applications:
# Security monitoring
grep "Failed password" /var/log/auth.log
# Code analysis
grep -r "TODO" ./src/
Q21: How can you list only directories in Linux?
Answer:
ls -d */ # Basic directory listing
ls -l | grep "^d" # With detailed info
find . -maxdepth 1 -type d # Using find
Use Cases:
# Backup directories only
for d in */; do
tar czf "${d%/}.tar.gz" "$d"
done
Q22: How do you check the processes running in Linux?
Answer:
ps aux # All processes
ps -ef # Full format listing
pgrep process_name # Get process ID
Monitoring Scenarios:
# Memory-hungry processes
ps aux --sort=-%mem | head
# Process tree
pstree -p
Q23: How do you get a Java thread dump in Linux?
Answer:
Command: jstack PID
Use Case: Useful for debugging Java application issues.
jstack PID > thread_dump.txt
kill -3 PID # Send SIGQUIT
# For multiple dumps
for i in {1..3}; do
jstack PID > dump_$i.txt
sleep 10
done
Best Practice: Save dumps with timestamps for detailed analysis later.
Troubleshooting: If jstack
isn’t available, install JDK tools or use kill -3 PID
.
Q24: How can you check the running ports on a Linux machine?
Answer:
netstat -tulpn # All listening ports
ss -tulpn # Modern alternative
lsof -i # File-based approach
Security Applications:
# Find unauthorized services
netstat -tulnp | grep LISTEN
# Monitor specific port
watch -n 1 'netstat -an | grep :80'
Gotchas: Only root
or privileged users can access full port lists.
I will continue with other questions later on.
In the next parts, we’ll cover questions focused on:
Questions 25-36: Shell Scripting and Advanced Topics