Ravindra BagaleCourses & study guides मराठी Track your progress

Appendix B: Command Cheat Sheet

Friends, keep this cheat sheet open beside you during labs. Ubuntu and Amazon Linux/CentOS commands are given side by side, so pick the right command for your OS.

B.1 Package and service management

Task Ubuntu Amazon Linux 2023 / CentOS Stream 9
Update package lists / upgrade sudo apt update && sudo apt upgrade -​y sudo yum update -​y
Install sudo apt install -​y <pkg> sudo yum install -​y <pkg>
Remove sudo apt remove <pkg> sudo yum remove <pkg>
Search apt search <word> yum search <word>
Start now + enable at boot sudo service <svc> start + sudo systemctl enable <svc> same
Status / logs sudo service <svc> status, journalctl -​u <svc> -​f same
Apache service apache2 httpd
MySQL service mysql mariadb
Web user www-data nginx / apache
Firewall sudo ufw allow 'Nginx Full' sudo firewall-​cmd --​permanent --​add-​service=​http && sudo firewall-​cmd --​reload

B.2 Files, permissions, users

ls -la            cd /path          pwd              mkdir -p a/b
cp -r src dst     mv old new        rm -r dir        touch file
cat f   less f    head -n 20 f      tail -f f        wc -l f
chmod 755 dir     chmod 644 file    chmod 400 key.pem
sudo chown -R user:group /path
sudo useradd -m -s /bin/bash u      sudo passwd u    sudo usermod -aG wheel u  (Ubuntu: sudo)

B.3 Search and text

grep -rin "text" /path              find / -name "*.conf" 2>/dev/null
awk '{print $1}' file               sed -i 's/old/new/g' file
cmd | sort | uniq -c | sort -rn     cmd > out.txt 2>&1      echo x | sudo tee -a /etc/file

B.4 Networking

ip a            ip r              hostname -I          curl -s https://checkip.amazonaws.com
sudo ss -tlnp   ping -c 4 host    curl -I http://host  dig +short domain
nc -zv host 3306                  traceroute host      sudo hostnamectl set-hostname web01

B.5 Disk and EBS

df -hT          du -sh /path       lsblk -f            sudo blkid
sudo file -s /dev/nvme1n1          sudo mkfs -t xfs /dev/nvme1n1
sudo mkdir /data && sudo mount /dev/nvme1n1 /data     sudo umount /data
sudo growpart /dev/nvme0n1 1       sudo xfs_growfs -d /     sudo resize2fs /dev/nvme0n1p1
sudo mount -a   # test /etc/fstab  (UUID=... /data xfs defaults,nofail 0 2)

B.6 Web servers

sudo nginx -t && sudo service nginx reload
sudo apachectl configtest && sudo service httpd reload          # AL2023 / CentOS
sudo apache2ctl configtest && sudo service apache2 reload       # Ubuntu
sudo a2ensite site.conf ; sudo a2dissite 000-default.conf ; sudo a2enmod rewrite proxy proxy_http
sudo restorecon -Rv /var/www ; sudo setsebool -P httpd_can_network_connect 1   # CentOS SELinux
sudo nginx -T | grep -E "listen|server_name|root"               # what Nginx really loaded
sudo apachectl -S                                               # Apache vhosts + default (Ubuntu: apache2ctl -S)
sudo ln -s /etc/nginx/sites-available/site /etc/nginx/sites-enabled/   # Ubuntu Nginx enable site
sudo semanage fcontext -a -t httpd_sys_content_t "/srv/site(/.*)?" ; sudo restorecon -Rv /srv/site
sudo semanage port -a -t http_port_t -p tcp 8081                # CentOS: allow a new web port
curl -H "Host: site1.example.com" http://localhost              # test a vhost without DNS
Setting Nginx (server { }) Apache (<VirtualHost>)
Port listen 80; <VirtualHost *:​80> + Listen 80
Site name server_​name example.​com www.​example.​com; ServerName example.​com + ServerAlias www.​example.​com
Folder root /​var/​www/​site; DocumentRoot /​var/​www/​site + <Directory>
Index file index index.​html; DirectoryIndex index.​html
No folder listing autoindex off; Options -Indexes
Redirect return 301 https://$host$request_​uri; Redirect permanent / https://​example.​com/
Hide version server_​tokens off; ServerTokens Prod + ServerSignature Off

B.7 DNS and domains

dig example.com +short           dig www.example.com +short       dig NS example.com +short
dig @8.8.8.8 example.com +short  dig MX example.com +short        dig +trace example.com
nslookup example.com             host example.com                 curl -I http://example.com
sudo yum install -y bind-utils   # dig on AL2023/CentOS  (Ubuntu: sudo apt install -y dnsutils)
ipconfig /flushdns               # Windows     resolvectl flush-caches   # Linux laptop
sudo certbot --nginx -d example.com -d www.example.com -d blog.example.com

