Getting everything ready for you…

Loading courses, problems and your progress. This takes just a moment.

0s

Linux Documentation

The OS of servers and the cloud — files, permissions, processes, packages, networking, SSH and services.

Linux runs most of the world's servers, cloud machines, Android phones and containers. Every backend or DevOps developer needs to be comfortable in its terminal: moving around the file system, managing files and permissions, processes, packages, networking and services. These docs use Ubuntu/Debian commands; most work on any distribution. For shell scripting see Bash / Shell.

1. Introduction & Setup

  • Kernel: the core that manages hardware, memory and processes. A distribution = kernel + tools + package manager (Ubuntu, Debian, Fedora, Arch, RHEL/Rocky, Alpine).
  • Try it on Windows: WSL — wsl --install in an admin PowerShell, then open "Ubuntu". On any OS: a VM (VirtualBox), a cloud VM, or docker run -it ubuntu bash.
whoami
uname -a
cat /etc/os-release | head -2

Output:

asha
Linux codify 6.8.0-45-generic #45-Ubuntu SMP x86_64 GNU/Linux
PRETTY_NAME="Ubuntu 24.04.1 LTS"
NAME="Ubuntu"

Getting help:

man ls            # full manual (q to quit, /word to search)
ls --help         # short help
tldr tar          # practical examples (install: sudo apt install tldr)

2. File System & Navigation

Everything starts at / (root). There are no drive letters.

Path Contains
/home/<user> (~) your files
/root the root user's home
/etc system configuration files
/var variable data — logs (/var/log), web files (/var/www)
/usr/bin, /bin programs
/tmp temporary files (cleared on reboot)
/opt optional/third-party software
/dev, /proc, /sys devices and kernel/process info
/mnt, /media mounted drives
pwd                    # where am I?
ls -la                 # list all (incl. hidden) with details
cd /var/log            # absolute path
cd ..                  # up one level
cd ~  or  cd           # home
cd -                   # previous directory
tree -L 2              # directory tree (sudo apt install tree)

Hidden files start with a dot (.bashrc, .env). Tab completes names; ↑ recalls history; Ctrl + R searches history; Ctrl + C stops a command; clear or Ctrl + L clears the screen.

3. Working with Files

touch notes.txt                 # create empty file / update time
mkdir -p projects/codify/src    # create nested folders
cp a.txt b.txt                  # copy
cp -r src/ backup/              # copy a folder
mv old.txt new.txt              # rename / move
rm file.txt                     # delete (no recycle bin!)
rm -r folder/                   # delete a folder
rmdir empty-folder
ln -s /opt/app/current app      # symbolic link

Viewing files:

cat file.txt                    # print everything
less big.log                    # scroll (q to quit)
head -n 20 file.txt             # first 20 lines
tail -n 50 app.log              # last 50 lines
tail -f app.log                 # follow new lines live
wc -l file.txt                  # count lines
nano file.txt                   # simple editor (Ctrl+O save, Ctrl+X exit)
vim file.txt                    # i = insert, Esc then :wq = save & quit, :q! = quit without saving

⚠️ rm -rf deletes without asking. Double-check the path — never run it with a variable that might be empty (rm -rf $DIR/).

4. Searching, Pipes & Text Processing

find . -name "*.js"                     # files by name
find /var/log -size +100M               # large files
find . -type f -mtime -1                # changed in the last day
grep "error" app.log                    # lines containing "error"
grep -rin "todo" src/                   # recursive, ignore case, line numbers
grep -v "DEBUG" app.log                 # lines NOT matching
which node                              # where a command lives

Pipes (|) send one command's output into another; redirection writes to files:

cat access.log | grep " 500 " | wc -l          # count 500 errors
ls -l | sort -k5 -n | tail -5                  # 5 largest files
echo "hello" > out.txt                          # overwrite
echo "again" >> out.txt                         # append
command 2> errors.txt                           # stderr only
command > all.txt 2>&1                          # stdout + stderr

Text tools:

cut -d',' -f2 data.csv                          # 2nd column of a CSV
sort names.txt | uniq -c | sort -rn             # count duplicates, most first
awk '{print $1}' access.log | sort | uniq -c | sort -rn | head   # top IPs
sed 's/http:/https:/g' links.txt                # find and replace
tr 'a-z' 'A-Z' < file.txt                       # upper-case

5. Users, Groups & Permissions

