Linux Training
Table of Contents
Architecture...........................................................................................................................................2
Setup in AWS........................................................................................................................................ 2
Command.............................................................................................................................................. 8
Installation........................................................................................................................................ 9
Shell Scripting..................................................................................................................................... 10
Commands...........................................................................................................................................13
SSH & SCP......................................................................................................................................... 13
If Else Condition................................................................................................................................. 16
Loops...................................................................................................................................................18
Functions............................................................................................................................................. 19
How to take a Backup Of Folder.........................................................................................................19
Disk Check → Trigger Alert............................................................................................................... 20
While Loop..........................................................................................................................................22
Alert Script on Disk Usage..................................................................................................................22
CronJob Crontab..................................................................................................................................22
.............................................................................................................................................................23
Architecture
Setup in AWS
Command
Tips: Do not use spaces in folderNames. Use either Caps before each word or underscore
• Create Directory → mkdir LinuxForDevops
• Create File in directory → touch filename
• Edit file → vim filename
• write in file → press I to activate insert mode then write anything
• press Esc then write :wq to write&quit from filename
• To view file content → cat filename
• Create multiple file using touch → touch file{1..5}.txt
• This will create file1.txt file2.text file3.txt file4.text file5.txt
• How to delete/remove any file starting with file name → rm file* ( files starting with file name
file )
• Copy all content from folder1 to folder2 → cp folder1/* folder2/
• How to rename/move a folder or file name → mv oldfoldername newfoldername
• How to check if internet is working in system → ping -c <number> 8.8.8.8
• ex: ping -c 2 8.8.8.8
• Here 2 can be number of packets to be transferred. It can be any value.
How to download any file from internet →wget <hyperlink>
WGET vs CURL
WGET can have option of read or download
CURL can implement HTTPS methods like GET , POST, DELETE. (Read, write, update & Delete)
Update: sudo apt update ;
sudo apt update - -upgrade
To see upgradable components: apt list --upgradable
Switch to root user → sudo su
Come out of super user → exit
Installation
Docker installation commands : https://www.digitalocean.com/community/tutorials/how-to-install-and-
use-docker-on-ubuntu-20-04
How to check status of any service (application) in linux → service <appname> status
How to stop any active service in Linux → service <appname> stop
Shell Scripting
Shell files end with extension .sh
Execute shell file with bash → bash <filename>
OR execute like → ./<filename>
How to give permission to user → chmod XXX (XXX → represent owner, group & other)
CHMOD → Change Modify
To print → echo “statement”
create script for below set of commands:
1. mkdir testfolder
2. cd testfolder
3. touch testfile.txt
4. echo “insert with redirection” > testfile.txt
How to check disk space ? command → df – h
Now print only first column only.
| → pipe will pass df -h output to
awk → initiate filtering, everything should be under ‘{}’
$1 → first column
Now print first
3 columns
from above
result set
df -h |
awk
'{print $1 " " $2 " " $3} NR==3{exit}' → will limit top 3 records only
Commands
https://www.notion.so/Linux-For-DevOps-Masterclass-2556811c239142cf99c4cec6548df01a
SSH & SCP
it stands for Secure Shell, a protocol typically used for connecting to Linux servers. The command-line
SSH tool lets you log into your server and run commands remotely to perform any required task.
Check if SSH is already installed on windows machine . Open CMD → type SSH and press Enter
If above message is not displayed then install it separately.
Enable SSH on window machine : https://winbuzzer.com/2021/08/25/how-to-enable-and-use-ssh-
commands-on-windows-10-xcxwbt/
Paste below shown command and this will connect local windows machine to your AWS instance
machine. Make sure pem key file exist in the same location
ssh -i "linux-for-devops.pem" [email protected]
What is Processing triggers for man-db line means after any installation ?
This mean manual db is created. If you want to know any information about that software then simply
type command man <software name>
eg: man ssh or man docker
How to copy file from local to remote machine ?
1. navigate to folder where pem key file is located
2. In local terminal, type below command-line
sudo scp -i <pemkeyfilename> <filename> <remotemachineaddress>:path
filename → if file is in same directory then directly provide file name otherwise entire path
path: → remote system path in which file needs to be copied (use pwd for entiere path)
How to copy file from remote server to local machine?
SCP → secure copy
``x
If Else Condition
Note: Space after if
Output:
Multiple If → elIf
Q. Find biggest in 3
Loops
Functions
How to take a Backup Of Folder
here backup file is the name of the zip
that is going to be created.
To unzip use tar xf filename
Disk Check → Trigger Alert
Disk file df -H
filter above output: AWK command
Disk usage script file
While Loop
Alert Script on Disk Usage
CronJob Crontab
How to schedule any file execution
bash /home/ubuntu/scripts/diskWarning.sh
crontab -e will open crontab file under which we can schedule execution of any shell file
CURL Commands
This command display data from internet.
WGET <link> → will download filename
cat filename.txt | grep ERROR
CURL → will show output and you can club grep in a single command
Curl <link> | grep ERROR