0% found this document useful (0 votes)
20 views11 pages

LINUX Command

The document provides an extensive overview of basic Linux commands, including system commands, file management, user and group management, permissions, and job scheduling. It also covers package management tools for different Linux distributions, log management practices, and archiving and compression techniques. Additionally, it outlines special permissions and access control lists (ACLs) for enhanced security and management of files and directories.

Uploaded by

Tanmay Gaikwad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views11 pages

LINUX Command

The document provides an extensive overview of basic Linux commands, including system commands, file management, user and group management, permissions, and job scheduling. It also covers package management tools for different Linux distributions, log management practices, and archiving and compression techniques. Additionally, it outlines special permissions and access control lists (ACLs) for enhanced security and management of files and directories.

Uploaded by

Tanmay Gaikwad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 11

Basic commands of linux

tty - -- show the current terminal number


uname -a -- Show the os related or kernal unfo
cal -- Shows the calendr
hostaname -- Display the hostname or machine name
cal -j -- Shows the julian data ( 1-365 )
date & time -- Show the current date and time
cat -- Use to check content in file
shutdown -h(10) , -c -- It will shutdown our System in 10min (-
c cancel shutdown )
whoami -- Show user name
who am i -- Shows user details
who -- user's login details

Helping commands

man < command > -- Shows the manual page of command

info < command > -- It is an alternative of man command


which < command > -- Shows the location of given command
what is < command > -- One line description of command
<command > --help -- shows more use case of command

System realated command

lscpu -- List the processor info


dmidecode -- Shows hardware related information
hostname -a -- machine
lsusb -- shows external usb divices

Monitoring command

free -h -- shows the the size of memory (-h human


readable format)
more -- it navigate page in downward direction
line by line
top -- shows the current real time monitoring
ps -- show running process
tail -- It shows bottom lines of file
head -- It shows top lines of file

-----------------------------------------------------------------------------------
---------

19 DIR in linux

dev -- Info about device


etc -- configuration file
var -- Its Stores variable
opt -- In linux we call it as optional dir
proc -- Processor related info
usr -- user related data
tmp -- In this data we can store our
temporary files
home -- prfile info about users
bin -- Binary and excutables files
root -- Home dir of root user
boot -- booting files
lib -- Libares files info
lib64 -- same as lib but it also stores 64 arch
files too
mnt -- mounting files and it stores temporary
files
media -- Its an most freely dir where we can do
our tasks
run -- Running services that are currentlu
running on our device
srv -- Running service information and data
sys -- System related information
sbin -- binary executables files of system

-----------------------------------------------------------------------------------
-----------------------

Working with Files and Dir

Creation of file

1- Creating 10 files at a single command


-- touch omkar{1..10}.txt

2- Creation of DIR
-- mkdir <Dir_name>

creating multiple dir's


-- mkdir /media/dir1 /opt/dir2 dir3

--------------------------------------------------------

Redirectors

Two types of redirectors


1- Single ( Its override the data )
2- Double ( In this the data will append )

---------------------------------------------------------------
-------- HARD LINK AND SOFT LINK --------------------------

*Default link count of directory is 2 whereas default link count of file is 1.

HARD LINK --- 1. hard link works only with file


2. Size of hard link and the original file will be same
3. Inode number of hardlink same as original file
4. We can create hardlink using "ln < origional file-name > <hardlink
name >"
5. Creating hardlink of directory is not possible.

SOFT LINK --- 1. Soft link work with both files and dir
Editors in linux

* Mostly There are two types of Editors


1 - Graphical ---- [ gedit , kedit ]
2 - Command line --- [ nano , pico , vi & vim ]

* Vi & Vim This editord include 4 types of mode namely..


1 - Command mode ( Default mode )
2 - insert mode
3 - Exe mode
4 - visual mode

--------------------------------------------------------------------------------

User and Group Managment

* Types Of Users
1 - Loacl (Standard User ) [ UID - 1000-60,000+] [ Shell - /bin/bash ]
2 - system [ UID - 1-999 ] [ shell - /sbib/nologin ]
3 - root (Super User) [ UID - 0 ] [ shell - /bin/bash ]

* If root user created a user bydefault which files are created

1 - /etc/Passwd --( Profile related information )


2 - /etc/shadow --( User password info )
3 - /etc/gshadow --( Group password )
4 - /etc/group --( Grp info )
5 - Skeleton --( its stores logout,profile,bashrc)
6 - Home Dir
7 - login Shell

* How to create user and set password

1 - userdd user1
2 - passwd user1
3 - groupadd Group-1

