Why Linux?
Nearly every server, container, and CI runner you'll encounter runs Linux. Being fluent on the command line is non-negotiable for a DevOps engineer.
Navigating the Filesystem
pwd # print current directory
ls -la # list files including hidden, with permissions
cd /etc # change directory
cd ~ # go to home directory
cd - # go back to previous directoryWorking with Files
touch app.log # create empty file
mkdir -p src/config # create nested directories
cp file.txt backup.txt # copy
mv old.txt new.txt # move / rename
rm -rf dist/ # remove directory recursively
cat /etc/os-release # print file contents
less large.log # paginate through large filesSearching
grep -r "ERROR" /var/log/ # recursive search in logs
find /home -name "*.sh" # find files by pattern
grep -n "TODO" src/*.js # show line numbersFile Permissions
Every file has three permission groups: owner, group, others.
-rwxr-xr-- 1 ubuntu deploy 1234 Jul 1 09:00 deploy.sh
↑↑↑↑↑↑↑↑↑
│└──┬──┘└──┬──┘└──┬──┘
│ owner group others
└── file type (- = file, d = directory)
chmod +x deploy.sh # add execute permission
chmod 644 config.yml # rw-r--r--
chown ubuntu:deploy app/ # change owner and groupProcesses
ps aux # list all running processes
top # real-time process monitor
htop # improved top (install separately)
kill -9 <PID> # force-kill a process
nohup ./server & # run in background, ignore hangupViewing Logs
tail -f /var/log/syslog # follow log in real time
journalctl -u nginx --since today # systemd journal for a service
dmesg | tail -20 # kernel ring buffertail -f is one of the most-used commands in production debugging. Combine it with grep using a pipe: tail -f app.log | grep ERROR.