Contents of DevOps

Essential DevOps tips, tricks, and best practices to improve your coding skills and write more efficient code.

Comprehensive Linux Interview Questions & Answers for DevOps: Master Essential Commands and Concepts

🧾 Introduction to Linux

1. What is Linux?
Linux is an open-source, Unix-like operating system kernel. It powers a wide range of systems from servers and desktops to mobile devices. It's known for stability, flexibility, and security.

2. How is Linux different from Unix?
Linux is free and open-source, while most Unix systems are proprietary. Linux supports more hardware and has more frequent updates.

3. Why is Linux preferred in DevOps?

  • Open-source and customizable
  • Powerful command-line interface
  • Automation-friendly (scripts, cron, systemd)
  • Wide tool support (Docker, Kubernetes, Ansible)

πŸ“ Commands and File Systems

1. How do you list files in a directory?
ls β€” basic listing
ls -a β€” includes hidden files
ls -l β€” long format with permissions, size, etc.

2. Absolute vs Relative Path?

  • Absolute: Starts from /, e.g., /home/user/docs
  • Relative: Based on current directory, e.g., ../docs

3. Linux file system hierarchy:

  • / – root
  • /home – user directories
  • /etc – configuration files
  • /var – logs
  • /bin – essential commands

πŸ› οΈ Common Commands

1. touch file.txt β€” creates an empty file or updates timestamp.

2. Copy directory:
cp -r source/ target/

3. mv old.txt new.txt β€” renames or moves file.

4. Rename a directory:
mv old_folder new_folder

5. Nested directory creation:
mkdir -p parent/child/grandchild


πŸ“ Vim Editor

1. Enter insert mode:
Press i

2. Save and exit:
:wq (write and quit)
:q! (quit without saving)

3. Delete entire line:
dd


πŸ“‚ File Types

1. File types in Linux:

  • Regular file (-)
  • Directory (d)
  • Symbolic link (l)
  • Block device (b)
  • Character device (c)

2. Check file type:
ls -l or file filename

3. Symbolic vs Hard Link:

  • Symbolic: Pointer to original (breaks if original deleted)
  • Hard: Another reference to the same inode (doesn’t break)

πŸ” Filters

1. grep 'text' file.txt β€” searches for text in files.

2. Display first 10 lines:
head file.txt

3. cut -d',' -f1 file.csv β€” extract fields
4. awk '{print $1}' file.txt β€” advanced field processing

5. sort, uniq β€” sort lines, remove duplicates.


πŸ” Redirections

1. > vs >>

  • >: Overwrites
  • >>: Appends

2. Redirect stdout and stderr:
command > output.txt 2>&1

3. What is 2>&1?
Redirects stderr (2) to stdout (1)


πŸ‘₯ Users and Groups

1. Create user:
sudo adduser newuser

2. Add user to group:
sudo usermod -aG groupname username

3. Switch user:
su - username or sudo -i


πŸ” File Permissions

1. rwx Meaning:

  • r: Read
  • w: Write
  • x: Execute

2. chmod 755 file

  • Owner: rwx
  • Group: r-x
  • Others: r-x

3. Change ownership:
sudo chown user:group file


⚠️ Sudo

1. What is sudo?
Allows users to run commands as another user (usually root).

2. Give sudo access:
Add user to sudo group:
sudo usermod -aG sudo username

3. su vs sudo

  • su: Switch user (requires user’s password)
  • sudo: Run one command as root (requires own password)

πŸ“¦ Package Management (Ubuntu/Debian)

1. Install a package:
sudo apt install package-name

2. Update list and upgrade packages:

sudo apt update sudo apt upgrade

3. apt vs apt-get

  • apt: User-friendly, newer
  • apt-get: Backward-compatible, scripting

πŸ” Services (Systemd)

1. Check status:
sudo systemctl status nginx

2. Start/Stop/Enable/Disable:

sudo systemctl start nginx sudo systemctl stop nginx sudo systemctl enable nginx sudo systemctl disable nginx

3. systemctl vs service:

  • systemctl: Newer systemd interface
  • service: Older, SysVinit style

βš™οΈ Processes

1. List processes:
ps aux or top

2. Kill process by PID:
kill -9 PID

3. Kill by name:
pkill processname

4. Zombie process?
A child process that has completed but still has an entry in the process table.


πŸ“¦ Archiving

1. Create .tar.gz:
tar -czvf archive.tar.gz folder/

2. Extract .tar.gz:
tar -xzvf archive.tar.gz

3. Zip/unzip:

zip file.zip file1 file2 unzip file.zip

πŸ§ͺ Ubuntu/Linux Specific

1. Check Ubuntu version:
lsb_release -a or cat /etc/os-release

2. Disk usage:

  • df -h β€” disk free space
  • du -sh folder/ β€” folder size

3. Check memory usage:
free -h


Would you like a downloadable version (PDF/Markdown/Notion doc/HTML)? Or want me to help you generate flashcards for spaced repetition learning too?

🐧 Extra Linux Interview Questions & Answers


πŸ”§ Shell Basics

Q: What is a shell in Linux?
A shell is a command-line interpreter that lets users interact with the OS. The most common one is bash (Bourne Again Shell).

Q: How do you find your current shell?

echo $SHELL

πŸ—‚ File and Directory Operations

Q: How do you find a file in Linux?

find /path -name "filename"

Q: How do you search for a string inside files?

grep "text" *.txt

βŒ› Scheduled Tasks

Q: What is cron in Linux?
cron is a time-based job scheduler. Users can schedule tasks using crontab.

Q: How do you list your cron jobs?

crontab -l

Q: Create a cron job to run a script every day at 5 PM.

0 17 * * * /path/to/script.sh

πŸ›œ Networking

Q: Check current IP address:

ip a

Q: Ping a host:

ping google.com

Q: Check open ports:

netstat -tuln

or

ss -tuln

🧱 Disk & Partitioning

Q: How to check disk partitions?

lsblk

Q: Format a disk with ext4:

mkfs.ext4 /dev/sdX

πŸ§ͺ Useful Linux Utilities

Q: How do you monitor system usage live?

  • top
  • htop (better UI, if installed)
  • iotop (for disk I/O)

Q: How do you check system uptime?

uptime

πŸ”„ File Comparison and Differences

Q: Compare two files:

diff file1.txt file2.txt

Q: How do you see the number of lines, words, and characters in a file?

wc file.txt

πŸ” SSH & Remote Access

Q: What is SSH?
Secure Shell (SSH) allows encrypted remote login to other systems.

Q: SSH into a server:

ssh user@ip-address

Q: Copy a file to a remote server via SSH:

scp file.txt user@server:/path/

πŸ“ Logs & Debugging

Q: View real-time logs:

tail -f /var/log/syslog

Q: Check authentication logs:

cat /var/log/auth.log

🧹 Cleanup & Housekeeping

Q: Remove all .log files in a directory:

rm *.log

Q: Empty a file without deleting it:

> file.txt

πŸ“‹ File Descriptors

Q: What are stdin, stdout, stderr?

  • 0: stdin (input)
  • 1: stdout (output)
  • 2: stderr (error output)

🧠 Bonus: Behavioral

Q: What are your favorite Linux commands for debugging or productivity?
Example answer:

I often use htop for real-time system monitoring, grep and awk for log analysis, journalctl for viewing systemd logs, and tmux for managing multiple sessions on remote servers.