CampusFlow
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.

OctalOwnerGroupOtherUse
755rwxr-xr-xExecutable (common for scripts)
644rw-r--r--Regular file
600rw-------Private file (SSH keys)
700rwx------Private directory

Essential Commands

ls -laList all files with permissions, owner, size, date
cd /pathChange directory to specified path
pwdPrint working directory
grep 'pattern' fileSearch for pattern in file
awk '{print $1}' filePrint first column of each line
sed 's/old/new/g' fileReplace text across file
chmod 755 fileSet rwxr-xr-x permissions
chown user:group fileChange file owner and group
ps auxList all running processes
kill -9 PIDForce kill a process by PID
top / htopReal-time process monitoring
df -hDisk space usage in human-readable format

Package 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 processes
  • top — Real-time process viewer
  • kill -15 PID — Graceful termination
  • kill -9 PID — Force kill
  • systemctl start nginx — systemd service mgmt
  • journalctl -u nginx — View service logs
  • nice -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 $NAME
Conditionals
if [ -f "$file" ]; then ...
Loops
for i in {1..10}; do ... done

Networking & Storage

Network Commands

  • ss -tuln — Listening ports
  • ip addr — IP configuration
  • curl -v http://... — HTTP debugging
  • nc -vz host 80 — Port connectivity

Disk & Filesystem

  • df -h — Disk usage
  • du -sh * — Directory sizes
  • fdisk -l — Partition table
  • mount /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.