ls -l script.sh
-rwxr-xr-- 1 asha devs 512 Oct 27 10:00 script.sh
│└┬┘└┬┘└┬┘   │    │
│ │  │  │    owner group
│ │  │  └ others: r-- (read)
│ │  └ group:  r-x (read, execute)
│ └ owner:     rwx (read, write, execute)
└ type: - file, d directory, l link
Number Permission
4 read (r)
2 write (w)
1 execute (x)

755 = rwx r-x r-x (programs, folders) · 644 = rw- r-- r-- (normal files) · 600 = rw- --- --- (private keys) · avoid 777.

chmod 755 deploy.sh             # numeric
chmod +x deploy.sh              # add execute
chmod -R u+rw,go-w project/     # symbolic, recursive
chown asha:devs file.txt        # change owner and group
sudo command                    # run as root (administrator)
sudo adduser ravi               # new user
sudo usermod -aG sudo ravi      # add to a group
id; groups                      # your user id and groups

⚠️ Common error: Permission denied — check ls -l; you may need chmod +x to run a script, or sudo for system files.

6. Processes & System Monitoring

ps aux | grep node              # find processes
top                             # live view (q to quit); htop is nicer
kill 1234                       # ask process 1234 to stop (SIGTERM)
kill -9 1234                    # force kill (SIGKILL) — last resort
pkill -f "node server.js"       # kill by name/command line
./long-task.sh &                # run in background
jobs; fg %1; bg %1              # manage background jobs
nohup ./server.sh > out.log 2>&1 &   # keep running after logout

System resources:

free -h                         # memory
df -h                           # disk space per filesystem
du -sh * | sort -h              # size of each item here
uptime                          # load average
nproc                           # CPU cores
lsof -i :3000                   # what is using port 3000

For long sessions on servers use tmux or screen so work continues if SSH disconnects.

7. Package Management

Distro Install Update everything
Ubuntu / Debian sudo apt install nginx sudo apt update && sudo apt upgrade
Fedora / RHEL / Rocky sudo dnf install nginx sudo dnf upgrade
Arch sudo pacman -S nginx sudo pacman -Syu
Alpine (Docker) apk add nginx apk upgrade
sudo apt update                       # refresh the package list
sudo apt install -y git curl build-essential
apt search postgres
sudo apt remove --purge apache2
sudo apt autoremove

Install Node.js with a version manager instead of the old distro package:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
nvm install --lts

8. Networking & SSH

ip a                              # interfaces and IP addresses
ping -c 4 google.com
curl -I https://codify.example    # response headers
curl -s https://api.github.com/users/octocat | head
wget https://example.com/file.zip
ss -tulpn                         # listening ports and their processes
dig codify.example +short         # DNS lookup
traceroute google.com

SSH — log in to a remote server securely:

ssh-keygen -t ed25519 -C "asha@example.com"     # create a key pair (~/.ssh/id_ed25519)
ssh-copy-id ubuntu@203.0.113.10                  # install your public key on the server
ssh ubuntu@203.0.113.10                          # connect
scp app.zip ubuntu@203.0.113.10:/home/ubuntu/    # copy a file
rsync -avz dist/ ubuntu@203.0.113.10:/var/www/app/   # sync a folder efficiently

Server hardening basics: key-only login (PasswordAuthentication no in /etc/ssh/sshd_config), no root login, firewall:

sudo ufw allow OpenSSH
sudo ufw allow 80,443/tcp
sudo ufw enable
sudo ufw status

9. Services, Logs & Scheduling

systemd starts and supervises services:

sudo systemctl status nginx
sudo systemctl start|stop|restart|reload nginx
sudo systemctl enable nginx         # start on boot
journalctl -u nginx -f              # follow a service's logs
journalctl --since "1 hour ago"

Run your Node app as a service:

# /etc/systemd/system/codify.service
[Unit]
Description=Codify API
After=network.target

[Service]
User=ubuntu
WorkingDirectory=/home/ubuntu/codify/server
EnvironmentFile=/home/ubuntu/codify/server/.env
ExecStart=/usr/bin/node src/index.js
Restart=always

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload && sudo systemctl enable --now codify

cron runs commands on a schedule (crontab -e):

# ┌ minute (0-59)  ┌ hour (0-23)  ┌ day of month  ┌ month  ┌ day of week (0=Sun)
  0  2  *  *  *   /home/ubuntu/backup.sh >> /var/log/backup.log 2>&1   # 2:00 AM daily
  */15 * * * *    curl -s https://codify.example/health > /dev/null     # every 15 minutes

