0% found this document useful (0 votes)
22 views

Linux Commands To Know by Devops Engineer

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Linux Commands To Know by Devops Engineer

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Linux Commands to know by DevOps Engineer Cheat Sheet

by rakesh zingade via cheatography.com/71377/cs/18096/

System/OS related commands User admin Commands (cont)

To know the OS type: To know


To create
the CPU
a new
archit​
group:
ecture:
$ uname -o $ uname
$ sudo
-m groupadd <group name>

To check the kernel version: To gete.g.


the OS$ name,
sudo release,
groupadd training
version:
$ uname -r To /etc/o​s-r​elease
$ cat delete the existing group:
To list the system hardware: $ the
To get sudo
CPUgroupdel
details: <group name>
$ lshw e.g.
$ lscpu $ sudo groupdel training

To check system memory: To check the virtual memory stats:


$ free -h $ vmstat -S m

Free memory cache, dentries and inode (with root): $ echo 3 > To print the process specific memory utiliz​ations:
/proc/​sys​/vm​/dr​op_​caches $ ps aux --sort​=-%mem

To search packages for instal​lation: To installed package:


$ apt search <pa​ckage name> $ sudo apt-get install <pa​ckage name>
e.g.:
$ apt search python​-boto
Print the groups to which the current user is associ​ated:
To uninstall package: To list$ the mounted disk drives:
groups
$ sudo apt-get remove <pa​ckage name $ df -kh

