\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{rakesh zingade} \pdfinfo{ /Title (linux-commands-to-know-by-devops-engineer.pdf) /Creator (Cheatography) /Author (rakesh zingade) /Subject (Linux Commands to know by DevOps Engineer Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{3C84A3} \definecolor{LightBackground}{HTML}{F2F7F9} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Linux Commands to know by DevOps Engineer Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{rakesh zingade} via \textcolor{DarkBackground}{\uline{cheatography.com/71377/cs/18096/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}rakesh zingade \\ \uline{cheatography.com/rakesh-zingade} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 2nd December, 2018.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{System/OS related commands}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{To know the OS type:}} \{\{nl\}\} `\$ uname -o` & {\bf{To know the CPU architecture:}} \{\{nl\}\} `\$ uname -m` \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{To check the kernel version:}} \{\{nl\}\} `\$ uname -r` & {\bf{To get the OS name, release, version:}} \{\{nl\}\} `\$ cat /etc/os-release` \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} {\bf{To list the system hardware:}} \{\{nl\}\} `\$ lshw` & {\bf{To get the CPU details:}} \{\{nl\}\} `\$ lscpu` \tn % Row Count 10 (+ 3) % Row 3 \SetRowColor{white} {\bf{To check system memory:}} \{\{nl\}\} `\$ free -h` & {\bf{To check the virtual memory stats:}} \{\{nl\}\} `\$ vmstat -S m` \tn % Row Count 14 (+ 4) % Row 4 \SetRowColor{LightBackground} {\bf{Free memory cache, dentries and inode (with root):}} `\$ echo 3 \textgreater{} \seqsplit{/proc/sys/vm/drop\_caches`} & {\bf{To print the process specific memory utilizations:}} \{\{nl\}\} `\$ ps aux -{}-sort=-\%mem` \tn % Row Count 19 (+ 5) % Row 5 \SetRowColor{white} {\bf{To search packages for installation:}} \{\{nl\}\} `\$ apt search \textless{}package name\textgreater{} \{\{nl\}\} e.g.: \{\{nl\}\} \$ apt search python-boto` & {\bf{To installed package:}} \{\{nl\}\} `\$ sudo apt-get install \textless{}package name\textgreater{}` \tn % Row Count 26 (+ 7) % Row 6 \SetRowColor{LightBackground} {\bf{To uninstall package:}} \{\{nl\}\} \$ sudo apt-get remove \textless{}package name & {\bf{To list the mounted disk drives:}} \{\{nl\}\} `\$ df -kh` \tn % Row Count 30 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{System/OS related commands (cont)}} \tn % Row 7 \SetRowColor{LightBackground} {\bf{To mount the volume:}} \{\{nl\}\} (create the directory first to mount volume) \{\{nl\}\} `\$ mkdir -p \textless{}directory path e..g /mount-vol\textgreater{} \{\{nl\}\} \$ sudo mount \textless{}src path\textgreater{} \textless{}above created dir path\textgreater{}` & {\bf{To list biggest files from directory (biggest 5):}} \{\{nl\}\} `\$ sudo du -a /dir/ | sort -n -r | head -n 5` \tn % Row Count 10 (+ 10) % Row 8 \SetRowColor{white} {\bf{Find the file (search for a file):}} \{\{nl\}\} `\$ find \textless{}dir path\textgreater{} -name \textless{}filename\textgreater{} -print \{\{nl\}\} e.g. to find app.log in /var directory \{\{nl\}\} `\$ find /var -name app.log –print` & {\bf{Search the text string in a directory and print filename containing that string:}} \{\{nl\}\} `\$ file /var -type f -print | xargs grep \textless{}search text\textgreater{}` \tn % Row Count 19 (+ 9) % Row 9 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\bf{File the text string from a given directory:}} \{\{nl\}\} `\$ grep -rIn \textless{}search text\textgreater{} \textless{}directory path\textgreater{}`} \tn % Row Count 21 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{User admin Commands}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{To know the group/user exists on the system:}} \{\{nl\}\} `\$ getent group \textless{}group name\textgreater{} \{\{nl\}\} \$ getent passwd \textless{}user name\textgreater{}` & {\bf{Check user added or not into system:}} \{\{nl\}\} `\$ id \textless{}username\textgreater{} \{\{nl\}\} e.g. \$ id clouduser1` \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} {\bf{To create a new group:}} \{\{nl\}\} `\$ sudo groupadd \textless{}group name\textgreater{} \{\{nl\}\} e.g. \$ sudo groupadd training` & {\bf{Modify existing user, add user to group:}} \{\{nl\}\}`\$ sudo usermod -aG \textless{}group name\textgreater{} \textless{}username\textgreater{} \{\{nl\}\} e.g. \$ sudo usermod –aG sudo clouduser1` \tn % Row Count 14 (+ 8) % Row 2 \SetRowColor{LightBackground} {\bf{To delete the existing group:}} \{\{nl\}\} `\$ sudo groupdel \textless{}group name\textgreater{} \{\{nl\}\} e.g. \$ sudo groupdel training` & {\bf{Add user's home directory (example for clouduser1):}} \{\{nl\}\} `\$ sudo mkdir -p /home/user1 \{\{nl\}\} \$ sudo chown \seqsplit{clouduser1:clouduser1} /home/user1 \$ ls -l /home \{\{nl\}\} drwxr-xr-x 2 clouduser1 clouduser1 4096 Nov 18 12:13 user1 \{\{nl\}\} \$ sudo usermod -d /home/user1 clouduser1 \{\{nl\}\} \$ id clouduser1 \{\{nl\}\} \seqsplit{uid=1002(clouduser1)} \seqsplit{gid=1003(clouduser1)} \seqsplit{groups=1003(clouduser1)},27(sudo) \{\{nl\}\} \$ su - clouduser1 \{\{nl\}\} \$ pwd \{\{nl\}\} /home/user1` \tn % Row Count 37 (+ 23) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{User admin Commands (cont)}} \tn % Row 3 \SetRowColor{LightBackground} {\bf{Print the groups to which the current user is associated:}} \{\{nl\}\} `\$ groups` & {\bf{Delete existing user with all files associated with user:}} \{\{nl\}\} `\$ sudo userdel -r clouduser1 \{\{nl\}\} \$ id clouduser1 \{\{nl\}\} id: 'clouduser1': no such user` \tn % Row Count 9 (+ 9) % Row 4 \SetRowColor{white} {\bf{Change the group name:}} \{\{nl\}\}`\$ sudo groupmod –n \textless{}new group name\textgreater{} \textless{}old group name\textgreater{} \{\{nl\}\} e.g. I want to change the groupname 'training' to 'cloudadmin' \{\{nl\}\} \$ sudo groupmod -n cloudadmin training` & {\bf{Add user to system:}}\{\{nl\}\} `\$ sudo adduser \textless{}user name\textgreater{} \{\{nl\}\} e.g. add clouduser1 to system \{\{nl\}\}\$ sudo adduser clouduser1` \tn % Row Count 20 (+ 11) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Editor/Text manipulation commands}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{awk command for pattern scanning \& processing:}}\{\{nl\}\}`1. Convert text from upper case to lower case \{\{nl\}\} \$ echo "SAMPLE TEXT" | awk '\{print tolower(\$0)\}' \{\{nl\}\} 2 Print the next word after found a pattern \{\{nl\}\} e.g. print the next work after 'reach:' appear in syslog file \{\{nl\}\} \$ awk '\{for(i=1;i\textless{}=NF;i++)if(\$i=="reach:")print \$(i+1)\}' /var/log/syslog\{\{nl\}\} 3. Trim the white spaces \{\{nl\}\} echo ' aws \textless{}command\textgreater{} help ' | awk '\{gsub(/\textasciicircum{} +| +\$/,"")\}1' \{\{nl\}\} 4. Print the selected columns from command output. \{\{nl\}\} E.g. from df command interested in only filesystem and use\% column data \{\{nl\}\} \$ df -kh |awk '\{print \$1 " " \$5\}' \{\{nl\}\} 5. use regex as a field separator, \{\{nl\}\} e.g input field separator as / or = e.g. \{\{nl\}\} \$ awk -F"=|:" '\{print \$2\}' \{\{nl\}\} input text as \seqsplit{'dnsconf=/etc/resolv}.conf' or \seqsplit{'dnsconf:/etc/resolv}.conf' for both same command will work` & {\bf{diff, get the differences by comparing files line by line}} \{\{nl\}\} ` \$ diff file1.txt file2.txt` \tn % Row Count 45 (+ 45) % Row 1 \SetRowColor{white} {\bf{cut, cutting out the sections from lines:}} \{\{nl\}\} `\$ cut -d "delimiter" -f \textless{}field\textgreater{} \textless{}file.txt\textgreater{} \{\{nl\}\} a) cut the line on space and print 1st to 4th field \{\{nl\}\} \$ echo "my phone number is 8873893" | cut -d " " -f 1-4 b) \{\{nl\}\} change the delimiter space with column \{\{nl\}\} \$ echo "hello world" | cut -d " " -f 1-2 -{}-output-delimiter=\%` & {\bf{Uniq, is a command that filter out the duplicates}} \{\{nl\}\}`a) fetch repeated/duplicate lines from a file \{\{nl\}\} \$ uniq -d \textless{}file.txt\textgreater{} \{\{nl\}\} b) get the count of uniq lines in a file \{nl\}\} \$ uniq -c \textless{}filename\textgreater{}` \tn % Row Count 63 (+ 18) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Editor/Text manipulation commands (cont)}} \tn % Row 2 \SetRowColor{LightBackground} {\bf{Sort is to sort file, records, lists etc:}} \{\{nl\}\} `a) sort file contents of text file (-r option to reverse sorting) \{\{nl\}\} \$ sort file.txt \{\{nl\}\} b) sort based on column number \{\{nl\}\} \$ df -kh | sort -k 5` & {\bf{tr is to translate or delete characters}} \{\{nl\}\} `a) translate all lowercase letters to upper case in a file \{\{nl\}\} \$ cat filename | tr "{[}:lower:{]}" "{[}:upper:{]}" \{\{nl\}\} b) translate white spaces to tabs \{\{nl\}\} \$ cat filename | tr {[}:space:{]} '\textbackslash{}t' \{\{nl\}\} c) remove all digits from string \{\{nl\}\} \$ echo "my mob number 88039223" | tr -d {[}:digit:{]} \{\{nl\}\} d) Just get the digits from string \{\{nl\}\} \$ echo "my mob number 88039223" | tr -cd {[}:digit:{]}` \tn % Row Count 23 (+ 23) % Row 3 \SetRowColor{white} {\bf{tee, is a command which reads the standard input and write into standard output and also to a file. This is used to redirect logs or data to a file:}} \{\{nl\}\} ` a) let we have two log files, file1.log \& file2.log and we need to append file1.log to file2.log \{\{nl\}\} \$ cat file1.log | tee -a file2.log \{\{nl\}\} b) redirect the command output to a log file \{\{nl\}\} \$ du -{}-max-depth=1 -h | sort -hr 2\textgreater{}\&1 | tee du.log` & {\bf{sed - stream editor, it is used for filtering and transforming text}} \{\{nl\}\} `a) Find and replace text \{\{nl\}\} \$ echo 'Unix is multi-user OS' | sed 's/Unix/Linux/' \{\{nl\}\} b) delete particular line from a file (e.g. 5th line) \{\{nl\}\} \$ sed '5d' file.txt \{\{nl\}\} c) delete 5th to 10th line from a file \{\{nl\}\} \$ sed '5,10d' file.txt \{\{nl\}\} (check more details in a separate block)` \tn % Row Count 44 (+ 21) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Network related commands}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{nslookup, Query internet domain name server}} \{\{nl\}\} `a) find the IP from fqdn \{\{nl\}\} \$ nslookup google.com \{\{nl\}\} b) check the fqdn from ip address \{\{nl\}\} \$ nslookup 172.217.167.174` & {\bf{netstat, print the network stats, listening ports etc}} \{\{nl\}\} `a) print all listening ports \{\{nl\}\} \$ netstat -plunt \{\{nl\}\} b) check if server is listening on port 8080 or not \{\{nl\}\} \$ netstat -plunt | grep 8080 \{\{nl\}\} c) list stats of all ports \{\{nl\}\} \$ netstat -s \{\{nl\}\} d) display pid of listening ports \{\{nl\}\} \$ netstat -pt \{\{nl\}\} e) list network interfaces \{\{nl\}\} \$ netstat -i ` \tn % Row Count 20 (+ 20) % Row 1 \SetRowColor{white} {\bf{scp, secure copy from remote host}} \{\{nl\}\} `a) copy file from remote host \{\{nl\}\} (syntax) scp -i \textless{}pem file\textgreater{} \textless{}username\textgreater{}@\textless{}remote ip\textgreater{}:\textless{}filepath\textgreater{} \textless{}local destination dirpath\textgreater{} \{\{nl\}\} e.g. \$ scp id\_rsa.pem \seqsplit{rakesh@192.168.56.120:/home/rakesh/data.txt} . \{\{nl\}\} b) copy local file to remote host \{\{nl\}\} \$ scp -i id\_rsa.pem data.txt \seqsplit{rakesh@192.168.56.120:/home/rakesh`} & {\bf{nmap, check open ports on server, generally used as network exploration tool}} \{\{nl\}\} `a) check open ports on remote host \{\{nl\}\} \$ nmap 172.217.27.206 \{\{nl\}\} b) list out all machines from network that responds to ping \{\{nl\}\} \$ nmap -sP 192.168.56.0/24 \{\{nl\}\} c) scan and print ports, os \& other details about remote host \{\{nl\}\} \$ sudo nmap -sS -A -T4 192.168.56.150` \tn % Row Count 39 (+ 19) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Network related commands (cont)}} \tn % Row 2 \SetRowColor{LightBackground} {\bf{lsof, list open files by processes}} \{\{nl\}\} `a) list open files by specific user \{\{nl\}\} lsof -u \textless{}username\textgreater{} \{\{nl\}\} b) find processes running on specific port \{\{nl\}\} \$ lsof -i TCP:9090 \{\{nl\}\}` & {\bf{netcat, debug and investigate network}} \{\{nl\}\} `a) start a dummy listening server on port 8080 \{\{nl\}\} \$ netcat -l 8080 \{\{nl\}\} b) send data over some port to server \{\{nl\}\} \$ netcat \textless{}remote server ip\textgreater{} \textless{}port\textgreater{} e.g. \{\{nl\}\} \$ netcat 192.168.56.120 8080 \{\{nl\}\} (press EOF CNTR+D at end)` \tn % Row Count 15 (+ 15) % Row 3 \SetRowColor{white} {\bf{curl ifconfig.co, get the public ip of the machine}} \{\{nl\}\} `\$ curl ifconfig.co` & {\bf{route, show/=manipulate IP routing table}} \{\{nl\}\} `a) show current routing table \{\{nl\}\} \$ route -n \{\{nl\}\} b) add route to particular network e.g. \{\{nl\}\} make 10.10.76.0/24 accessible via gw 10.10.76.1 \{\{nl\}\} \$ route add -net 10.10.76.0 netmask 255.255.255.0 gw 10.10.76.1` \tn % Row Count 29 (+ 14) % Row 4 \SetRowColor{LightBackground} {\bf{ufw, manage firewall}} \{\{nl\}\} `a) check firewall status \{\{nl\}\} \$ sudo ufw status \{\{nl\}\} b) enable/disable firewall \{\{nl\}\} \$ sudo ufw enable/disable` & {\bf{hostname, provides hostname of a machine}} \{\{nl\}\}`a) get hostname \{\{nl\}\} \$ sudo hostname` \tn % Row Count 37 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{sed - stream editor}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Sed}} - perform basic transformations on an input stream i.e. a file or a stream input from a pipeline. \newline % Row Count 3 (+ 3) {\bf{Example:}} replace all occurrences of TCP to UDP in network.log file \newline % Row Count 5 (+ 2) `\$ sed 's/TCP/UDP/' network.log \textgreater{} modified-network.log` \newline % Row Count 7 (+ 2) {\bf{Common sed command line options}} \newline % Row Count 8 (+ 1) {\emph{ -i : edit in place i.e. sed -i 's/TCP/UDP/' network.log }} \newline % Row Count 10 (+ 2) {\emph{ -n \textless{}line number\textgreater{}p e.g. print on line no 30 from network.log sed -n '30p' network.log }} \newline % Row Count 12 (+ 2) {\emph{ -e : expression e.g. sed -e 's/TCP/UDP/' network.log }} \newline % Row Count 14 (+ 2) {\emph{ {[} here 's' stand for substitute {]}}} \newline % Row Count 15 (+ 1) {\bf{Basic regular expression overview}} \newline % Row Count 16 (+ 1) {\bf{.}} : (dot) matches any single character \newline % Row Count 17 (+ 1) {\bf{*}} : matches a sequence of zero or more instances e.g. \newline % Row Count 19 (+ 2) {\emph{ ` \$ echo \seqsplit{'hostname=localhost.myorg.com'} | sed 's/l.}}l/myappserver/' `* \newline % Row Count 21 (+ 2) {\bf{\textasciicircum{}}} : indicates the beginning of the line \newline % Row Count 22 (+ 1) {\bf{\$}} : indicates the end of the line \newline % Row Count 23 (+ 1) {\bf{{[}list{]}}} or {\bf{{[}\textasciicircum{}list{]}}} :matches any single char in a list. e.g. {[}1-9{]} matches any digit from 1 to 9 \newline % Row Count 26 (+ 3) {\bf{\textbackslash{}+}} : As *, matches any single or multiple instances of chars \newline % Row Count 28 (+ 2) {\bf{\textbackslash{}?}}: As *, matches any zero or one instances of chars \newline % Row Count 30 (+ 2) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{sed - stream editor (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{\textbackslash{}\{i\textbackslash{}\}}}: matches exactly {\emph{i}} sequences 'i is between 0 to 255' \newline % Row Count 2 (+ 2) {\bf{ \textbackslash{}\{i,\textbackslash{}\}}} : matches more than or equal to {\emph{i}} sequences \newline % Row Count 4 (+ 2) {\bf{regex1|regex2}} : matches regular expression 1 or regular expression 2 \newline % Row Count 6 (+ 2) {\bf{{[}a-z0-9A-z{]}}}: matches any ASCII chars \newline % Row Count 7 (+ 1) \seqsplit{=====================================} \newline % Row Count 8 (+ 1) {\bf{Examples}} \newline % Row Count 9 (+ 1) -{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}- \newline % Row Count 10 (+ 1) \# find and replace any os name with Ubuntu \newline % Row Count 11 (+ 1) e.g. \newline % Row Count 12 (+ 1) 1. \newline % Row Count 13 (+ 1) input: osname: centOS7 \newline % Row Count 14 (+ 1) output: osname: Ubantu \newline % Row Count 15 (+ 1) 2. \newline % Row Count 16 (+ 1) input: winOS: Windows-10 \newline % Row Count 17 (+ 1) output: osname: Ubantu \newline % Row Count 18 (+ 1) 3. \newline % Row Count 19 (+ 1) input: MacOS:Mac10 \newline % Row Count 20 (+ 1) output: osname: Ubantu \newline % Row Count 21 (+ 1) Solution: \newline % Row Count 22 (+ 1) key=`echo "\textless{}input string\textgreater{}" | cut -d ":" -f 1` \newline % Row Count 23 (+ 1) echo "\textless{}input string" | sed -e 's/\textasciicircum{}\$key:\textbackslash{}s{\emph{.}}\$/\$key: Ubantu/g' \newline % Row Count 25 (+ 2) first store the key i.e. left side label \newline % Row Count 26 (+ 1) \textasciicircum{} - start of line \newline % Row Count 27 (+ 1) \textbackslash{}s* - zero or more space charaters \newline % Row Count 28 (+ 1) .* - any zero or multiple charaters \newline % Row Count 29 (+ 1) \$ - end of the line \newline % Row Count 30 (+ 1) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{sed - stream editor (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}- \newline % Row Count 1 (+ 1) Extract the line containing IP address from a file \newline % Row Count 3 (+ 2) sed -rn '/({[}0-9{]}\{1,3\}\textbackslash{}.)\{3\}{[}0-9{]}\{1,3\}/p' /etc/hosts% Row Count 5 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}