\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{rando (jalexa9)} \pdfinfo{ /Title (bash.pdf) /Creator (Cheatography) /Author (rando (jalexa9)) /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}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \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}{rando (jalexa9)} via \textcolor{DarkBackground}{\uline{cheatography.com/58013/cs/15355/}}} \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}rando (jalexa9) \\ \uline{cheatography.com/jalexa9} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 2nd April, 2018.\\ Updated 2nd April, 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*}{3} \begin{tabularx}{5.377cm}{x{1.89126 cm} x{3.08574 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Simple Bash Commands}} \tn % Row 0 \SetRowColor{LightBackground} HOME & Cursur to start of line \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} END & Cursur to end of line \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} TAB & Autocompletion \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} !! & Repeat last Bash cmd \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} cd foldername & change director to foldername \tn % Row Count 6 (+ 2) % Row 5 \SetRowColor{white} cd .. & go up one folder \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} ls & list services- shows files in current directory \tn % Row Count 9 (+ 2) % Row 7 \SetRowColor{white} man \textless{}cmd\textgreater{} & shows manual for \textless{}cmd\textgreater{} \tn % Row Count 10 (+ 1) % Row 8 \SetRowColor{LightBackground} clear & clears terminal \tn % Row Count 11 (+ 1) % Row 9 \SetRowColor{white} reset & resets terminal but doesn't restart service \tn % Row Count 13 (+ 2) % Row 10 \SetRowColor{LightBackground} CTRL-Z & Stops current running function \tn % Row Count 15 (+ 2) % Row 11 \SetRowColor{white} CTRL-J & Same as RETURN \tn % Row Count 16 (+ 1) % Row 12 \SetRowColor{LightBackground} DEL & deletes backward from pointer \tn % Row Count 18 (+ 2) % Row 13 \SetRowColor{white} exit & logs out of current session \tn % Row Count 20 (+ 2) % Row 14 \SetRowColor{LightBackground} cat 'filename' & prints file to std out on terminal \tn % Row Count 22 (+ 2) % Row 15 \SetRowColor{white} pwd & print working directory \tn % Row Count 23 (+ 1) % Row 16 \SetRowColor{LightBackground} wc 'filename' & word count of filename \tn % Row Count 24 (+ 1) % Row 17 \SetRowColor{white} echo 'string or filename' & prints string or filename on the terminal \tn % Row Count 26 (+ 2) % Row 18 \SetRowColor{LightBackground} cat \textgreater{} 'filename' & takes standard input into file \tn % Row Count 28 (+ 2) % Row 19 \SetRowColor{white} head 'filename' & prints first 10 lines of file \tn % Row Count 30 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{1.89126 cm} x{3.08574 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Simple Bash Commands (cont)}} \tn % Row 20 \SetRowColor{LightBackground} tail 'filename' & prints last 10 lines of file \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.29402 cm} x{3.68298 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Cut}} \tn % Row 0 \SetRowColor{LightBackground} cut -b & specific bytes \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} cut -b 1,2,3 & bytes 1 2 and 3 \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} cut -b 1-3,5-7 & bytes 1-3 and 5-7 \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} cut -b 1- & from first byte to end of line \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} cut -d & use a delimiter \tn % Row Count 8 (+ 1) % Row 5 \SetRowColor{white} cut -d " " & outputs from beginning of line to first space \tn % Row Count 10 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.38896 cm} x{2.58804 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Common Compilation commands}} \tn % Row 0 \SetRowColor{LightBackground} gcc 'filename.c' & C files \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} chmod +x 'filename.sh' & Bash script files \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} g++ 'filename.cpp' & CPP files \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} javac 'javafile' & JAVA \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} python 'filename' & to run python scripts \tn % Row Count 7 (+ 2) % Row 5 \SetRowColor{white} gcc -o newname 'filename.c' & change name of compiled program \tn % Row Count 9 (+ 2) % Row 6 \SetRowColor{LightBackground} g++ -o newname 'filename.cpp' & change name of compiled program \tn % Row Count 11 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.23965 cm} x{2.73735 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Grep Commands}} \tn % Row 0 \SetRowColor{LightBackground} grep 'string' \textless{}/dir/filename.log\textgreater{} & outputs all lines that match 'string' \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} grep 'string' filename1 filename2 & output all lines that match 'string' in multiple files \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} grep -i 'string' filenmae & ignores case \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} grep {[}-options{]} 'string' & grep standard output \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} grep {[}-options{]} 'string' filename & grep the contents of a file \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} grep -A n 'string' filename & displays n lines after string \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} grep -B n 'string' filename & displays n lines before string \tn % Row Count 15 (+ 2) % Row 7 \SetRowColor{white} grep -v 'string' filename & returns all lines which don't match 'string' \tn % Row Count 17 (+ 2) % Row 8 \SetRowColor{LightBackground} grep -E & allows extended regular expressions \tn % Row Count 19 (+ 2) % Row 9 \SetRowColor{white} grep -E 'string\{n\}' & get lines with n number of string in it \tn % Row Count 21 (+ 2) % Row 10 \SetRowColor{LightBackground} grep -c & count results \tn % Row Count 22 (+ 1) % Row 11 \SetRowColor{white} grep -n & show line number \tn % Row Count 23 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{3.73275 cm} x{1.24425 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Common Grep Cmds}} \tn % Row 0 \SetRowColor{LightBackground} grep -E '{[}0-9{]}\{1,3\}\textbackslash{}.{[}0-9{]}\{1,3\}\textbackslash{}.{[}0-9{]}\{1,3\}\textbackslash{}.{[}0-9{]}\{1,3\}' 'filename' & Ip address \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} grep -srhw "{[}{[}:alnum:{]}{]}\textbackslash{}+@{[}{[}:alnum:{]}{]}\textbackslash{}+" 'filename' & email address \tn % Row Count 5 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{3.73275 cm} x{1.24425 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Common Grep Cmds}} \tn % Row 0 \SetRowColor{LightBackground} grep -E '{[}0-9{]}\{1,3\}\textbackslash{}.{[}0-9{]}\{1,3\}\textbackslash{}.{[}0-9{]}\{1,3\}\textbackslash{}.{[}0-9{]}\{1,3\}' 'filename' & Ip address \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} grep -srhw "{[}{[}:alnum:{]}{]}\textbackslash{}+@{[}{[}:alnum:{]}{]}\textbackslash{}+" 'filename' & email address \tn % Row Count 5 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.54287 cm} x{3.43413 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Program/Script commands}} \tn % Row 0 \SetRowColor{LightBackground} cmdX||cmdY & run cmdX if it fails then run cmdY \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} cmdX \&\& cmdY & run cmdX if it doesn't fail run cmdY \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} cmd \& & will push cmd to background \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} cmd \& \textgreater{}/dev/null \& & will put cmd to background and not display cmd outputs \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} disown & typed after pushing cmd to background to disown cmd from current terminal \tn % Row Count 10 (+ 3) % Row 5 \SetRowColor{white} jobs & show disowned jobs \tn % Row Count 11 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{SED}} \tn % Row 0 \SetRowColor{LightBackground} sed G & double space a file \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} sed 'G;G' & triple space a file \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} sed -n '\$=' & count lines \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} sed = filename | sed 'N; s/\textasciicircum{}/ /; s/ *\textbackslash{}(.\textbackslash{}\{6,\textbackslash{}\}\textbackslash{})\textbackslash{}n/\textbackslash{}1 /' & number each line of a file \tn % Row Count 7 (+ 4) % Row 4 \SetRowColor{LightBackground} sed 's/\textasciicircum{}{[} \textbackslash{}t{]}{\emph{//;s/{[} \textbackslash{}t{]}}}\$//' & delete both leading and trailing whitespace \tn % Row Count 10 (+ 3) % Row 5 \SetRowColor{white} sed 's/{[} \textbackslash{}t{]}*\$//' & delete trailing whitespace \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} sed '/\textbackslash{}n/!G;s/\textbackslash{}(.\textbackslash{})\textbackslash{}(.*\textbackslash{}n\textbackslash{})/\&\textbackslash{}2\textbackslash{}1/;//D;s/.//' & reverse all characters on the line \tn % Row Count 15 (+ 3) % Row 7 \SetRowColor{white} sed 10q & print first 10 lines of file \tn % Row Count 17 (+ 2) % Row 8 \SetRowColor{LightBackground} sed q & print first line of file \tn % Row Count 19 (+ 2) % Row 9 \SetRowColor{white} sed -e :a -e '\$q;N;11,\$D;ba' & Last 10 lines of file \tn % Row Count 21 (+ 2) % Row 10 \SetRowColor{LightBackground} sed -n '/regexp/p' & print only line that matches regex \tn % Row Count 23 (+ 2) % Row 11 \SetRowColor{white} sed -n '8,12p' & print lines 8-12 \tn % Row Count 24 (+ 1) % Row 12 \SetRowColor{LightBackground} sed '1,10d' & delete first 10 lines of a file \tn % Row Count 26 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.39356 cm} x{3.58344 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Regular Expressions}} \tn % Row 0 \SetRowColor{LightBackground} . & Matches any single character \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \textbackslash{}d & number in 0-9 \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \textbackslash{}D & non number \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \textbackslash{}w & "word" letters, digits and \_ \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \textbackslash{}W & non word \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \textbackslash{}r & return \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \textbackslash{}n & newline \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} \textbackslash{}s & whitespace \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} \textbackslash{}S & non whitespace \tn % Row Count 9 (+ 1) % Row 9 \SetRowColor{white} 'term'* & 0 or more repetitions of term \tn % Row Count 11 (+ 2) % Row 10 \SetRowColor{LightBackground} 'term'+ & 1 or more repetitions of term \tn % Row Count 13 (+ 2) % Row 11 \SetRowColor{white} 'term'? & 0 or one instances of term \tn % Row Count 14 (+ 1) % Row 12 \SetRowColor{LightBackground} 'term'\{n\} & exactly n instances of term \tn % Row Count 15 (+ 1) % Row 13 \SetRowColor{white} 'term'\{n,\} & atleast n instances of term \tn % Row Count 16 (+ 1) % Row 14 \SetRowColor{LightBackground} 'term'\{x,n\} & between x and n instances of term \tn % Row Count 18 (+ 2) % Row 15 \SetRowColor{white} \seqsplit{(term1|term2)} & term1 or term2 \tn % Row Count 20 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.58804 cm} x{2.38896 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Common regex Cmds}} \tn % Row 0 \SetRowColor{LightBackground} {[}0-9{]} & matches any number \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} {[}a-z{]} & matches any letter \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} {[}aeiou{]} & matches vowels \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} ({[}A-Za-z0-9-{]}+) & letters numbers and hyphens \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} (\textbackslash{}d\{1,2\}\textbackslash{}/\textbackslash{}d\{1,2\}\textbackslash{}/\textbackslash{}d\{4\}) & European Date (eg. 21/3/2018 ) \tn % Row Count 7 (+ 2) % Row 5 \SetRowColor{white} (\textbackslash{}w+@{[}a-zA-Z\_{]}+?\textbackslash{}.{[}a-zA-Z{]}\{2,6\}) & email addresses \tn % Row Count 9 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{0.9954 cm} x{3.9816 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{File Redirection}} \tn % Row 0 \SetRowColor{LightBackground} \textgreater{} 'file' & create file or overwrite if existing \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \textgreater{}\textgreater{} 'file' & append to the file \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \textless{} 'file' & read from file \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} X|Y & pipe X as input to Y \tn % Row Count 6 (+ 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}{Notes}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{To use these commands just replace 'filename' or 'term' or 'cmd' with the file or regex or program that is to be used.% Row Count 3 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.38896 cm} x{2.58804 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{How to run Programs or scripts}} \tn % Row 0 \SetRowColor{LightBackground} ./a.out & for recently compiled program \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} ./'script.sh' & bash script \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} ./'compiledname' & name changed compiled program \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} 'name of installed program' & eg. gedit, nano, vim \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}