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

main_devops-engineer-linux-commands-cheat-sheet (1)

Uploaded by

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

main_devops-engineer-linux-commands-cheat-sheet (1)

Uploaded by

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

Linux Commands to know by DevOps Engineer Cheat

Sheet

System/OS related commands User admin Commands

To know the group/user


Check user added or not into system:
To know the OS type: To know the CPU
exists on the system:
$ id <username>
$ uname -o architecture:
$ getent group
$ uname -m e.g. $ id clouduser1
<group name>
To check the kernel version: To get the OS name, release,
$ getent passwd
$ uname -r version:
<user name>
$ cat /etc/os-release
To create a new group:
Modify existing user, add user to group:
To list the system hardware: To get the CPU details:
$ sudo groupadd
$ sudo usermod -aG <group name>
$ lshw $ lscpu
<group name>
<username>
To check system memory: To check the virtual memory e.g. $ sudo
e.g. $ sudo usermod –aG sudo
$ free -h stats: groupadd training
clouduser1
$ vmstat -S m
To delete the existing
Add user’s home directory (example for
Free memory cache, dentries and To print the process specific group:
clouduser1):
inode (with root): $ echo 3 > memory utilizations: $ sudo groupdel
$ sudo mkdir -p /home/user1
/proc/sys/vm/drop_caches $ ps aux --sort=-%mem
<group name>
$ sudo chown
To search packages for installation: To installed package: e.g. $ sudo
clouduser1:clouduser1
$ apt search <package name> $ sudo apt-get install groupdel training
/home/user1 $ ls -l /home
e.g.: <package name>
drwxr-xr-x 2 clouduser1
$ apt search python-boto
clouduser1 4096 Nov 18 12:13
To uninstall package: To list the mounted disk user1
$ sudo apt-get remove <package drives: $ sudo usermod -d /home/user1
name
$ df -kh clouduser1

To mount the volume: To list biggest files from $ id clouduser1

(create the directory first to mount directory (biggest 5): uid=1002(clouduser1)


volume) $ sudo du -a /dir/ | gid=1003(clouduser1)
$ mkdir -p <directory path sort -n -r | head -n 5 groups=1003(clouduser1),27(sudo)
e..g /mount-vol> $ su - clouduser1
$ sudo mount <src path> $ pwd
<above created dir path> /home/user1

