Operations 24 min read

Master Linux Command‑Line Essentials for Interview Success

This comprehensive guide covers the most frequently asked Linux command‑line topics for interviews, including file and directory manipulation, process management, system monitoring, networking, permission handling, and practical scenario‑based exercises, all illustrated with clear examples and command syntax.

IT Services Circle
IT Services Circle
IT Services Circle
Master Linux Command‑Line Essentials for Interview Success

File and Directory Operations

Basic file and directory commands are essential in Linux interviews, covering listing, creating, deleting, and moving files.

1. ls – List directory contents

Displays files and subdirectories in the current or specified directory.

Common options: -l: long format with permissions, owner, size, etc. -a: include hidden files (starting with .). -h: human‑readable sizes.

ls -lah /var/log
ls example
ls example

2. cd – Change directory

Switches to the specified directory.

Common usage:

cd /path/to/dir
cd ..

– parent directory cd ~ – home directory cd - – previous directory

cd /etc/nginx
cd ..

3. pwd – Print working directory

Shows the absolute path of the current directory.

pwd
pwd output
pwd output

4. mkdir – Create directory

Creates a new directory.

Common option: -p creates parent directories as needed.

mkdir -p /tmp/test/dir1/dir2

5. rm – Remove files or directories

Deletes specified files or directories.

Common options: -r: recursive delete -f: force, no prompt

rm -rf /tmp/test

6. cp – Copy files or directories

Copies files or directories to a target location.

Common options: -r: recursive copy -p: preserve attributes

cp -r /etc/nginx /backup/nginx

7. mv – Move or rename files/directories

Moves or renames a file or directory.

Common option: -i prompts before overwriting.

mv file1.txt /tmp/file2.txt

8. find – Search for files

Searches for files or directories matching criteria.

Common options: -name: pattern matching -type f|d: file or directory -exec: execute a command on results

find /var/log -name "*.log" -type f -mtime +7 -exec ls -lh {} \;
find example
find example

9. touch – Create empty file or update timestamp

touch test.txt

File Content Operations

10. cat – View file contents

Outputs file content to standard output.

Common option: -n shows line numbers.

cat -n /etc/passwd
cat example
cat example

11. less / more – Paginated view

Displays file content page by page, useful for large files.

Key commands: / search, q quit.

less /var/log/syslog

12. head / tail – View beginning or end of a file

head

shows the start; tail shows the end.

Common option: -n number of lines.

tail -f /var/log/nginx/access.log

13. grep – Search file contents

Searches for matching strings.

Common options: -i: ignore case -r: recursive -n: show line numbers -v: invert match

grep -r "error" /var/log
grep example
grep example

14. awk – Text processing

Processes columns, e.g., extracting fields.

awk '{print $1,$3}' /etc/passwd
awk example
awk example

15. sed – Stream editor

Performs text substitution, deletion, insertion.

sed 's/old/new/g' file.txt

Process Management

16. ps – View processes

Shows current processes.

Common options: aux (all users), -ef (full format).

ps aux | grep nginx
ps example
ps example

17. top / htop – Real‑time process monitor

Displays live system processes; htop offers a friendlier UI.

Key keys: q quit, k kill process.

htop
htop example
htop example

18. kill / killall – Terminate processes

Kill by PID ( kill) or by name ( killall).

Common signals: -9 (SIGKILL) – force kill -15 (SIGTERM) – graceful termination

kill -9 12345
killall nginx

19. jobs / fg / bg – Manage background jobs

List, bring to foreground, or send to background.

sleep 100 &
jobs
fg %1

System Monitoring

20. df – Disk usage

Shows filesystem space.

Option: -h human‑readable.

df -h
df example
df example

21. du – Directory/file size

Summarizes disk usage for files/directories.

Option: -sh total size, human‑readable.

