Linux Introduction
Linux Introduction
Linux Introduction
Why Linux?
• OpenSource.
• Community support.
• Heavily customizable.
• Most Servers runs on Linux.
• DevOps most of the tools implements on Linux only.
• Automation
• Secure.
Architecture of Linux
Diffrent Linux distros
➔ Popular Desktop Linux OS
• • Ubuntu Linux
• • Linux Mint
• • Arch Linux
Fedora
Debian
OpenSuse
Centos
SUSE Enterprise Linux
Most used Linux distros currently in IT industry.
RPM based:- RHEL & Centos
Package name:google-chrome-stable_current_amd64.deb
NOTE: You will also encounter diffrent commands, packages and service names while using
both kinds of distros.
2. Basic Commands
➔ Open Terminal
➔ Create some more directories and list them with “ls” command.
➔ Create some empty files with “touch” command and list them.
➔ Reconfirm your location in your system.
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
root directory(/). In other words we can say absolute path is a complete path from
/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.
=> Enter.
➔ Read file with cat command.
VIM EDITOR
This is command mode editor for files. Other editors in Linux are emacs, gedit
vi editor is most popular
It has 3 modes:
1 Command Mode
2 Insert mode (edit mode)
3 extended command mode
Note: When you open the vim editor, it will be in the command mode by default.
Command Mode:
I •. :::., - --
Extended Mode: ( Colon Mode)
Extended Mode is used for save and quit or save without quit using "Esc" Key with":"
Esc+:20(n) To go to line no 20 or n
Is command options
Types of files in linux.
Symbolic links
Symbolic links are like desktop shortcuts we use in windows.
Create a soft link for /var/log directory in our current working directory.
4. Filter & IO redirection command.
Grep
➔ Linux is case sensetive, Root is diffrent that root. Ignoring case in grep with -i option.
• head
• tail
• cut
• sed
I/O redirection
➔ Search for text “tech” replace it with “tools” and redirect output to a new file.
Find
5. Users & Groups.
USERS
Types of user
Group file
2. /etc/group
The file /etc/group stores group information. Each line in this file stores one group entry.
1. Username
2. Encrypted password
3. Number of days when password was last changed
4. Number of days before password can be changed
5. Number of days after password must be changed
6. Number of days before password expiry date to display the warning message
7. Number of days to disable the account after the password expiry
8. Number of days since the account is disabled
9. Reserved field
passwd username
groupdel
last
who
whoami
lsof -u user
6. File permissions
Changing Permissions - Symbolic Method
• To change access modes:
o chmod [-OPTION] ... mode[,mode] filel directory ...
• mode includes:
o u,g or o for user, group and other
o + - or =for grant, deny or set
o r , w or x for read, write and execute
• Options include:
o - R Recursive
o -v Verbose
o --reference Reference another file for its mode
• Examples:
o chmod ugo+r file: Grant read access to all for file
o chmod o-wx dir: Deny write and execute to others for dir
Changing Permissions - Numeric Method
• Uses a three-digit mode number
o first digit specifies owner 's permissions
o second digit specifies group permissions
o third digit represents others' permissions
• Permissions are calculated by adding:
o 4 (for read)
o 2 (for write)
o 1 (for execute)
• Example:
o chmod 640 myfile
7. Sudo
sudo gives power to a normal user to execute commands which is owned by root user.
Example shown below:
If a user has already full sudoers privilege, it can become a root user anytime.
Note: User imran was already a sudo user with full privilege.
➔ Adding user sam in sudoers list.
For CentOS
To install Tree
# curl https://rpmfind.net/linux/centos/7.9.2009/os/x86_64/Packages/tree-1.6.0-10.el7.x86_64.rpm -o tree-1.6.
10.el7.x86_64.rpm
# rpm -ivh tree-1.6.0-10.el7.x86_64.rpm
To install httpd
# curl https://rpmfind.net/linux/centos/7.9.2009/os/x86_64/Packages/httpd-2.4.6-95.el7.centos.x86_64.rpm -o
2.4.6-95.el7.centos.x86_64.rpm
Due to Dependencies its failing and it will be installed one we install all the dependencies. But what if we h
Hundreds of dependencies, And that can be solved easily by other package managers like YUM .
repos. d/ directory. It reads each YUM Repository configuration file to get the information required to
download and install new software, resolves software dependencies and installs the required RPM pack
files. YUM Repository configuration files must: be located in /etc/yum.repos.d
# ls /etc/yum.repos.d/
# yum update
To install httpd
# yum install httpd -y
To remove httpd
For Ubuntu
# wget http://archive.ubuntu.com/ubuntu/pool/universe/t/tree/tree_1.7.0-3_amd64.deb -o tree_1.7.0-
3_amd64.deb
# dpkg -i tree_1.7.0-3_amd64.deb
We have seen YUM Like that for Ubuntu we have a package manager ‘apt’.
The sources. list file is a key factor in adding or upgrading applications to your Ubuntu installation. This is
also used by your system for system updates. The file is basically the roadmap for your system to know wh
it may download programs for installation or upgrade.
# cat /etc/apt/sources.list
To install apache2
# apt install apache2 -y
To remove apache2
# apt remove apache2 -y
Commands Description
wget link to download file from
link
access file from link
curl link
access file and store
curl link -o o/p to a file
outputfile
dependencies
CentOS_8 Commands
https://www.linuxtechi
DNF
.com/dnf-command-
commands examples-rpm-
cheatsheet management-fedora-
linux/
Additional package
repository that
dnf install epel- provides easy access
to install packages
release for commonly used
software.
dnf history View History of dnf
https://access.redhat.
com/sites/default/file
YUM Commands s/attachments/rh_yum_c
Cheatsheet heatsheet_1214_jcs_pri
nt-1.pdf
To install httpd
yum install httpd -y
package
Ubuntu20 Commands
https://itsfoss.com/ap
apt
t-command-guide/
commands
cheatsheet
14. SERVICES
Centos8
$ sudo systemctl start httpd # Starts httpd on centos
active or not
enabled or not
Ubuntu20
$ sudo systemctl start apache2 # Starts apache2 on ubuntu
active or not
18. HARDWARE
19. STATISTICS