Linux - bdbenu/Notes GitHub Wiki
-
Application deployment will happen on linux machines only
-
Tools will be installed on Linux machines only
Ex: Docker, K8S, Jenkins, Nexus, SonarQube, ELK etc...
-
Application log files will be stored in linux machine only
=> It is a software which acts as mediator between user and computer
=> Users will communicate with computers using OS
=> Without OS we can't use any computer
=> OS provides platform to run our applications in computer
Ex: notepad, calculator, browser, tomcat, eclipse...
=> We have several operating systems in market
Ex: Windows, Linux, Mac, Android, IOS etc...
=> Developed by Microsoft company (Bill Gates)
=> It is commercial OS (licensed)
=> It is single user based OS
=> Security features are very less in Windows
Note: We need to install anti-virus software to protect files
=> Windows is GUI based OS
=> Windows is recommened for personal use only
Ex: internet browsing, games, watch movies, attend online classes....
=> Linux community based OS
=> Linux is free & open source os
=> Linux is CLI based OS
=> Linux is multi user based OS
=> Security Features are very high in linux
Note: Anti-virus s/w is not required
=> Linux OS developed by "Linus Torvalds"
=> Linux is highly recommended to manage servers
Ex: App Severs, DB servers, Docker, Jenkis, K8S etc..
-> Linus Torvalds identified some challenges/issues in Unix OS
-> Linus Torvalds identified one OS which is matching with his ideas
i.e Minux os
-> Linus Torvalds used Minux OS code and made some changes and released into market was new OS
(Li) nus + Mi (nux) ===> Linux
-> Linus Torvalds provided Linux OS code for free of cost
-> So many companies downloaded Linux OS source code and modified according to their requirement and released into market with their brand names those are called as Linux Distributions/ Linux Flavours.
-> We have 200+ Linux Distributions in the market.
Ex: Amazon Linux, Ubuntu, CentOS, RedHat, Debian, SUSE, Kali, Fedora....
Approach-1) Install Linux OS directley in computer
Approach-2) We can use Virtual Box and install Linux OS as Guest OS in Windows
Approach-3) Setup Linux VM in AWS Cloud (Recommended)
Step-1 : Login into AWS cloud account
Step-2 : Create EC2 Instance (Linux VM) (Amazon Linux)
instance type : t2.micro (free tier eligible)
Step-3 : Connect with Ec2 instance using SSH Client
( git bash/ mobaxterm / putty)
Step-4 : Practice Linux commands
👉 AWS account setup : https://www.youtube.com/watch?v=xi-JDeceLeI
👉 Linux Machine with Git Bash : https://www.youtube.com/watch?v=JMlQaTXvw5o
👉 Linux Machine with MobaXterm : https://youtu.be/uI2iDk8iTps?si=ZuZs0lQTxoRpbRMk
👉 Linux Machine with putty : https://youtu.be/GXc_bxmP0AA?si=HgSydrP89mPxv23s
=> Linux is CLI based OS
=> We will perform operations in linux vm using linux commands
whoami pwd date cal cal 2025
mkdir : Make directory
mkdir ashokit
mkdir java python aws devops
rmdir : Remove empty directory
rmdir devops
ls : list the files of present working directory
ls -l : Display in alphabetical order
ls -lr : Display in reverse of alphabetical order
ls -lt : Display files based on timestamp (latest on top)
ls -ltr : Display old files on top & latest at bottom
ls -la : display hidden files (.a)
cd : change directory (navigation)
cd <dir-name> : go inside the directory
cd .. : come out from directory
touch : To create empty files
touch f1.txt
touch f2.txt f3.txt f4.txt
cat : create file with data + append data to file + print file data
cat > f1.txt : Create new file with data
cat >> f1.txt : Append data to the exiting file data
cat f1.txt : Print file data from top to bottom
cat -n f1.txt : print file data along with line numbers
rm : Remove files
rm f1.txt : Remove the file
rm -rf devops : remove non-empty directory
cp : copy the data from one file to another file
cp f1.txt f2.txt
Note: To copy the data from multiple files we need to use cat command like below
cat f1.txt f2.txt > f3.txt
mv : rename file/directory + move the file/directory
mv linux.txt linux-os.txt
mv git.txt devops/
=======================================================================
tac : Read file data from bottom to top (opposite of cat cmd)
tac f1.txt
wc : word count
wc f1.txt
rev : reverse the file data and print it
rev f1.txt
========================================
head : To display file data from top (default 10 lines)
head app.log
head -n 20 app.log
head -n 25 app.log
tail : To display file data from bottom (default 10 lines)
tail app.log
tail -n 20 app.log
tail -n 100 app.log
grep : grep stands for global regular expression print
Note : We will use this grep command for keyword search in file
grep 'exception' app.log (print lines which contains given keyword)
grep -i 'exception' app.log (ignore case sensitive)
grep -n 'java' app.log (print lines along with line num)
grep -v 'apache' app.log (print lines which don't have apache keyword)
=> vi (visual editor) it is default editor in linux machines
=> using 'vi' we can create new files and we can edit existing files also
$ vi f1.txt
=> vi command is having 3 modes
a) command mode (just to open the file)
b) insert mode (to edit the file) ---> press 'i' in keyboard
c) esc mode (to comeout from insert mode) --> press 'esc' in keyboard
## Save changes & close the file => :wq or :wq!
## Without saving changes close the file => :q!
Note: vi command will open the file if it is already avilable otherwise it will create new file and it will open that file.
touch : Create empty file
cat : Create file with data
cp : copy one file data into another file
vi : create and open file for editing
cat : print file data from top to bottom
tac : print file data from bottom to top
rev : print each line in reverse order
head : print top 10 lines of file
tail : print last 10 lines of file
vi : open file
=> SED stands for stream editor
=> It is used to process file data
=> Using SED command we can perform operations on the file without opening the file.
sed 's/linux/unix/' linux-os.txt
sed 's/linux/unix/2' linux-os.txt
sed 's/linux/unix/g' linux-os.txt
sed -i 's/linux/unix/g' linux-os.txt
sed -i '2d' linux-os.txt
sed -i '4d' linux-os.txt
sed -i '$d' linux-os.txt
sed -i 'n,$d' linux-os.txt
sed -i '2,10d' linux-os.txt
$ sed -n '3,6p' linux-os.txt
$ sed '4i\i am from ashokit' linux-os.txt
$ sed '$a\i love linux' linux-os.txt
=> Linux is a multi user based OS
=> Multiple users can acces single linux machine and can perform multi tasking
Note: "ec2-user" is default user in amazon linux vm
Note: ec-user having sudo priviliges
Note: For every user we can create new account to access linux vm.
sudo useradd
sudo passwd
cat /etc/passwd
$ sudo su
$ cd ~
$ sudo userdel
$ sudo userdel --remove
$ sudo usermod -l
=> It is very important configuration file in linux machine.
=> Using this file we can control which user can run command as a superuser.
$ sudo cat /etc/sudeors
Note: We should be very careful while working with sudoers file. If we do any mistakes in sudoers file then system will be crashed.
########## Giving sudo previliges for user #######
$ sudo visudo
ALL=(ALL:ALL) ALL
=> After making changes to close sudoers file => ( CTRL + X + Y + Enter)
======================================================== How to enable password based authentication in linux ?
=> in sshd_config file , by default PassswordBasedAuthentication is no.
=> To enable password based authentication we need to set the value as yes.
$ sudo cat /etc/ssh/sshd_config
$ sudo vi /etc/ssh/sshd_config
Public IP : 43.204.143.144 username : loguser pwd: log@123
$ ssh uname@public-ip
Note: To connect with linux vm using username and password then passwordbasedauthentication must be enabled in that linux vm.
=> When we create user in linux, for every user one user group also will be created with the given username.
$ cat /etc/group
$ sudo groupadd
$ sudo usermod -aG
$ sudo gpasswd -d
=======================================
-
File permissions & ownership chomod & chown
-
Networking commands
-
Package Managers (s/w installation)
-
Linux Architecture
ec2-user => /home/ec2-user ==> f1.txt
raju => /home/raju ==> f1.txt
rani => /home/rani ==> f2.txt
ashok => /home/ashok ==> f3.txt
=> We can create several user accounts in single linux vm
=> Multiple users can connect to single linux vm at a time.
Note: One user can modify the file created by other user in linux vm.
=> To avoid this problem we will use file permissions in linux
=> In Linux, file permissions are divided into 3 types
r => read
w => write
x => execute
=> A file/directory contains 3 sections of permissions
user (owner) => u
group => g
others => o
=> We can see below permissions for a file & directory
rwxrwxrwx f1.txt
user having read + write + execute
group having read + write + execute
others having read + write + execute
rw-r--r-- f2.txt
user having read & write (no execute permission)
group having only read
others having only read
rwxr-xr-x java
user having read + write + execute
group having read + execute
others having read + execute
r-xr----x sbms
user having read + execute
group having only read
others having only execute
=> To change file permissions we will use 'chmod' command
$ chmod u+x f1.txt
$ chmod g+w f1.txt
$ chmod o-x f1.txt
$ chmod o-rwx f1.txt
$ chmod g+rwx f1.txt
0 => No Permission 1 => Execute 2 => Write 3 => (2+1) => Write + Execute 4 => Read 5 => (4+1) => Read + Execute 6 => (4+2) => Read + Write 7 => (4+2+1) => Read + Write + Execute
$ chmod 765 f1.txt
- user having all permissions
- group having read + write
- others having read + execute
$ chmod 456 f1.txt
- user having only read
- group having read + execute
- others having read + write
=> To change file/directory ownership we will use 'chown' command
sudo chown new-owner file/directory
sudo chown :new-group file/directory
sudo chown new-owner:new-group file/directory
chmod => To change file/directory permissions
chown => To change owner/group
ping : To check connectivity
$ ping www.google.com
$ ping www.google.com
$ ping 192.168.1.20
wget : It is used to download the files from internet
$ wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.91/bin/apache-tomcat-9.0.91.zip
curl : To send http request to server (api call)
$ curl https://type.fit/api/quotes
ifconfig: To get IP address of our machine
$ ifconfig
=======================================
whoami pwd date cal cal 2050 mkdir rmdir touch ls -ltr cat cp rm -rf mv tac head tail grep vi sed
useradd userdel usermod groupadd groupdel id
chmod chown
ping wget curl ifconfig
=> Package Managers are used to install softwares in linux machines
=> Package Managers are specific to linux distribution
Amazon Linux + Red HAT : yum
Ubuntu Linux + Debian : apt
#install git client s/w sudo yum install git -y
sudo yum install java
sudo yum install maven
=> Webserver is a software which is used to run websites
=> Websites are divided into 2 types
1) static website (fixed content)
ex : wikipedia
2) dyanmic website (content will change based on user)
ex: gmail, facebook
=> For static websites execution we can use 'httpd' as webserver
=> For dynamic websites execution we can use 'tomcat' as webserver
sudo yum install httpd -y
sudo service httpd start
Note: httpd webserver runs on http protocol which is 80.
To access our webserver we need to enable 80 port number in EC2 VM security group inbound rules (firewell setting)
=> Access our webserver using EC2 VM public ip address in our browser.
cd /var/www/html
sudo vi index.html
=> systemctl is a command-line utility in Linux systems which is used to manage system services
=> Starting service => stopping service => restarting service => reloading service => enabling / disabling services
#check service status sudo systemctl status <service_name>
#start service sudo systemctl start <service_name>
#stop service sudo systemctl stop <service_name>
#re-start service sudo systemctl restart <service_name>
$ sudo hostname
$ exit
Note: Connect back to linux vm using ssh command.
To know the location of the package we have installed
whereis java
whereis maven
whereis git
=> find command is used to search files location
sudo find /home -name oops.txt
sudo find /home -type f -empty
sudo find /home -type d -empty
sudo find /home -mtime 30 -print
Deploy Spring Boot Application in Linux VM : https://www.youtube.com/watch?v=cRQPgbwOWq0
-
Why Linux for Java developers ?
-
What is OS & why ?
-
Windows Vs Linux
-
Linux History
-
Linux Distributions
-
Linux VM Setup
-
Linux commands
-
Working with directories & files
-
Working with editors (vi & sed)
-
Users & groups Management
-
sudoers file & sshd_config file
-
PasswordBasedAuthentication enable
-
File Permissions & Owership
-
Package Managers
-
Services management (systemctl)