Linux Commands To Know by Devops Engineer
Linux Commands To Know by Devops Engineer
Free memory cache, dentries and inode (with root): $ echo 3 > To print the process specific memory utilizations:
/proc/sys/vm/drop_caches $ ps aux --sort=-%mem
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 <directory path e..g /mount-vol>
$ 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 ‘clouda
Find the file (search for a file): Search the text string in a directory and print filename containing that
$ find <dir path> -name <filename> -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`
awk command for pattern scanning & processing: cut, cutting out the sections from lines: diff, get the
1. Convert text from upper case to lower case $ cut -d “delimiter” -f <field> <file.txt> files line by
$ echo "SAMPLE TEXT" | awk '{print tolower($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 8873893" | 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++)if($i=="reach:")print
$ echo
$(i+1)}'
"hello/var/log/syslog
world" | cut -d " " -f 1-2 --output-deli
3. Trim the white spaces %
echo ' aws <command> 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 ‘dnsconf=/etc/resolv.conf’ or ‘dnsconf:/etc/resolv.conf’ for both same comma
nd will work
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> <username>@<remote
$ echoip>:<f
'Unix
$ cat file1.log | tee -a file2.log irpath>
b) redirect the command output to a log file e.g. $ scp id_rsa.pem rakesh@192.168.56.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@192.168.56.120
c) delete 5t