To mount the volume: To list biggest files from directory (biggest 5):
(create the directory first to mount volume) $ sudo du -a /dir/ | sort -n -r | head -n 5
Change the group name:
$ mkdir -p <di​rectory path e..g /mount​-vo​l>
$ sudo groupmod –n <new group name> <old group name>
$ sudo mount <src path> <above created dir path>
e.g. I want to change the groupname ‘training’ to ‘cloud​a
Find the file (search for a file): Search the text string in a directory and print filename containing that
$ find <dir path> -name <fi​len​ame> -print string: $ sudo groupmod -n cloudadmin training
e.g. to find app.log in /var directory $ file /var -type f -print | xargs grep <search text>
$ find /var -name app.log –print`

File the text string from a given directory:


$ grep -rIn <search text> <di​rectory path>

User admin Commands

To know the group/user exists on the Check user added or not


system: into system:
$ getent group <group name> $ id <us​ern​ame>
$ getent passwd <user name> e.g. $ id clouduser1

By rakesh zingade Not published yet. Sponsored by CrosswordCheats.com


cheatography.com/rakesh- Last updated 2nd December, 2018. Learn to solve cryptic crosswords!
zingade/ Page 1 of 4. http://crosswordcheats.com
Linux Commands to know by DevOps Engineer Cheat Sheet
by rakesh zingade via cheatography.com/71377/cs/18096/

Editor​/Text manipu​lation commands Editor​/Text manipu​lation commands (cont)

awk command for pattern scanning & proces​sing: cut, cutting out the sections from lines: diff, get the
1. Convert text from upper case to lower case $ cut -d “delim​iter” -f <fi​eld> <fi​le.t​xt> files line by
$ echo "​SAMPLE TEXT" | awk '{print tolowe​r($0)}' a) cut the line on space and print 1st to 4th field$ diff
2 Print the next word after found a pattern $ echo "my phone number is 887389​3" | cut -d " " -f 1-4 b
e.g. print the next work after ‘reach:’ appear in syslogchange
file the delimiter space with column
$ awk '{for(​i=1​;i<​=NF​;i+​+)i​f($​i==​"​rea​ch:​"​)print
$ echo
$(i+1)}'
"​hello/var/log/syslog
world" | cut -d " " -f 1-2 --outp​ut-​del​i
3. Trim the white spaces %
echo ' aws <co​mma​nd> help ' | awk '{gsub(/^ +| +$/,"")}1'
Sort is to sort file, records, lists etc:
4. Print the selected columns from command output. a) sort file contents of text file (-r option to reverse so
E.g. from df command interested in only filesystem and use% column
$ sort data
file.txt
$ df -kh |awk '{print $1 " " $5}' b) sort based on column number
5. use regex as a field separator, $ df -kh | sort -k 5
e.g input field separator as / or = e.g.
$ awk -F"=​|:" '{print $2}'
input text as ‘dnsco​nf=​/et​c/r​eso​lv.c​onf’ or ‘dnsco​nf:​/et​c/r​eso​lv.c​onf’ for both same comma
nd will work

By rakesh zingade Not published yet. Sponsored by CrosswordCheats.com


cheatography.com/rakesh- Last updated 2nd December, 2018. Learn to solve cryptic crosswords!
zingade/ Page 2 of 4. http://crosswordcheats.com
Linux Commands to know by DevOps Engineer Cheat Sheet
by rakesh zingade via cheatography.com/71377/cs/18096/

Editor​/Text manipu​lation commands (cont) Network related commands (cont)

tee, is a command which reads the standard input and write into standard output
scp, secure
and also
copy
to a
from
file.remote
This is host
used to redirect logs or data sed - stream edit
to a file: a) copy file from remote host a) Find and r
a) let we have two log files, file1.log & file2.log and we need toscp
(syntax) append file1.log
-i <pem to file2.log
file> <us​ern​ame​>@<​remote
$ echoip>​:<f
'Unix
$ cat file1.log | tee -a file2.log irpat​h>
b) redirect the command output to a log file e.g. $ scp id_rsa.pem rakesh​@19​2.1​68.5​6.120:/home​/ra​
b) delete pa
$ du --max-​depth=1 -h | sort -hr 2>&1 | tee du.log b) copy local file to remote host $ sed '5d' f
$ scp -i id_rsa.pem data.txt rakesh​@19​2.1​68.5​6.120
c) delete 5t

lsof, list open files by processes $ sed '5,10d


a) list open files by specific user (check more
lsof -u <us​ern​ame>
Network related commands b) find processes running on specific port
nslookup, Query internet domain name server netstat, print the network stats,
$ lsof listening ports etc
-i TCP:9090
a) find the IP from fqdn a) print all listening ports
$ nslookup google.com $ netstat -plunt
b) check the fqdn from ip address b) check if server
curlis listening
ifconf​ onpublic
ig.co, get the portip8080
of the or not
machine
$ nslookup 172.21​7.1​67.174 $ netstat -plunt $
| curl
grep ifconf​ig.co
8080
c) list stats of all ports
$ netstat -s
d) display pid of listening ports
$ netstat -pt
e) list network interfaces
$ netstat -i
ufw, manage firewall
a) check firewall status
$ sudo ufw status
b) enable​/di​sable firewall
$ sudo ufw enable​/di​sable

By rakesh zingade Not published yet. Sponsored by CrosswordCheats.com


cheatography.com/rakesh- Last updated 2nd December, 2018. Learn to solve cryptic crosswords!
zingade/ Page 3 of 4. http://crosswordcheats.com
Linux Commands to know by DevOps Engineer Cheat Sheet
by rakesh zingade via cheatography.com/71377/cs/18096/

sed - stream editor sed - stream editor (cont)

Sed - perform basic transf​orm​ations on an input stream i.e. a file or a stream


$ -input
end from
of thealine
pipeline. ------​---​---​---​---​---​---​---​---​-------
Example: replace all occurr​ences of TCP to UDP in networ​k.log file Extract the line containing IP address from a file
sed -rn '/([0-​9]{​1,3​}\.)​{3​}[0​-9]​{1,​3}/p' /etc/hosts
$ sed 's/TCP​/UDP/' networ​k.log > modifi​ed-​net​wor​k.log
Common sed command line options
-i : edit in place i.e. sed -i 's/TCP​/UDP/' networ​k.log
-n <line number​>p e.g. print on line no 30 from networ​k.log sed -n '30p' networ​k.log
-e : expression e.g. sed -e 's/TCP​/UDP/' networ​k.log
[ here 's' stand for substitute ]
Basic regular expression overview
. : (dot) matches any single character
* : matches a sequence of zero or more instances e.g.
$ echo 'hostn​ame​=lo​cal​hos​t.m​yor​g.com' | sed 's/l.l/myap​pse
​rver/' *
^ : indicates the beginning of the line
$ : indicates the end of the line
[list] or [^list] :matches any single char in a list. e.g. [1-9] matches any digit from 1 to 9
\+ : As *, matches any single or multiple instances of chars
\?: As *, matches any zero or one instances of chars
\{i\}: matches exactly i sequences 'i is between 0 to 255'
\{i,\} : matches more than or equal to i sequences
regex1​|regex2 : matches regular expression 1 or regular expression 2
[a-z0-​9A-z]: matches any ASCII chars
======​===​===​===​===​===​===​===​===​=======
Examples
------​---​---​-------
# find and replace any os name with Ubuntu
e.g.
1.
input: osname: centOS7
output: osname: Ubantu
2.
input: winOS: Windows-10
output: osname: Ubantu
3.
input: MacOS:​Mac10
output: osname: Ubantu
Solution:
key=echo "​<input string​>" | cut -d "​:" -f 1
echo "​<input string​" | sed -e 's/^$k​ey:\s.$/$key: Ubantu/g'
first store the key i.e. left side label
^ - start of line
\s* - zero or more space charaters
.* - any zero or multiple charaters

By rakesh zingade Not published yet. Sponsored by CrosswordCheats.com


cheatography.com/rakesh- Last updated 2nd December, 2018. Learn to solve cryptic crosswords!
zingade/ Page 4 of 4. http://crosswordcheats.com

You might also like