* Now , I want to add user1 in group-1 -- usermod(gpasswd) -g user1 group-1


* Assigin user1 as a group-1 admin -- usermod -A user1 group-1
* i want to rename the user1 to omi1 -- usermod -l user1 omi1
* i want to delete user1 -- userdel -r omi

* Tell me the fields of passwd files

1 - username
2 - encrypted
3 - user - id
4 - group - id
5 - comment
6 - home dir
7 - shell/mail/logs

* Tell me the fiels of shadow files

1 - username
2 - encrypted password
3 - last pass change
4 - Min pass age (m)
5 - Max pass age (M)
6 - warning peroid (w)
7 - inactive (I)
8 - Expiary date (E)
9 - unused ( for feature )

-----------------------------------------------------------------------------------
-------------------------

----PERMISSION------

* Types of File in linux


------users files----------

1 - Normal file (-)


2 - Linked file (l)
3 - Dier file (d)

------System files-----

4 - Block file (b)


5 - Charcter (c)
6 - Socket File (s)
7 - Pipe File (p)

* Types of permission

1 - Read (r -- Octel no = 4 )
2 - Write (w -- Octel no = 2 )
3 - Execute (x -- Octel no = 1 )

* What is the use of UMASK


-> Umask is used to calculate the default permission of files and dir created bu
local and root users .

Umask of root = 022


Umask of local = 002

Total Permission of files - 666


Total permission of Dir - 777

* If root user creates files and Dir


Than,
Default permission of Files - (Total permission of file - Umask = 666-022 = 644 )
same for Dir we get = 755

* If Local user creates files and Dir


Default permission of Files = 664
Default permission of Dir = 775

* changing Permission we use command


Syntax default permission using letters
---- chmod < u,g,o > <+,-,=> <file_name> -----

-----------------------------------------------------------------------------------
----

-----TYPES OF SHELLS-------
-----------------------------------------------------------------------------------
---------------------------------------

* SPECIAL PERMISSION *

We have three types os special permission

1 - SUID ( Set user Identity ) --- Works on user level


2 - SGID ( Set group Identity ) -- Files created by dir get the same group
3 - Sticky bit -- One user cannot delete the file of others once
you applied sticky bits

* SUID -- chmod u+s <file_name>

--> We have command Dmidecode which can run only through root user , if we are
applying SUID to that command it will also ececute by local user
command --- chmod u+s /sbin/dmidecode

* SGID -- chmod g+s <file_name>

--> If we assigned SGID to a particular Dir if file is created inside the that dir
by local or root user that file will get default group
ownership automatically

* Sticky bit -- chmod o+t <file_name>

--> It avoid the deletion of files by two users

* ACL ( access control list ) -- We can assigned ACL permission in files/Dir to


particular group or user

* Bsic Syntax of ACL

# setfacl -m u:<user-name>:<Perm> <file_name> -- for user


# setfacl -m g:<grp-name>:<Perm> <file_name> -- for grp

-----------------------------------------------------------------------------------
-----------------------------------------------------------

------ PACKAGE MANAGMEBT ----------

* We can manage package in different ways , mostly we use Redhat(linux) family and
Ubuntu family

# In Readhat family we have two tools to install and download packages and their
dependencies
--> Yum
1. Yum stands for Yellow dog manage
2. It is high level tool
3. It resolve and install packages as well as dependies

# Syntax and options for Yum . We are taking the example of tree package

1. yum install tree -y


2. yum update tree
3. yum info tree
4. yum history tree
5. yum repolist
6. yum remove tree
7. yum search < package name >

--> Rpm
1. Rpm Stands for RedHat package Manager
2. It is low lovel tool
3. It Does not Resolve Dependies It only install packages

# Syntax and options for Rpm . We are taking the example of tree packa

1. rpm -i <package-name> ---(installation)


2. rpm -v ( for verbose)
3. rpm -h ( show hash bar)
4. rpm -u ( to upgrade packages )
5. rpm -q ( query package )
6. rpm -e ( to erase package )

# Ubuntu Family
--> In Ubunty family to manage packahges we use

1.apt-get
2.dpkg

# We also use curl -O and wget to manage packages in ubuntu family


Syntac wget <Package URL > ---- ( Same for Curl )

# Practicle for Practice TO make our private Repo

mkdir /local_store
ls /
cd /local_store/
yumdownloader httpd
ls
createrepo /local_store/
ls
cd /etc/yum.repos.d/
ls
vim localrp.repo
ls
yum clean all
yum repolist all
yum install httpd
rpm -evf httpd
yum install httpd-------> it will install httpd package from your local rep