du -sh /var/log/*
du example
du example

22. free – Memory usage

Displays RAM and swap usage.

Option: -h human‑readable.

free -h
free example
free example

23. uptime – System uptime and load

uptime

Network Related

24. ping – Test connectivity

ping -c 4 baidu.com
ping example
ping example

25. netstat / ss – Network status

Shows connections, listening ports, etc.

Common option (ss): -tuln display TCP/UDP listening ports.

ss -tuln
ss example
ss example

26. curl / wget – Download/request resources

curl -O https://example.com/file.txt

27. ifconfig / ip – Configure network interfaces

ip addr
ip example
ip example

Permission Management

28. chmod – Change file permissions

Modify access rights.

Numeric mode: e.g., 755 (rwxr-xr-x).

Symbolic mode: e.g., u+x (add execute for owner).

chmod 755 script.sh

29. chown – Change file owner

Change owner and group.

Option: -R recursive.

chown -R user:group /var/www

30. sudo – Execute with elevated privileges

sudo apt update

Other Useful Commands

31. tar – Archive and compress

Common options: -c create -x extract -z gzip -f specify file

tar -czvf backup.tar.gz /var/www

32. crontab – Schedule tasks

Common options: -e edit, -l list. crontab -e Add a daily 2 AM backup:

0 2 * * * /backup.sh

33. man – Command manual

man ls
man example
man example

Scenario‑Based Interview Questions

Scenario 1 – Find and clean old log files

Find .log files in /var/log older than 7 days, list sizes, and safely delete.

find /var/log -type f -name "*.log" -mtime +7 -exec ls -lh {} \;

Save list for review:

find /var/log -type f -name "*.log" -mtime +7 > /tmp/old_logs.txt
cat /tmp/old_logs.txt

Move to backup before deletion:

mkdir -p /tmp/log_backup
find /var/log -type f -name "*.log" -mtime +7 -exec mv {} /tmp/log_backup/ \;
rm -rf /tmp/log_backup/*

Scenario 2 – Identify and kill high‑CPU process

Use top or htop to locate the highest CPU consumer, note PID, then:

ps -p <PID> -o pid,ppid,cmd,%cpu
kill -15 <PID>   # graceful
kill -9 <PID>    # force if needed

Scenario 3 – Batch modify configuration files

Replace listen 80 with listen 8080 in all .conf files under /etc/nginx/conf.d:

cp -r /etc/nginx/conf.d /etc/nginx/conf.d.bak
find /etc/nginx/conf.d -type f -name "*.conf" -exec sed -i 's/listen 80/listen 8080/g' {} \;

Scenario 4 – Real‑time log monitoring

tail -f /var/log/nginx/error.log | grep --line-buffered "error"

Scenario 5 – Check and free disk space

df -h
du -sh /var/* | sort -hr | head -n 5
cp /var/log/app.log /backup/app.log.bak
> /var/log/app.log

Scenario 6 – Configure daily backup via cron

# /scripts/backup.sh
#!/bin/bash
DATE=$(date +%Y%m%d)
 tar -czf /backup/www_${DATE}.tar.gz /var/www
 find /backup -name "www_*.tar.gz" -mtime +30 -delete
chmod +x /scripts/backup.sh
crontab -e   # add: 0 2 * * * /scripts/backup.sh

Scenario 7 – Diagnose network connectivity

ping -c 4 baidu.com
nslookup baidu.com
ip addr
ip route
cat /etc/resolv.conf
# optionally add DNS
 echo "nameserver 8.8.8.8" | sudo tee -a /etc/resolv.conf

Scenario 8 – Set directory permissions

chown -R www-data:www-data /var/www/html
find /var/www/html -type d -exec chmod 755 {} \;
find /var/www/html -type f -exec chmod 644 {} \;

Scenario 9 – Release occupied port

ss -tuln | grep :80   # or lsof -i :80
kill -15 12345   # graceful
kill -9 12345    # force

Scenario 10 – Extract recent IPs and URLs from Nginx access log

tail -n 100 /var/log/nginx/access.log | awk '{print $1, $7}' > /tmp/access.txt

These examples provide ready‑to‑use commands and best‑practice explanations to help you excel in Linux‑related interview questions.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxInterview Preparationcommand-lineSystem AdministrationShell Commands
IT Services Circle
Written by

IT Services Circle

Delivering cutting-edge internet insights and practical learning resources. We're a passionate and principled IT media platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.