Linux
Short
notes
FOR DEVOPS ENGIN
EERS
TraIn
WTIh
Shubha
Linux Short
Notes
History of LINUX
Linux came from a Unix family, Linux is a free and open-source software
operating system, which Linus Torvalds developed in September 1991.
In 1991, Linus Torvalds was a student at the University of Helsinki, Finland,
USA.
He developed the first code of Linux 0.01 and post it on the minix newsgroup
on 17 Sep 1991, his code become so popular people encouraged him to
develop new code and he was led to develop new code and release the first
“o ffi cial” version of Linux, version 0.02 on October 5, 1991.
Today many year pass and Linux become one of the most popular operating
systems. Today 90% fastest Supercomputers out of 500 run on Linux variants
including the top 10.
Linux File System Hierarchy
In Linux everything is represented as a file including a hardware
program, the files are stored in a directory, and every directory
contains a file with a tree structure. That is called File System
Hierarchy.
Linux uses single rooted, inverted tree-like structure.
Root Directory represents with / (forward slash) It is a top-level
directory in Linux.
TraIn
WITh
/
The base of the Linux directory is the root. This is the starting point of FSH.
Every directory arises from the root directory. It is represented by a forward
slash (/).
If someone says to look into the slash directory, they refer to the root
directory.
/root
It is the home directory for the root user (superuser).
/bin → User Binaries
Contains binary executable.
Common Linux commands you need to use in single-user modes are
located under this directory.
Commands used by all the users of the system are located here.
/sbin → SystemBinaries
Just like /bin, /sbin also contains binary executables.
But, the linux commands located under this directory are used typically
by system aministrator, for system maintenance purpose.
For example: iptables, reboot, fdisk, ifconfig, swapon
/dev → Device Files
it contains hardware device files,
Contains device files.
These include terminal devices, usb, or any device attached to the system.
For example: /dev/tty1, /dev/usbmon0
TraIn
WITh
/ v a r → Variable Files
The variable data files such as log files are located in the /var directory.
File contents that tend to grow are located in this directory.
> This includes
◦
/var/log: System log files generated by OS and other applications.
◦
/var/lib: Contains database and package files.
◦
/var/mail: Contains Emails.
◦
/var/tmp: Contains Temporary files needed for reboot.
/mnt → mount Directory
This directory is used to mount a file system temporarily.
/media → Removable media Devices
The /media directory contains subdirectories where removable media devices
inserted into the computer are mounted.
/ u s r → User Binaries
The /usr directory contains applications and files used by users, as opposed
to applications and files used by the system.
/etc → Configuration files
It contains all configuration files of server
The core configuration files are stored in the /etc directory. It controls the
behavior of an operating system or application. This directory also contains
startup and shutdown program scripts that are used to start or stop individual
programs.
TraIn
WITh
/boot → Boot Loader Files
The /boot directory contains the files needed to boot the system
— for example,
the GRUB boot loader's files and your Linux kernels are stored here.
/opt → Optional Applications
The opt directory is used for installing the application software from third-
party vendors that are not available in the Linux distribution. Usually, the
software code is stored in the opt directory and the binary code is linked to
the bin directory so that all users can run that software.
/home → Home Directory
It contains secondary users home directory.
/tmp → Temporary Files
Directory that contains temporary files created by system and users.
Files under this directory are deleted when system is rebooted.
TraIn
WITh
Basic Commands
#pwd → it shows the present working directory
# l s → it shows available files and directory list in the present working
directory.
#uname → it shows the name of the kernel (OS)
#uname - r → it shows version of the kernel
#cd → it use for change directory
#clear → it use for clear screen
#whoami → it show currently login user name
#history → it show list of previously used commands
#date → it show time and date
Create file or
directory
1. For create single directory
2. For create multiple directory
3. For create directory path (directory inside directory)
4. For create number of directory
TraIn
WITh
Create file
Touch:
Touch command is use for create empty file, we c a n ’ t write data in a file,
c a n ’ t edit or save file.
1. Create single file with touch command
2. Create multilpe file
3.Create number of files
For cop y and paste
CP:
cp :
cp command is used for copy and paste file or directory
Syntax:
#cp <option> <source> <destination>
Options
- r for recursive
- v for verbose
- f for forcefully
TraIn
WITh
1. For copy file
2. For copy all data which start form D alphabet
For remove file & directory
1. For delete file or directory
For move or rename file & directory
1. For move file or directory
2. For rename file or directory
User management
For create user account
TraIn
WITh
For check user account properties
For create user account password
For check user password properties
For switch user account
For switch user account
For logout from user account
Or
For Delete user account
TraIn
WITh
For change user Login name
Group management
A group is a collection of user accounts that is very use full to administrators for
managing and applying permission to a number of users.
For add Group account
For check group account property
For check group admin property
For Delete group Account
For add single member in group
For add multiple member in group
TraIn
WITh
For remove group member
For make group admin
Linux File System Permission
Type of File Permission
Basic permission
Special
permission
Access Control List
(ACL) permission
For check file
permission
permissio
n Link
Owner
Group
owner Size
of file
Date & time of file
creation Name of file
For check directory permission
TraIn
WITh
Permission in details
Type of File Permission
Basic permission
Special
permission
Access Control List
(ACL) permission
Permission Group
Permission Description
Owner (u) → permissions used for the owner of
the file Group (g) → permissions used by
members of the group Other (o) → permissions
used by all other users
Permission Set
Permission with numeric & symbol
TraIn
WITh
For change permission
For add read permission to owner
For add read write permission to group
For remove read permission to others
For change ownership
Syntax:
For change group
ownership
Syntax:
TraIn
WITh
Set permission with a numeric value
r (read) = 4
w (write) =
2
x (execute)
= 1
For set
permission
with a
numeric value
Access Control List (ACL)
Access control list (ACL) provides an additional, more flexible permission
mechanism for file systems.
Access control list is a service which is used for providing special permission
to specific users and group to particular directories and file
Use of ACL
Think of a scenario in which a particular user is not a member of group created
by you but still you want to give some read or write access, how can you do it
without making user a member of group, here comes in picture Access Control
Lists, ACL helps us to do this trick.
For check ACL Permission
Syntax:
TraIn
WITh
For set ACL permission to user
For remove ACL permission of user
For set ACL permission to Group
For remove ACL permission of group
For remove all ACL permissions
Access Control List (ACL)
Regular Expressions
What are Regular Expressions?
Regular expressions are special characters which help search
data, matching complex patterns.
GREP (Global Regular Expression Print)
The grep filter searches a file for a particular pattern of
characters, and displays all lines that contain that pattern.
TraIn
WITh
Search a word (string in a file)
Search a string in multiple files
Search a string insensitive in file
Search a string in all files recursively
Inverting the string match
Displaying the string match total line no
Display the file names that match the string
Display the file names that do not contain the string
Displaying the string match line with number
TraIn
WITh
Display the lines that start with a string
Display the lines that end with a string
Search and redirect output in a new file
Find
The Linux Find Command is one of the most important and
much used command in Linux systems.
Find command used to search and locate the list of files and
directories based on conditions you specify for files that match
the arguments.
Find can be used in a variety of conditions like you can find files
by permissions, users, groups, file type, date, size, and other
possible criteria
Find files under Home directory
Find files with suid permission
TraIn
WITh
Find files with guid permission
Find files with sticky bit permission
Using Find command based on users
Using Find command based on groups
Search the file with less than 10mB in a folder
Search the file with more than 10mB in a folder
WC (Word Count)
The wc command is use for the count word and line numbers.
Count number of lines
Count number of words
TraIn
WITh
head
Head command is used for to display top line of the file.
Display top 10 line of the file
Display top specific no line of the file
tail
Tail command is used for to display the bottom line of the file.
Display bottom 10 line of the file
Display bottom specific line of the file
Archive File in Linux
Archiving is the process of combining multiple files and directories (same or
different sizes) into one file. Archive process is very useful for backup and
compression size of data in Linux.
What is Tar
The Linux “ t a r ” stands for tape archive, which is used by large number of
Linux/Unix system administrators to compress size or drives backup. For create
archive tar used some compression algorithms Such as gzip,bz2 and xz
TraIn
WITh
Tar command syntax
#tar <options> <files>
Commonly used options
c - for create
x - for extract
v - for verbose
f - for forcefully
t - for test
z - for gzip
j - for bz2
J - for xz
C - for
specific
destination
To create
a tar
archive file
To show file size in human-readable format
To extract a tar archive file on the default location
To extract a tar archive file on the specific location
TraIn
WITh
To create a tar archive file with compress in size (gzip)
To extract a tar archive file with compress in size (gzip)
To create a tar archive file with compress in size (bzip2/bz2)
To extract a tar archive file with compress in size (bzip2/bz2)
To create a tar archive file with compress in size (xz)
To extract a tar archive file with compress in size (xz)
Job Automation
Job automation allows us to perform tasks automatically in OS by using tools.
This feature is very useful for the administrator to assign tasks to OS whenever
he is not present or performing daily basis work.
Two type of job automation
1. at—command is used to execute a job only one time.
2. crontab—Crontab command is used to execute a job
multiple times. TraIn
WITh
To a set job with at command
To show pending a job
To remove a job
To restrict user from accessing at
To start crond service
To enable crond service (Permanent on)
For set cron jobs
TraIn
WITh
To show cron jobs of the current user
To remove cron jobs
Or,
Go to the crontab file and remove the job line
To the set cron job to other users
To show cron job, other user
To restrict user from crond service
TraIn
WITh
Sudo Command
What is sudo?
sudo (“superuser do”, or “switch user do”) allows a user with
proper permissions to execute a command as another user, such
as the superuser.
sudo allows a permitted user to execute a command as another
user, according to specifications in the /etc/sudoers file.
Provide sudo privilege to the user
For edit configuration file:
# vim /etc/sudoers
root ALL=(ALL) ALL
amir ALL=(ALL) ALL
(add this line
appro. 101 lines)
:wq
Provide sudo
privilege to the
group
For edit
configuration
file:
# vim
/etc/sudoers
%punegrp
ALL=(ALL) ALL
(line number
108)
:wq
By default, all
members
By default,ofall members of the wheel group got sudo TraIn
punegrp
privilegesgroup WITh
Sudo without password
For edit configuration file:
# vim /etc/sudoers
amir ALL=(ALL) NOpASSWD: ALL
%punegrp ALL=(ALL) NOpASSWD: ALL
:wq
managing networking based
on Red Hat Enterprise Linux
To show ip address
Or,
Configure networking with nmcli
Network manager is a daemon that monitors and manages network settings.
nmcli command used to manage networking
manage IP configuration
For Show all list of connection
TraIn
WITh
manage IP configuration
To Show all list of connection
To show a active connection
To show a specific connection
To show the device status
To create a new connection with nmcli
To show the device status
#nmcli con mod “cit y n et ” ipv4.add 192.168.0.100
#nmcli con mod “cit y n et ” gw4 192.168.0.254
#nmcli con mod “cit y n et ” ipv4.dns 192.168.0.254
#nmcli con down citynet
#nmcli con up citynet
#nmcli con show—active
#nmcli con show citynet
TraIn
WITh
To activate new connection
To deactivate connection
To start a new connection and stop the old connection
To remove existing connection
To remove the existing connection
To set hostname
To show hostname
Configuring networking with nmtui
TraIn
WITh
IP address configuration files
All created connections with nmcli and nmtui by default are stored in the
following file
Note
We can also modify the connection using the above connection file, but it
not recommended.
If update the file, restart Networkmanager service to update I P - configuration
TraIn
WITh
Thank You
Dosto
TraIn
WTIh
Shubha