(-------------same for sambha --------)

-----------------------------------------------------------------------------------
----------------------------------------------

---- LOG MANAGMENT ---------------

* The most important work use for monitoring purpose it is used by Developer,System
Admin and Devops guy as well.
* It is also use for TroubleShooting
* Logs in linix that also stores various event activity of the System .
* In Simple words Every things than happen on our System its reacords and stores ,
Which will be more help for the users to know their system well.
# All the logs related to service are stored in

---- /var/log/<service-name> -------

# Commands for monitoring logs

1. To view logs -- cat or less /var/logs/<service-name>


2. Monitoring logs in real time -- tail -f /var/logs/<service-name> ----( -f
use for real time logs )
3. Smiliarly we also have -- head -n /var/logs/<service-name> ----( -n
number )
4. For searching we use -- grep "< word to search >"
/var/logs/<service-name>
5. Checking size or usage of logs-- du -h /var/log ( -h for human readble )
6. to manually rotate logs we can also use -- logrotate -f /etc/logrotate.conf
7. journalctl -xe -- To ckeck the very latest logs or current logs

# Rsyslog - It is also use for managing system logs in linux system


Works on port no -- 514
Having Configuration file -- /etc/rsyslog.conf
Its is the Demon service that always runs in backgrounf Continously

# Centralized log Managment -- The name itself indicat that we can store all the
system realated logs in Centralized Manner
That reduces human Effort and Time Managment
Also we get the advance security capablity for
monitoring System

-----------------------------------------------------------------------------------
---------------------------------------------------------

------- Archiving & Compression ------------------

* Archiving is the process where we can combine multile files and Directories .---
( TO KEEP BACKUPS )
* We usually use archiving to keep the backup files .
* Compression is the process that reduce the file size or directory ---
( TO REDUCE SIZE )

# To Store large amount of data in single file we have command " tar "

--> tar <option> <new-Compressfile-name>.tar <file to be compress>


--> tar -c etc-backup.tar /etc --- ( I am reducing the size of etc file and giving
name "etc-backup.tar"
Before tar size of /etc = 38M
After tar size of /etc = 34M

# we have multiple option while creating tar file


1. -c ( create )
2. -f ( file name )
3. -t ( list the archive content )
4. -v ( verbose )
5. -x ( execute the content from archive )
6. -C ( copy the archive file to different Dir )

# Mainly we can compress the file using three ways ( gzip , bzip2 , xz )
( ----- The main dependency for compression is tar file --------- Suppose we have
already created file with name "etc-backup.tar")
1. gzip -z(option) <file-name>.tar.gz(extension) ------( size reduce 30% )

EX.g [ tar -cvzf /etc-backup.tar.gz /etc ]

2. bzip2 -j(option) <file-name>.tar.bz2(extension) -----( size reduce 50% )

EX.g [ tar -cvjf /etc-backup.tar.bz2 /etc ]

3. xz -J(option) <file-name>.tar.xz(extension) ---- ( size reduce 80% )

EX.g [ tar -cvJf /etc-backup.tar.xz /etc ]

-----------------------------------------------------------------------------------
---------------------------------------------------------

-------- JOB SCHEDULING --------

* It is use to automate tasks at specified times or intervals.


* In linux mostly we have two commands we can schedule our job
1. at -- "at" command is used when we want to execute our task in single time
ex --- at 10:30 PM tomorrow
> echo " Good morning " > file.txt
> ctrl D ----- ( to save the task )
atq ---- ( to check job is schedule or not )

2. cron -- "Cron" is used when we want to execute our task perodically


-- > Field of crontab
-- > Crontab <option>
1. -e ( edit cron tab )
2. -l ( list cron )
3. -r ( remove crontab )
4. -e -u ( edit cron for specific user )
5. -l -u ( list cron for specific user )
6. -r -u ( remove cron for specific user )

------- [ min (0-59)] [hours(0-23)] [days of month (1-31)] [month(1-12)] [days


of week(0-6)] ---------------
Example :-
1.Create a file in /root/Downloads dir with name FLOWER.txt at 10.30 pm
on 15 Aug
--> crontab -e
--> 30 22 15 8 * /root/Downloads/FLOWER.txt

2.Display “HELLO” massage on terminal after every hour on 10th of Jan,


Feb, and March
--> crontab -e
--> 0 * 10 jan,feb,mar * echo “HELLO”

-----------------------------------------------------------------------------------
-----------------------------------------

You might also like