\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{gregcheater} \pdfinfo{ /Title (bash.pdf) /Creator (Cheatography) /Author (gregcheater) /Subject (bash 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}{B8C4A3} \definecolor{LightBackground}{HTML}{F6F7F3} \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{bash Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{gregcheater} via \textcolor{DarkBackground}{\uline{cheatography.com/26582/cs/7469/}}} \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}gregcheater \\ \uline{cheatography.com/gregcheater} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 14th March, 2016.\\ Updated 11th May, 2016.\\ 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*}{3} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{basic bash commands}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}pwd : print working directory} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}cd /path/to/dir : change direcotry} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}ls /dir/to/list : list directory content (default is .) \{\{bb\}\}} \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~~~-1 : display the content on one column} \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~~~~-l : display the content with long listing format} \tn % Row Count 8 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~~~-a : display the content of the directory (including hidden files)} \tn % Row Count 10 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~~~~-R : Display the content of the directory and the content of subdirectories\{\{bb\}\}} \tn % Row Count 13 (+ 3) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}mv /path/to/file /path/where/to/move : move or rename a file or a directory} \tn % Row Count 15 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}cp /path/to/file /path/where/to/copy : copy a file \{\{bb\}\}} \tn % Row Count 17 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~~~-r : copy recursively (used to copy directory) \{\{bb\}\}} \tn % Row Count 19 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}rm /path/to/file : remove a file \{\{bb\}\}} \tn % Row Count 21 (+ 2) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~~~-r : remove recursively (used to remove directories)} \tn % Row Count 23 (+ 2) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~~~~-f : force remove \{\{bb\}\}} \tn % Row Count 24 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}mkdir /path/dirName : create an empty directory} \tn % Row Count 26 (+ 2) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}rmdir /path/to/dir : remove a directory (works only if the direcotry is empty)} \tn % Row Count 28 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{bash redirections}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}command \textgreater{} file : redirect stdout to file. (creates the file if it doesn't exist and overwrite it if it does exist)} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}command \textgreater{}\textgreater{} file : redirect stdout to file. (creates the file if it doesn't exist and append to the end it if it does exist)} \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}command 2\textgreater{} file : redirect stderr to file (creates the file if it doesn't exist and overwrite it if it does exist)} \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}command 2\textgreater{}\textgreater{} file : redirect stdout to file. (creates the file if it doesn't exist and append to the end it if it does exist)} \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}command \&\textgreater{} file : redirect stdout and stderr to file (creates the file if it doesn't exist and overwrite it if it does exist)} \tn % Row Count 15 (+ 3) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}command \&\textgreater{}\textgreater{} file : redirect stdout and stderr to file. (creates the file if it doesn't exist and append to the end it if it does exist)} \tn % Row Count 18 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}command \textless{} file : redirect stdin to file.} \tn % Row Count 20 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\} command1 | command 2 : uses the output of command1 as the input of command2} \tn % Row Count 22 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{file globbing regex}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}\textbackslash{} : escape character. It deletes the signification of a special character} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}? : Any character, once.} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}* : Any character, 0, 1 or many time.} \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}{[}...{]} : Any character that is in the class. ex: {[}abc{]}, {[}a-z{]}, {[}0-9{]}} \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}{[}\textasciicircum{}...{]}: Any character that is not in the class. ex: {[}\textasciicircum{}abc{]}, {[}\textasciicircum{}a-z{]}, {[}\textasciicircum{}0-9{]}} \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}\{s1, s2, sN\} : match s1 or s2 or sN} \tn % Row Count 10 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{control structure (if)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{if \textless{}expression\textgreater{}; then \newline {[}statements{]} \newline elif \textless{}expression\textgreater{}; then \newline {[}statements{]} \newline else \newline {[}statements{]} \newline fi} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{control structure (while)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{while \textless{}expression\textgreater{}; do \newline {[}statements{]} \newline done} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{control structure (for)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{for var in \textless{}expression\textgreater{}; do \newline echo \$var \newline {[}statements{]} \newline done} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{control structure (case)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\emph{\# patterns are file globing regex}} \newline case \textless{}expression\textgreater{} in \newline pattern1) \newline {[}statements{]} \newline ;; \newline pattern2) \newline {[}statements{]} \newline ;; \newline *) \newline {[}statements{]} \newline ;; \newline esac} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{function definition}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{function functionName \{ \newline {[}statements{]} \newline {[}return X{]} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{conditional expressions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}\&\& : logical and operator} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}|| : logical or operator\{\{bb\}\}} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}{[}{[} string {]}{]} : return 0 if string is not empty} \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}{[}{[} -z string {]}{]} : return 0 if the string is empty} \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}{[}{[} string1 == string2 {]}{]} : return 0 if the string are equivalent} \tn % Row Count 8 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}{[}{[} string1 != string2 {]}{]} : return 0 if the string are not equivalent} \tn % Row Count 10 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}{[}{[} string =\textasciitilde{} pattern {]}{]} : return 0 if the string matches the pattern (extended regex)\{\{bb\}\}} \tn % Row Count 13 (+ 3) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}{[}{[} -e file {]}{]} : return 0 if the file exists} \tn % Row Count 15 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}{[}{[} -d file {]}{]} : return 0 if file is a directory} \tn % Row Count 17 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}{[}{[} -f file {]}{]} : return 0 if file is a file} \tn % Row Count 19 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}{[}{[} -x file {]}{]} : return 0 if file is executable} \tn % Row Count 21 (+ 2) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}{[}{[} \$n1 -eq \$n2 {]}{]} : return 0 if \$n1 == \$n2} \tn % Row Count 23 (+ 2) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}{[}{[} \$n1 -lt \$n2 {]}{]} : return 0 if \$n1 \textless{} \$n2} \tn % Row Count 25 (+ 2) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}{[}{[} \$n1 -gt \$n2 {]}{]} : return 0 if \$n1 \textgreater{} \$n2} \tn % Row Count 27 (+ 2) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}{[}{[} \$n1 -ge \$n2 {]}{]} : return 0 if \$n1 \textgreater{}= \$n2} \tn % Row Count 29 (+ 2) % Row 15 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}{[}{[} \$n1 -le \$n2 {]}{]} : return 0 if \$n1 \textless{}= \$n2} \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{conditional expressions (cont)}} \tn % Row 16 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}{[}{[} \$n1 -ne \$n2 {]}{]} : return 0 if \$n1 != \$n2} \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{more basic bash commands}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}passwd : change your password} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}history : consult the history of your command} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}jobs : list of your pending proccesses} \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}cat file1 file2 ... : concatenate files and print to stdout} \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}more / less file1 file2 .. : diplsay a file page by page on stdout} \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}tail / head number : display the "number" first or last line of a file on stdout} \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}touch file1 file2 ... : change the modification date of the files} \tn % Row Count 13 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}chmod : change the privileges of a file / directory} \tn % Row Count 15 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}echo "text" : display a line of text to stdout} \tn % Row Count 17 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}sort file1 file2 ... : sort the file (combine files if many are specified) and print the result to stdout (files aren't impacted) \{\{bb\}\}} \tn % Row Count 21 (+ 4) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~~~~-r : sort in reverse order} \tn % Row Count 22 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~~~-n : numerical sort} \tn % Row Count 23 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~~~~-u : delete duplicated lines \{\{bb\}\}} \tn % Row Count 25 (+ 2) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}wc file1 file2 ... : print to stdout the number of characters, words and lines of files \{\{bb\}\}} \tn % Row Count 28 (+ 3) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~~~~-l : number of lines only} \tn % Row Count 29 (+ 1) % Row 15 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~~~-w : number of words only} \tn % Row Count 30 (+ 1) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{more basic bash commands (cont)}} \tn % Row 16 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~~~~-w : number of characters only\{\{bb\}\}} \tn % Row Count 2 (+ 2) % Row 17 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}diff file1 file1 : compare file1 and file 2 for differences \{\{bb\}\}} \tn % Row Count 4 (+ 2) % Row 18 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~~~~-i : ignore the character case} \tn % Row Count 6 (+ 2) % Row 19 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~~~-B : ignore empty lines} \tn % Row Count 7 (+ 1) % Row 20 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~~~~-w : ignore whitespaces} \tn % Row Count 8 (+ 1) % Row 21 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~~~-c : add context to the output (good for readability)\{\{bb\}\}} \tn % Row Count 10 (+ 2) % Row 22 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}which commandName : print the path of a command} \tn % Row Count 12 (+ 2) % Row 23 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}pushd / popd /path/to/dir : change directory using the directory stack} \tn % Row Count 14 (+ 2) % Row 24 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}dirs : print the directory stack} \tn % Row Count 15 (+ 1) % Row 25 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}find /path/to/dir -name pattern : find every files and directory that have a name that matches "pattern" in the directory specified and its subdirectories} \tn % Row Count 19 (+ 4) % Row 26 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}man commandName : Display the manual for command commandName} \tn % Row Count 21 (+ 2) % Row 27 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}sudo command : run the command as superuser} \tn % Row Count 23 (+ 2) % Row 28 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}command1 | xargs -i command2 : uses the output of the command1 as the input of the command2. output will be accessible via \{\} in command2} \tn % Row Count 27 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{grep (simple regex)}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}grep "pattern" file1 file2 ... : print the lines that matched the pattern \{\{bb\}\}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~~~-v : print lines that didn't match the pattern} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~~~~-i : ignore the character case} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~~~-l : print the name of the files that have at least one match} \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~~~~-o : print only the piece of line that matched the pattern} \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~~~-E : uses the extended regex} \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~~~~-q : quiet. returns 0 in \$? if at least one line has been matched. 1 if no line matched} \tn % Row Count 15 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{variables}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}VAR=VARVALUE : create a variable VAR. the variable can be accessed like so: \$VAR or \$\{VAR\}} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}VAR="\$VAR2" : \$VAR will contains the value of \$VAR2} \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}VAR='\$VAR2' : \$VAR will contains \$VAR2} \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}VAR=\$(command) : \$VAR will contains the output of the command} \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}(( VAR = \$VAR + 1 )): the double parentheses must be used when doing arithmetics} \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}\$\{VAR\#pattern\} : return a substring of VAR where the smallest string (starting from the beginning) matching "pattern" will be cut} \tn % Row Count 14 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}\$\{VAR\#\#pattern\} : return a substring of VAR where the longest string (starting from the beginning) matching "pattern" will be cut} \tn % Row Count 17 (+ 3) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}\$\{VAR\%pattern\} : return a substring of VAR where the smallest string (starting from the end) matching "pattern" will be cut} \tn % Row Count 20 (+ 3) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}\$\{VAR\%\%pattern\} : return a substring of VAR where the longest string (starting from the end) matching "pattern" will be cut} \tn % Row Count 23 (+ 3) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}\$? : the exit status of the last command / function executed. usually 0 when everything went right.} \tn % Row Count 26 (+ 3) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}\$\# : the number of args passed to the script / function} \tn % Row Count 28 (+ 2) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}\$0 : the name of the script} \tn % Row Count 29 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}\$n : the nth argument passed to the script / function} \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{variables (cont)}} \tn % Row 13 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}\$@ : the list of all the argument passde to the script / function} \tn % Row Count 2 (+ 2) % Row 14 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}Arrays\{\{bb\}\}} \tn % Row Count 3 (+ 1) % Row 15 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~~~~myArray=(value1 value2 value3): declare an array} \tn % Row Count 5 (+ 2) % Row 16 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~~~declare -a myArray=(value1 value2 value3): declare an array} \tn % Row Count 7 (+ 2) % Row 17 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~~~~\$\{myArray{[}index{]}\} : access an element (index starts at 0)} \tn % Row Count 9 (+ 2) % Row 18 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~~~myArray{[}index{]}= : add or modify the element at index} \tn % Row Count 11 (+ 2) % Row 19 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~~~~\$\{\#myArray{[}*{]}\} : return the lenght of the array} \tn % Row Count 13 (+ 2) % Row 20 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~~~\$\{myArray{[}*{]}\}: all the elements of the array} \tn % Row Count 15 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{simple regex}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}\textbackslash{} : escape character. It deletes the signification of a special character} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}. : joker. It represents any characters} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}* : 0, 1 or many repetition of the last character / sequence of character} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}\textasciicircum{} : The beginning of the line} \tn % Row Count 7 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}\$ : The end of the line} \tn % Row Count 8 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}{[}...{]} : Any character that is in the class. ex: {[}abc{]}, {[}a-z{]}, {[}0-9{]}} \tn % Row Count 10 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}{[}\textasciicircum{}...{]}: Any character that is not in the class. ex: {[}\textasciicircum{}abc{]}, {[}\textasciicircum{}a-z{]}, {[}\textasciicircum{}0-9{]}} \tn % Row Count 12 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}\textbackslash{}(...\textbackslash{}) : Capture the pattern. The pattern can then be accessed with \textbackslash{}1, \textbackslash{}2 ... \textbackslash{}n depending on the number of capture in the regex} \tn % Row Count 15 (+ 3) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}\textbackslash{}\{n\textbackslash{}\} : n repetitions of the last character / sequence of character} \tn % Row Count 17 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}\textbackslash{}\{n,\textbackslash{}\} : At least n repetitions of the last character / sequence of character} \tn % Row Count 19 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}\textbackslash{}\{n, m\textbackslash{}\} : Between n and m repetitions of the last character / sequence of character} \tn % Row Count 21 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{extended regex}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}\textbackslash{} : escape character. It deletes the signification of a special character} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}. : joker. It represents any characters} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}* : 0, 1 or many repetition of the last character / sequence of character} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}+ : 1 or more repetition of the last character / sequence of character} \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}? : The last character / sequence of character can appear or not} \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}\textasciicircum{} : The beginning of the line} \tn % Row Count 11 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}\$ : The end of the line} \tn % Row Count 12 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}{[}...{]} : Any character that is in the class. ex: {[}abc{]}, {[}a-z{]}, {[}0-9{]}} \tn % Row Count 14 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}{[}\textasciicircum{}...{]}: Any character that is not in the class. ex: {[}\textasciicircum{}abc{]}, {[}\textasciicircum{}a-z{]}, {[}\textasciicircum{}0-9{]}} \tn % Row Count 16 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}s1|s2 : Either s1 or s2 but not both} \tn % Row Count 18 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}(...) : change the priority} \tn % Row Count 19 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}\{n\} : n repetitions of the last character / sequence of character} \tn % Row Count 21 (+ 2) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}\{n,\} : At least n repetitions of the last character / sequence of character} \tn % Row Count 23 (+ 2) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}\{n, m\} : Between n and m repetitions of the last character / sequence of character} \tn % Row Count 25 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{sed (simple regex)}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}sed 'sed script' file : execute the script on every line of "file" \{\{bb\}\}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{~~~~s/pattern/newString/gI} : Substitute the piece of the line that matches "pattern" by "newString". g (optional): global, I (optional): ignore case} \tn % Row Count 6 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~~~~/pattern/d : delete the line if "pattern" is matched} \tn % Row Count 8 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~~~/pattern/p : print the line if "pattern" is matched} \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~~~~/pattern1/,/pattern2/ : print every lines between the first line that matches "pattern1" to the first line that matches "pattern2"} \tn % Row Count 14 (+ 4) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~~~-i.ext : Modifications done "in-place". A backup file will be created with .ext extension (it is optional)} \tn % Row Count 17 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~~~~-n : print only the lines that matched the pattern} \tn % Row Count 19 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{awk (extended regex)}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}awk -Fc 'awk script' file1 file2 ... (where "c" is the delimiter)} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{fa-square-o\}\}typical awk script: 'BEGIN \{statements\} /pattern/ \{script statements\} END \{statements\}'\{\{bb\}\}} \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~~~~BEGIN \{\} : Will be executed once at the start} \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~~~END \{\} : Will be executed once at the end} \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~~~~/pattern/ : only lines that matched the pattern will be processed} \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~~~/pattern1/,/pattern2/ : every line from the first line that matches pattern1 to the first line that matches pattern2 will be processed} \tn % Row Count 15 (+ 4) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~~~~\{script statements\} : core of the script} \tn % Row Count 17 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~~~~~printf: C-style formatter (man printf)} \tn % Row Count 19 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~~~~~~~~\$n : the nth field of the line} \tn % Row Count 21 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~~~~~~~\$0 : the entire line} \tn % Row Count 23 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~~~~~~~~NR : the record number} \tn % Row Count 25 (+ 2) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~~~~~~~NF : the number of fields in the record} \tn % Row Count 27 (+ 2) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{~~~~~~~~FS: The field separator (the delimiter)} \tn % Row Count 29 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}