Linux
Linux
Why Linux?
• Open source
• Community support
• Heavily customizable
• Most servers run on Linux
• Most of the DevOps tools implements on Linux only
• Automation
• Secure
Architecture of Linux
Different Linux Distros
Popular Desktop Linux OS
• Ubuntu Linux
• Linux Mint
• Arch Linux
• Fedora
• Debian
• openSUSE
What is a path?
A path is a unique location to a file or a folder in a file system of an
OS. A path to a file is a combination of / and alpha-numeric
characters.
/home/imran/linux-practices/
/var/ftp/pub
/etc/samba.smb.conf
/boot/grub/grub.conf
If you see, all these paths started from / directory which is a root
directory for every Linux/Unix machines.
When you open the vim editor, it will be in the command mode
by default.
It has 3 modes:
• Command mode
• Insert mode (Edit mode)
• Extended Mode: (Colon mode): Extended Mode is used for
save and quit or save without quit using "Esc" Key with":".
Symbolic links
Symbolic links are like desktop shortcuts we use in windows.
• less: Displays file content page wise or line wise. Ex: less /etc/passwd
• more
• head
• tail
tail -f {file-name} can be used to see dynamic content from the file i.e.
recently made changes in a file. To quit from this use CTRL + Z if using
newer versions of Git Bash or use CTRL + C to use older versions of Git
Bash. Use tail -f var/log/ directory structure in root folder of the root
user to see use of this command.
• cut
• sed
The /g makes the changes global. If we do not use /g & a line has more
than one instance of the word to be changed than it will only change the
word at the first instance & move to the next line.
To change the original file use option -i. For eg: sed -i ‘s/Tech/Techologies/g’
ktfile will make changes in the original file.
Similar search & replace can be done using the VIM editor but in that
case we can only change a single file.
To search & replace using VIM we need to enter the extended command
mode using esc key & then use the following command.
For eg - :%s/Tech/Techologies
To make the changes global. Use the following
command. For eg - :%s/Tech/Techologies/g
• find
I/O Redirection Commands
Piping
So, far we've dealt with sending data to and from files. Now we'll
take a look at a mechanism for sending data from one program to
another. It's called piping and the operator we use is (|). What this
operator does is feed the output from the program on the left as
input to the program on the right.
Users & Groups
Users
Types of users
COMMANDS DESCRIPTION
useradd Creates user in RedHat
adduser Creates user in Ubuntu
id Shows user info
groupadd Creates group
usermod -G grpnam {user-name} Adds user to group
passwd Set/Reset password
userdel -r Removes user with home directory
groupdel Removes group
last Shows last login in the system
who Who is logged into the system
whoami Username
lsof -u {user-name} List of files opened by the user
File Permissions
Changing Permissions - Symbolic Method
• mode includes:
u, g or o for user, group and other
o +, - or = for grant, deny or set
r, w or x for read, write or execute
• Options include:
-R Recursive
-v Verbose
--reference Reference another file for its mode
Examples:
chmod ugo+r file: Grant read access to all for file
chmod o-wx dir: Deny write and execute to others for di
Changing Permissions - Numeric Method
Example:
chmod 640 myfile
Sudo
To install telnet
curl
https://rpmfind.net/linux/centos/7.9.2009/os/x86_64/Packages/htt
pd- 2.4.6-95.el7.centos.x86_64.rpm -o httpd- 2.4.6-
95.el7.centos.x86_64.rpm
To install httpd
curl
https://rpmfind.net/linux/centos/7.9.2009/os/x86_64/Packages/http
d- 2.4.6-95.el7.centos.x86_64.rpm -o httpd- 2.4.6-
95.el7.centos.x86_64.rpm
dpkg -i tree_1.6.0-1_amd64.deb
Like YUM for CentOS we have a package manager named apt for Ubuntu.
• sources.list: sources.list file is a key factor in adding or
upgrading applications to on your Ubuntu VM. The file is
basically the roadmap for your system to know where it may
download programs for installation or upgrade.
• apt help: Shows the usage of apt command with options
CentOS Commands
dnf Commands: https://www.linuxtechi.com/dnf-command-
examples- rpm- management-fedora-linux/
• dnf --help: Show the help
• dnf search {package-name}: Search from available repositories
• dnf install {package-name} -y: To install the package
Example: dnfinstall httpd -y
• dnf install vim -y: To install VIM editor
• dnf reinstall {package-name}: To reinstall package
• dnf remove {package-name}: To remove package
• dnf update: To update all packages
• dnf update {package-name}: To update package
• dnf grouplist: List all available group packages
• dnf groupinstall {group-name}: Installs all the packages in a group
• dnf repolist: List enabled dnf repositories
• dnf clean all: Clean dnf cache
• dnf install epel- release: Additional package repository that
provides easy access to install packages for commonly used
software.
• dnf history: View history of dnf
• dnf info {package-name}: Shows the information of
package like version, size, source, repository etc
YUM Commands:
https://access.redhat.com/sites/default/files/attachments/rh_yu
m_cheatsheet_1214_jcs_print-1.pdf
• yum --help: Show the help
• yum search {package-name}: Search from available repositories
• yum install {package-name} -y: To install the package
Example: dnfinstall httpd -y
• yum install vim -y: To install VIM editor
• yum reinstall {package-name}: To reinstall package
• yum remove {package-name}: To remove package
• yum update: To update all packages
• yum update {package-name}: To update package
• yum grouplist: List all available group packages
• yum groupinstall {group-name}: Installs all the packages in a group
• yum repolist: List enabled dnf repositories
• yum clean all: Clean dnf cache
• yum install epel- release: Additional package
repository that provides easy access to install
packages for commonly used software.
• yum history: View history of dnf
• yum info {package-name}: Shows the information of
package like version, size, source, repository etc
Ubuntu
Commands
apt
Commands
• apt search {package-name}: Search from available repositories
• apt install {package-name} -y: To install package
Example: apt install apache2 -y
• apt reinstall {package-name}: To reinstall package
• apt remove {package-name}: To remove package
• apt update: To update all packages
• apt update {package-name}: To update package
• apt grouplist: List all available group packages
• apt groupinstall {group-name}: Installs all the packages in a group
• apt repolist: List enabled apt repositories
• apt clean all: Clean apt cache
• apt history: View history of apt
• apt show {package-name}: Shows the information of
package like version, size, source, repository etc
Services
CentOS
Commands Description
sudo systemctl start {service-name} Starts the service
sudo systemctl stop {service-name} Stops the service
sudo systemctl restart {service-name} Restart the service
sudo systemctl status {service-name} Shows the current status
sudo systemctl reload {service-name} Reload the service
sudo systemctl enable {service-name} Starts the service at boot time
sudo systemctl disable {service-name} Stops the service at boot time
sudo systemctl is-active {service-name} Shows whether the service is active
or not
sudo systemctl is-enabled {service-name} Shows whether the service is
enabled or not
Ubuntu
Commands Description
sudo systemctl start {service-name} Starts the service
Archiving/ Compression
Search
File Transfer
Login (SSH & TELNET)
Disk Usage
System
Hardware
Statistics