DevOps Lesson 2: Linux Basics
90% of servers run Linux. These commands are used every day by every DevOps engineer. Learn them well.
Essential Commands
# Navigation
pwd # current directory
ls -la # list all files (including hidden)
cd /etc/nginx # change directory
cd .. # go up one level
# File operations
cp file.txt backup.txt # copy
mv file.txt /tmp/ # move or rename
rm file.txt # delete
mkdir -p app/src/utils # create nested dirs
cat file.txt # view file
less file.txt # paginated view
tail -f /var/log/app.log # watch log in real time
# Permissions
chmod 755 script.sh # rwxr-xr-x
chown user:group file # change owner
# Process management
ps aux # all running processes
kill 1234 # kill process by PID
top / htop # interactive process viewer
nohup ./app & # run in background
SSH & File Transfer
# Connect to remote server
ssh user@192.168.1.100
ssh -i ~/.ssh/mykey.pem ubuntu@54.123.45.67 # with key
# Copy files to/from server
scp file.txt user@server:/home/user/
scp user@server:/var/log/app.log ./ # download
# Sync directories
rsync -avz ./app/ user@server:/var/www/app/
Essential Tools
grep "ERROR" /var/log/app.log # search in files
grep -r "TODO" ./src/ # recursive search
awk '{print $2}' file.txt # print column 2
sed 's/old/new/g' file.txt # find and replace
curl https://api.example.com/users # HTTP request
wget https://example.com/file.zip # download file
cron / crontab -e # scheduled tasks
🏋️ Practice Task
Complete these Linux exercises: (1) Create a directory tree: project/src/{js,css}, project/dist, project/tests. (2) Find all .log files modified in last 24 hours. (3) Count lines in a file. (4) Search for “error” (case-insensitive) in all .txt files. (5) Create a cron job that logs the date every minute.
💡 Hint: find . -name “*.log” -mtime -1. grep -i “error” **/*.txt. wc -l file.txt. crontab -e then: * * * * * date >> /tmp/dates.log