DevOpsLinux Basics
Linux Basics
Master the Linux command line — the foundation of modern DevOps. Covers filesystem navigation, permissions, package management, process control, and shell scripting.
Filesystem Hierarchy
/bin— Essential user binaries/etc— Configuration files/var— Variable data (logs, databases)/usr— User programs and libraries/proc— Virtual filesystem for processes/tmp— Temporary files (cleared on boot)/home— User home directories
File Permissions
Permissions: rwx (read, write, execute) for Owner / Group / Others.
| Octal | Owner | Group | Other | Use |
|---|---|---|---|---|
| 755 | rwx | r-x | r-x | Executable (common for scripts) |
| 644 | rw- | r-- | r-- | Regular file |
| 600 | rw- | --- | --- | Private file (SSH keys) |
| 700 | rwx | --- | --- | Private directory |
Essential Commands
ls -laList all files with permissions, owner, size, datecd /pathChange directory to specified pathpwdPrint working directorygrep 'pattern' fileSearch for pattern in fileawk '{print $1}' filePrint first column of each linesed 's/old/new/g' fileReplace text across filechmod 755 fileSet rwxr-xr-x permissionschown user:group fileChange file owner and groupps auxList all running processeskill -9 PIDForce kill a process by PIDtop / htopReal-time process monitoringdf -hDisk space usage in human-readable formatPackage Management
- Debian/Ubuntu (apt):
apt update && apt install nginx - RHEL/CentOS (yum/dnf):
yum install -y nginx - Arch (pacman):
pacman -S nginx - Alpine (apk):
apk add nginx
Process Management
ps aux— Snapshot of all processestop— Real-time process viewerkill -15 PID— Graceful terminationkill -9 PID— Force killsystemctl start nginx— systemd service mgmtjournalctl -u nginx— View service logsnice -n -10 ./app— Set process priority
Shell Scripting
#!/bin/bash # Backup script with rotation BACKUP_DIR="/var/backups" SOURCE_DIR="/var/www" RETENTION_DAYS=7 # Create timestamped backup tar -czf "$BACKUP_DIR/backup-$(date +%Y%m%d).tar.gz" "$SOURCE_DIR" # Remove backups older than retention period find "$BACKUP_DIR" -name "*.tar.gz" -mtime +$RETENTION_DAYS -delete # Log the operation echo "[$(date)] Backup completed" >> /var/log/backup.log
Variables
NAME="value"; echo $NAMEConditionals
if [ -f "$file" ]; then ...Loops
for i in {1..10}; do ... doneNetworking & Storage
Network Commands
ss -tuln— Listening portsip addr— IP configurationcurl -v http://...— HTTP debuggingnc -vz host 80— Port connectivity
Disk & Filesystem
df -h— Disk usagedu -sh *— Directory sizesfdisk -l— Partition tablemount /dev/sda1 /mnt— Mount filesystem
Interview Questions
Q1: What is the difference between a hard link and a symbolic link?
A hard link is a direct reference to the inode — it shares the same data blocks as the original file. Deleting the original does not remove the data. A symbolic link (symlink) is a pointer to the filename; if the original is deleted, the symlink breaks. Hard links cannot cross filesystems or link to directories.
Q2: Explain the Linux boot process.
1) BIOS/UEFI performs POST and loads the bootloader. 2) GRUB loads the kernel into memory. 3) Kernel initializes hardware and mounts the initial RAM disk (initramfs). 4) systemd (or init) starts as PID 1 and launches target units. 5) System services and getty are started, presenting the login prompt.
Q3: How do you troubleshoot a high CPU process in Linux?
Use `top` or `htop` to identify the offending PID. Check `strace -p PID` for system calls. Use `perf top` for profiling. For Java apps, use `jstack` to dump thread stacks. Common fixes include restarting the service, adding resource limits via systemd or ulimit, or optimizing the application code.
Q4: What is the role of cgroups and namespaces in Linux containers?
Namespaces provide isolation — they make each container see its own PID, network, mount, and UTS namespace. Cgroups (control groups) limit and account resource usage (CPU, memory, disk I/O). Together they form the foundation of Linux containerization used by Docker and Podman.