Typical records: A @ → Elastic IP · CNAME www → @ · A blog → Elastic IP · TTL 300–3600.

B.8 Databases

sudo mysql                                   # admin shell (socket auth)
sudo mysql_secure_installation
mysql -u appuser -p -h 127.0.0.1 appdb
mysqldump -u appuser -p appdb > backup.sql   mysql -u appuser -p appdb < backup.sql
mongosh         # MongoDB shell: show dbs ; use db ; db.col.find()

B.9 App process managers

pm2 start app.js --name api ; pm2 status ; pm2 logs api ; pm2 reload api ; pm2 startup ; pm2 save
sudo systemctl daemon-reload ; sudo service flaskapp start ; sudo systemctl enable flaskapp ; journalctl -u flaskapp -f
gunicorn --workers 3 --bind 127.0.0.1:8000 wsgi:app

B.10 EC2 operations (AWS CLI, optional)

aws ec2 allocate-address --domain vpc
aws ec2 associate-address --instance-id i-xxx --allocation-id eipalloc-xxx --allow-reassociation
aws ec2 release-address --allocation-id eipalloc-xxx
aws ec2 create-image --instance-id i-xxx --name web-v1            # add --no-reboot only if you accept the risk
aws ec2 copy-image --source-region ap-south-1 --source-image-id ami-xxx --region ap-south-2 --name web-v1-dr
aws ec2 deregister-image --image-id ami-xxx ; aws ec2 delete-snapshot --snapshot-id snap-xxx
aws ec2 create-snapshot --volume-id vol-xxx --description "before-upgrade"
aws ec2 modify-instance-attribute --instance-id i-xxx --instance-type "{\"Value\": \"t3.small\"}"   # instance stopped
nproc ; free -h ; lscpu                                            # verify after resizing

B.11 SSH and file transfer

ssh -i key.pem ec2-user@IP                   ssh -i key.pem ubuntu@IP
scp -i key.pem file ec2-user@IP:~/           scp -i key.pem -r dir ubuntu@IP:~/
scp -i key.pem ec2-user@IP:/path/file .      rsync -avz -e "ssh -i key.pem" dir/ ubuntu@IP:~/dir/

Ravindra Bagale's Tip

Don't copy placeholders like <pkg>, <svc>, IP, key.pem or i-xxx from the cheat sheet as they are – put in your own value first. And before running commands like delete or mkfs, check the device or path once.

Practice Tasks

About this scenario

Ahmednagar Sugar Co-op is a sugar co-operative business in Ahilyanagar. Balasaheb Pawar looks after its IT and cloud work. They count money in INR and run their AWS resources in the ap-south-1 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.

0 / 12

Easy List your EC2 instances

Why: Before changing anything, see what is running and in which state.

What to do: Show details of all EC2 instances of Ahmednagar Sugar Co-op in ap-south-1.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy List files in a bucket folder

Why: Check that the upload worked and see file sizes.

What to do: List the objects under s3://nagarsugar-invoices-2026/reports/.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Create a bucket

Why: A bucket is the top-level container for your files in S3.

What to do: Create the bucket nagarsugar-invoices-2026 in ap-south-1.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Read a config file

Why: Reading a file on the screen is the quickest way to check its settings.

What to do: Print the whole file /etc/nagarsugar/app.conf on the screen.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy List all files with details

Why: Hidden files (like .env) and file sizes or owners only show with the right options.

What to do: Show a long listing of every file, including hidden ones, in /var/www/nagarsugar.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Create an empty file

Why: Some apps need a file to exist before they can write to it.

What to do: Create an empty file named orders-inr.csv in the current folder.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy List Availability Zones

Why: Spreading servers across AZs keeps you up if one data centre fails.

What to do: List the Availability Zones in ap-south-1.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy List all Regions

Why: Choose a Region close to your users for low delay and the right laws.

What to do: List the AWS Regions available to your account.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Create nested folders in one go

Why: Projects need a clean folder tree. Making all levels in one command saves time and avoids errors.

What to do: Create the folder /srv/nagarsugar/reports/2026 for Ahmednagar Sugar Co-op. The parent folders do not exist yet, so create them too.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Show where you are

Why: Before you copy or delete anything, you must know which folder you are in.

What to do: Balasaheb Pawar logged in to the Ahmednagar Sugar Co-op server and is not sure which folder the terminal is in. Print the current folder path.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Check who you are logged in as

Why: Always confirm the account and identity before running changes.

What to do: Show the account ID and ARN of the identity your CLI is using.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Create an AMI from a server

Why: An AMI is a full server image. Launch identical copies from it any time.

What to do: Create an AMI named nagarsugar-web-v1 from instance i-05c252ad5d1311a2b.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.