\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{uhndreams} \pdfinfo{ /Title (bash-commands-ism-4323.pdf) /Creator (Cheatography) /Author (uhndreams) /Subject (Bash Commands - ISM 4323 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}{FCA1BC} \definecolor{LightBackground}{HTML}{FEF3F6} \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 Commands - ISM 4323 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{uhndreams} via \textcolor{DarkBackground}{\uline{cheatography.com/178879/cs/37269/}}} \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}uhndreams \\ \uline{cheatography.com/uhndreams} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 22nd February, 2023.\\ Updated 3rd May, 2023.\\ 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.44333 cm} x{3.53367 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Bash}} \tn % Row 0 \SetRowColor{LightBackground} File system Root & / - top of file hierarchy \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Path & either absolute or relative \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} pwd & present working directory \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} cd & change directory \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} \textasciitilde{} & indicates home directory \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} .. & moving up to folder above current \tn % Row Count 8 (+ 2) % Row 6 \SetRowColor{LightBackground} . & current folder \tn % Row Count 9 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{} \tn % Row Count 9 (+ 0) % Row 8 \SetRowColor{LightBackground} ls & lists all \tn % Row Count 10 (+ 1) % Row 9 \SetRowColor{white} ls -F & lists only folders \tn % Row Count 11 (+ 1) % Row 10 \SetRowColor{LightBackground} ls -l & show details \tn % Row Count 12 (+ 1) % Row 11 \SetRowColor{white} ls -a & show hidden files \tn % Row Count 13 (+ 1) % Row 12 \SetRowColor{LightBackground} ls -al & show hidden files + details \tn % Row Count 14 (+ 1) % Row 13 \SetRowColor{white} mkdir & creates folders \tn % Row Count 15 (+ 1) % Row 14 \SetRowColor{LightBackground} rmdir & removes folders \tn % Row Count 16 (+ 1) % Row 15 \SetRowColor{white} cp & copy \tn % Row Count 17 (+ 1) % Row 16 \SetRowColor{LightBackground} mv & move; can also be used to rename a file \tn % Row Count 19 (+ 2) % Row 17 \SetRowColor{white} rm & remove command \tn % Row Count 20 (+ 1) % Row 18 \SetRowColor{LightBackground} -i & adds interactivity; warning if will delete an existing file \tn % Row Count 23 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{UNIX file systems are CASE SENSITIVE \newline Folders are directories \newline {\bf{Copying and Moving Files}} \newline General syntax - {\emph{\textless{}command\textgreater{} \textless{}source\textgreater{} \textless{}target\textgreater{}}} \newline Examples - {\emph{cp hello.txt hello\_world.txt}} \newline {\bf{Notes on cp \& mv}} \newline 'cp' is only top level files, does not get what is in folders only folders on top \newline 'mv' is always recursive \newline 'cp -r' - copies a directory including all its content \newline {\bf{Invasive Commands }} \newline 'cp', 'mv', and 'rm' - no recovery possible} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.59264 cm} x{3.38436 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{{\emph{File Permissions}}}} \tn % Row 0 \SetRowColor{LightBackground} ls -al & 10 charactesr; (1)file type + (9)file permissions \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} rwx & read, write, execute \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} owner, group, world & order which permissions are displayed \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} r & 4 - indicates read permission \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} w & 2 - indicates write permission \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} x & 1 - indicates execute permission \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} r-x & read and execute (5) \tn % Row Count 12 (+ 1) % Row 7 \SetRowColor{white} 755 & rwe-er-er \tn % Row Count 13 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.04057 cm} x{2.93643 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Conditionals}} \tn % Row 0 \SetRowColor{LightBackground} IF/THEN & if {[} \textless{}condition\textgreater{} {]} then \textless{}commands\textgreater{} fi \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} fi & terminates IF/THEN \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{if\_{[}\_\textless{}equation\textgreater{}\_{]}} \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} -eq & is equal to (integer) \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} -ne & is not equal to (integer) \tn % Row Count 7 (+ 2) % Row 5 \SetRowColor{white} -gt & greater than (integer) \tn % Row Count 8 (+ 1) % Row 6 \SetRowColor{LightBackground} -lt & less than (integer) \tn % Row Count 9 (+ 1) % Row 7 \SetRowColor{white} -ge & greater than or equal to (integer) \tn % Row Count 11 (+ 2) % Row 8 \SetRowColor{LightBackground} -le & less than or equal to (integer) \tn % Row Count 13 (+ 2) % Row 9 \SetRowColor{white} = & is equal to (string) \tn % Row Count 14 (+ 1) % Row 10 \SetRowColor{LightBackground} != & is not equal to (string) \tn % Row Count 16 (+ 2) % Row 11 \SetRowColor{white} ELIF & alternative to nested-if statements \tn % Row Count 18 (+ 2) % Row 12 \SetRowColor{LightBackground} read & reads user input \tn % Row Count 19 (+ 1) % Row 13 \SetRowColor{white} bash \textless{}directory\textgreater{} \textless{}variables\textgreater{} & remember to put variables at end if variables are needed for command \tn % Row Count 22 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.89126 cm} x{3.08574 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Shell Scripting}} \tn % Row 0 \SetRowColor{LightBackground} grep \textless{}word\textgreater{} & print lines matching a pattern \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} redirect operator & (\textgreater{}) send output to file instead of displaying on screen \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} append operator & (\textgreater{}\textgreater{}) appends data instead of displaying on screen \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} cut -d" " & cut empty columns \tn % Row Count 9 (+ 1) % Row 4 \SetRowColor{LightBackground} cut -d, -f1,2,4 & cuts out only columns 1,2,4 \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} sort & sorts alphabetically \tn % Row Count 12 (+ 1) % Row 6 \SetRowColor{LightBackground} sort -n & sorts numerically \tn % Row Count 13 (+ 1) % Row 7 \SetRowColor{white} uniq & removes duplicate lines from a text file; MUST BE SORTED FORT \tn % Row Count 16 (+ 3) % Row 8 \SetRowColor{LightBackground} tr "abc" "xyz" & subsitute \textless{}v1\textgreater{} to \textless{}v2\textgreater{} \tn % Row Count 17 (+ 1) % Row 9 \SetRowColor{white} tr "{[}:lower:{]}""{[}:upper:{]}" & specify all lowercase letters to turn uppercase \tn % Row Count 19 (+ 2) % Row 10 \SetRowColor{LightBackground} new variable & supply variable name and its value; no spaces inbetween \tn % Row Count 22 (+ 3) % Row 11 \SetRowColor{white} variable1=2 & valid; no spaces between equals \tn % Row Count 24 (+ 2) % Row 12 \SetRowColor{LightBackground} \$((\textless{}equation\textgreater{})) & arithmetic expansion \tn % Row Count 25 (+ 1) % Row 13 \SetRowColor{white} echo \$\textless{}variable\textgreater{} & prints \textless{}variable value\textgreater{} \tn % Row Count 27 (+ 2) % Row 14 \SetRowColor{LightBackground} " " & does not affect use \tn % Row Count 28 (+ 1) % Row 15 \SetRowColor{white} ' ' & used literally, does not call variables \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}{Shell Scripting (cont)}} \tn % Row 16 \SetRowColor{LightBackground} \$USER & lists current user \tn % Row Count 1 (+ 1) % Row 17 \SetRowColor{white} \$PWD & prints present working directory \tn % Row Count 3 (+ 2) % Row 18 \SetRowColor{LightBackground} \$HOME & home directory of current user \tn % Row Count 5 (+ 2) % Row 19 \SetRowColor{white} \$RANDOM & o and 32767 \tn % Row Count 6 (+ 1) % Row 20 \SetRowColor{LightBackground} sleep \# & sleeps for \# seconds \tn % Row Count 7 (+ 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}{find}} \tn % Row 0 \SetRowColor{LightBackground} find & search for files \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} find {[}where to start searching from{]}{[}expression to fine{]}{[}-options{]}{[}what to find{]} & takes 2 arguements; where to search \& what to find; wildcards can be used \tn % Row Count 5 (+ 4) % Row 2 \SetRowColor{LightBackground} find /home -user alice -empty & finds files in the home folder from alice which are empty \tn % Row Count 8 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.34379 cm} x{3.63321 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Wildcards \& Examples}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{Wildcards}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} ? & matches a single character \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} * & matches any zero or more characters \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} {[}x..y{]} & matches a range of letters or numbers \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{Examples}}} \tn % Row Count 7 (+ 1) % Row 5 \SetRowColor{white} ls & lists all files + extensions \tn % Row Count 8 (+ 1) % Row 6 \SetRowColor{LightBackground} ls *.doc & lists only files with .doc extensions \tn % Row Count 10 (+ 2) % Row 7 \SetRowColor{white} re - r \textless{}target\textgreater{} & removes folders with content; be very careful \tn % Row Count 12 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.69678 cm} x{4.28022 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{While Loops}} \tn % Row 0 \SetRowColor{LightBackground} while & run until a specific conditions is met \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{CTRL+C} & to close script \tn % Row Count 4 (+ 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}{vim - file editor}} \tn % Row 0 \SetRowColor{LightBackground} vim \seqsplit{"filename"} & starts up in command mode \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} i & insert mode - start typing \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} :w & write \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} :q & quit vim type \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} :wp & save and quit \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} :q! & quit w/o saving \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} /word & search towards end of file for first occurance of word \tn % Row Count 9 (+ 2) % Row 7 \SetRowColor{white} ?word & search towards beginning of the file for the word \tn % Row Count 11 (+ 2) % Row 8 \SetRowColor{LightBackground} n & search for next occurance \tn % Row Count 12 (+ 1) % Row 9 \SetRowColor{white} N & search for previous occurance \tn % Row Count 13 (+ 1) % Row 10 \SetRowColor{LightBackground} less & view file contents one screen at a time \tn % Row Count 15 (+ 2) % Row 11 \SetRowColor{white} head & top of file to see if it is the one you need \tn % Row Count 17 (+ 2) % Row 12 \SetRowColor{LightBackground} head -3 & show the first three results \tn % Row Count 18 (+ 1) % Row 13 \SetRowColor{white} tail & bottom of file to see new log entries \tn % Row Count 20 (+ 2) % Row 14 \SetRowColor{LightBackground} -n & default output of ten line \tn % Row Count 21 (+ 1) % Row 15 \SetRowColor{white} -n\# & changes number of lines outputed \tn % Row Count 23 (+ 2) % Row 16 \SetRowColor{LightBackground} -n \& -n\# & to be used with head or tail \tn % Row Count 24 (+ 1) % Row 17 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{{\bf{YUM}}} \tn % Row Count 25 (+ 1) % Row 18 \SetRowColor{LightBackground} YUM & yellowdog updater modifier - package modifier \tn % Row Count 27 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{su changes \$ -\textgreater{} \#} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.74195 cm} x{3.23505 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{{\bf{chmod}}}} \tn % Row 0 \SetRowColor{LightBackground} chmod & updates permissions on files and folders \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} su & grants super user privileges \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} ls -laF & lists all folders + access \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} chmod 775 engineering & changes permissions for the engineering folders \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} chown & change ownership \tn % Row Count 8 (+ 1) % Row 5 \SetRowColor{white} chgrp & change group \tn % Row Count 9 (+ 1) % Row 6 \SetRowColor{LightBackground} chown dave README & changes owner of README to dave \tn % Row Count 11 (+ 2) % Row 7 \SetRowColor{white} chgrp sales\_grp README & changes the group that can access README to sales\_grp \tn % Row Count 14 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.24425 cm} x{3.73275 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Encryption}} \tn % Row 0 \SetRowColor{LightBackground} aescrypt & secret key encryption \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} -e & encrypt the file \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} -d & decrypt the file \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} -p \textless{}password\textgreater{} & password to use; if omitted, the command will prompt the user \tn % Row Count 6 (+ 3) % Row 4 \SetRowColor{LightBackground} -o \textless{}filename\textgreater{} & output file \tn % Row Count 8 (+ 2) % Row 5 \SetRowColor{white} md5sum & easy way to generate a checksum \tn % Row Count 10 (+ 2) % Row 6 \SetRowColor{LightBackground} \#! /bin/bash & turns list of commands into one command // no need for bash ... \tn % Row Count 13 (+ 3) \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}{For Loops}} \tn % Row 0 \SetRowColor{LightBackground} for var in \textless{}item/directory\textgreater{} do \textless{}commands\textgreater{} done & how to format for loops \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Sequences & \{\#..\#\} \tn % Row Count 4 (+ 1) % Row 2 \SetRowColor{LightBackground} \#..\# & first \# starting value .. second\# ending value \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} \#1..\#2..\#3 & \#3 is increment between each number series \tn % Row Count 10 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}