Find the file (search for a file): Search the text string in a Print the groups to Delete existing user with all files
$ find <dir path> -name directory and print filename which the current user associated with user:
<filename> -print containing that string: is associated: $ sudo userdel -r clouduser1
e.g. to find app.log in /var $ file /var -type f - $ groups $ id clouduser1
directory print | xargs grep id: ‘clouduser1’: no such user
$ find /var -name app.log –print` <search text>

File the text string from a given directory:


$ grep -rIn <search text> <directory path>

By rakesh zingade
Not published yet. Sponsored by Readability-
cheatography.com/rake Last updated 2nd December, Score.com Measure your website
sh- zingade/ 2018. Page 1 of 4. readability! https://readability-
score.com
Linux Commands to know by DevOps Engineer
Cheat Sheet

User admin Commands (cont) Editor/Text manipulation commands (cont)


Change the group name:Add user to system:
$ sudo groupmod –n <new group name>$ sudo adduser cut, cutting out the sections
Uniq, is a command that filter
<old group name><user name> from lines:
e.g. I want to change the groupnamee.g. add ‘training’ to ‘cloudadmin’clouduser1 to out the duplicates
$ sudo groupmod -n cloudadminsystem $ cut -d “delimiter” -f
a) fetch
training$ sudo adduser
<field> <file.txt>
clouduser1 repeated/duplicate lines
a) cut the line on space from a file
and print 1st to 4th field
$ uniq -d <file.txt>
$ echo "my phone number is
b) get the count of uniq
8873893" | cut -d " " -f
lines in a file {nl}} $
1-4 b)
uniq -c <filename>
Editor/Text manipulation commands change the delimiter space
with column
awk command for pattern scanning & diff, get the
processing: differences by comparing$files
echo
line"hello
by line world" |
1. Convert text from upper case to lower$case
diff
$ echo "SAMPLE TEXT" | awk '{print cut -d " " -f 1-2 --
output-delimiter=%

Sort is to sort file, records, lists tr is to translate or delete


tolower($0)}' file1.txt etc: characters
2 Print the next word after found a file2.txt
a) sort file contents of a) translate all lowercase
pattern text file (-r option to letters to upper case in a
e.g. print the next work after ‘reach:’ appear in syslog filereverse sorting)
$ awk '{for(i=1;i<=NF;i++)if($i=="reach:")p rint $(i+1)}' /var/log/syslog file
Trim the white spaces $ sort file.txt $ cat filename | tr
echo ' aws <command> help ' | awk '{gsub(/^ +| +$/,"")}1'
Print the selected columns from command output. b) sort based on column “[:lower:]” “[:upper:]”
E.g. from df command interested in only filesystem and use% number
column data
$ df -kh |awk '{print $1 " " $5}' b) translate white spaces
5. use regex as a field separator, $ df -kh | sort -k 5 to tabs
e.g input field separator as / or = e.g.
$ awk -F"=|:" '{print $2}' input text as ‘dnsconf=/etc/resolv.conf’ or $ cat filename | tr
‘dnsconf:/etc/resolv.conf’ for both
same command will work [:space:] ‘\t’
c) remove all digits from
string
$ echo "my mob number
88039223" | tr -d
[:digit:]
d) Just get the digits
from string
$ echo "my mob number
88039223" | tr -cd
[:digit:]

By rakesh zingade Not published yet. Sponsored by Readability-


Last updated 2nd December, Score.com
cheatography.com/
rakesh- zingade/ 2018. Page 2 of 4. Measure your website
Linux Commands to know by DevOps Engineer
Cheat Sheet

Editor/Text manipulation commands (cont) Network related commands (cont)

tee, is a command which reads the standard


sed - stream editor, it scp, secure copy from remote host nmap, check open ports
input and write into standard output and also
is used for filtering a) copy file from remote host on server, generally used
to a file. This is used to redirect logs or data
and transforming text (syntax) scp -i <pem file> as network exploration
to a file:
a) Find and <username>@<remote ip>: tool
a) let we have two log files,
replace text <filepath> <local destination a) check open ports
file1.log & file2.log and we need to
$ echo 'Unix is dirpath> on remote host
append file1.log to file2.log
multi-user OS' | e.g. $ scp id_rsa.pem $ nmap
$ cat file1.log | tee -a file2.log
sed [email protected]:/home/r 172.217.27.206
b) redirect the command output to a
's/Unix/Linux/' akesh/data.txt . b) list out all
log file
b) delete b) copy local file to remote machines from network
$ du --max-depth=1 -h | sort -hr
particular line host that responds to ping
2>&1 | tee du.log
from a file $ scp -i id_rsa.pem data.txt $ nmap -sP

(e.g. 5th line) [email protected]:/home/r 192.168.56.0/24

$ sed '5d' akesh c) scan and print

file.txt ports, os & other

c) delete 5th to details about remote

10th line from a host

file $ sudo nmap -sS -A -

$ sed '5,10d' T4 192.168.56.150

file.txt (check lsof, list open files by processes netcat, debug and
more details in a) list open files by specific investigate network
a separate user a) start a dummy
block) lsof -u <username> listening server on

b) find processes running on port 8080


Network related commands specific port $ netcat -l 8080
nslookup, Query internetnetstat, print the network stats, domain name serverlistening
$ lsof ports etc
-i TCP:9090 b) send data over
find the IP froma) print all listening ports fqdn$ netstat -plunt
$ nslookup google.com b) check if server is listening some port to server
check the fqdnon port 8080 or not
$ netcat <remote
from ip address$ netstat -plunt | grep 8080
$ nslookupc) list stats of all ports server ip> <port>
172.217.167.174$ netstat -s
display pid of listening ports e.g.
$ netstat -pt
$ netcat
list network interfaces
$ netstat -i 192.168.56.120 8080
(press EOF CNTR+D at
end)

By rakesh zingade Not published yet. Sponsored by Readability-


Last updated 2nd December, Score.com
cheatography.com/
rakesh- zingade/ 2018. Page 3 of 4. Measure your website
Linux Commands to know by DevOps Engineer
Cheat Sheet

Network related commands (cont) sed - stream editor (cont)


\{i\}: matches exactly i sequences 'i is between 0 to 255'
curl ifconfig.co, get the
route, show/=manipulate IP routing table \{i,\} : matches more than or equal to i sequences
public ip of the machine regex1|regex2 : matches regular expression 1 or regular expression 2
a) show current routing table
[a-z0-9A-z]: matches any ASCII chars
$ curl ifconfig.co =====================================
$ route -n
Examples
b) add route to particular
network e.g.
make 10.10.76.0/24 accessible via # find and replace any os name with Ubuntu e.g.
1.
gw 10.10.76.1 input: osname: centOS7 output: osname: Ubantu 2.
input: winOS: Windows-10 output: osname: Ubantu 3.
$ route add -net 10.10.76.0
input: MacOS:Mac10 output: osname: Ubantu Solution:
netmask 255.255.255.0 gw key=echo "<input string>" | cut -d ":" -f 1 echo "<input string" | se
^ - start of line
10.10.76.1 \s* - zero or more space charaters
.* - any zero or multiple charaters
ufw, manage firewall hostname, provides hostname of a $ - end of the line
a) check firewall machine -------------------------------------
Extract the line containing IP address from a file sed -rn '/([0-9]{1,3}\.){3}[0-
status a) get hostname
$ sudo ufw status $ sudo hostname
b) enable/disable
firewall
$ sudo ufw
enable/disable

sed - stream editor


Sed - perform basic transformations on an input stream i.e. a file or a stream input from a pipeline.
Example: replace all occurrences of TCP to UDP in network.log file
$ sed 's/TCP/UDP/' network.log > modified-network.log
Common sed command line options
-i : edit in place i.e. sed -i 's/TCP/UDP/' network.log
-n <line number>p e.g. print on line no 30 from network.log sed -n '30p' network.log
-e : expression e.g. sed -e 's/TCP/UDP/' network.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 'hostname=localhost.myorg.com' | sed 's/l.l/myappserver/' *
^ : 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

By rakesh zingade Not published yet. Sponsored by Readability-


cheatography.com/rake Last updated 2nd December, Score.com Measure your website
sh- zingade/ 2018. Page 4 of 4. readability! https://readability-
score.com

You might also like