10. Advanced Concepts

  • Environment variables: export API_URL=https://…, echo $PATH, persist in ~/.bashrc (or ~/.profile); env lists them.
  • Archives: tar -czvf backup.tar.gz folder/ (create), tar -xzvf backup.tar.gz (extract), zip -r a.zip dir, unzip a.zip.
  • Links: hard link = another name for the same inode; symbolic link = a pointer to a path.
  • Signals: SIGTERM (15, polite stop), SIGKILL (9, can't be caught), SIGINT (2, Ctrl+C), SIGHUP (reload config).
  • Exit codes: 0 = success; echo $? shows the last one; && runs the next command only on success, || only on failure.
  • Disk & mounts: lsblk, mount, /etc/fstab; swap with swapon.
  • Boot process: firmware (BIOS/UEFI) → bootloader (GRUB) → kernel → init (systemd, PID 1) → services → login.
  • Linux in containers: containers use kernel namespaces (isolation) and cgroups (resource limits) — that's how Docker works.

11. Examples with Output

Example 1 — Count lines of code

find src -name "*.js" | xargs wc -l | tail -1
  4821 total

Example 2 — Top 3 IPs in an access log

awk '{print $1}' access.log | sort | uniq -c | sort -rn | head -3
    912 203.0.113.7
    455 198.51.100.23
    120 192.0.2.44

Example 3 — Disk usage

df -h /
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        40G   12G   26G  32% /

12. Practice Problems

  1. Create the folder tree projects/{api,web}/src in one command and list it with tree.
  2. Find all .log files bigger than 10 MB under /var/log and show their sizes sorted.
  3. Count how many requests in an nginx access log returned status 404.
  4. Create a user deploy, add them to a web group, and give the group write access to /var/www/app only.
  5. Write a systemd service for a Node app that restarts on crash, and read its logs with journalctl.
  6. Schedule a cron job that compresses yesterday's logs every night at 1 AM.
  7. Set up SSH key login to a VM and disable password login.
  8. Find which process is using port 5000 and stop it.

13. Interview Questions

1. What is the Linux kernel vs a distribution? The kernel manages hardware, processes and memory; a distribution bundles it with tools, a package manager and defaults.

2. Explain chmod 755. Owner rwx (7), group r-x (5), others r-x (5).

3. Process vs thread? How do you find and kill a process? A process has its own memory; threads share it. Use ps aux | grep name / pgrep, then kill PID (or kill -9 if it won't stop).

4. Hard link vs soft link? A hard link points to the same inode (survives deleting the original name); a soft link stores a path and breaks if the target is removed.

5. How do you check disk and memory usage? df -h for disk space, du -sh for folder sizes, free -h for memory, top/htop for live usage.

6. What does grep -r do? What is a pipe? Searches recursively through files; a pipe sends one command's output as another's input.

7. What is a daemon / systemd? A background service; systemd is the init system that starts, stops and supervises services.

8. How do you see which ports are open? ss -tulpn (or netstat -tulpn), and lsof -i :PORT for a specific port.

9. What is cron? A scheduler that runs commands at times defined by five fields (minute hour day month weekday).

10. What is sudo? Runs a command with root privileges for users allowed in the sudoers file, with logging.

14. Cheat Sheet & References

Navigation and files

pwd; ls -la; cd /path; cd ..; cd ~
mkdir -p a/b/c; touch f.txt
cp -r src dst; mv a b; rm -r dir
cat f; less f; head -n 20 f; tail -f log
find . -name "*.js"; grep -rin "text" .

Permissions and users

chmod 755 file; chmod +x script.sh
chown user:group file
sudo command; sudo -i
id; whoami; groups
sudo usermod -aG docker $USER

Processes and system

ps aux | grep node; top; htop
kill PID; kill -9 PID; pkill -f name
free -h; df -h; du -sh *
lsof -i :3000; ss -tulpn
uname -a; uptime; nproc

Packages and services

sudo apt update && sudo apt upgrade
sudo apt install pkg; sudo apt remove pkg
sudo systemctl status|start|stop|restart|enable svc
journalctl -u svc -f
crontab -e; crontab -l

Network and archives

ip a; ping host; curl -I url; wget url
ssh user@host; scp f user@host:/path
rsync -avz dir/ user@host:/path/
tar -czvf a.tar.gz dir; tar -xzvf a.tar.gz

Official documentation