\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{hamza391} \pdfinfo{ /Title (linux-terminal-cheat-sheet.pdf) /Creator (Cheatography) /Author (hamza391) /Subject (Linux Terminal 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}{CF021D} \definecolor{LightBackground}{HTML}{FCEFF0} \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 Terminal Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{hamza391} via \textcolor{DarkBackground}{\uline{cheatography.com/52792/cs/14298/}}} \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}hamza391 \\ \uline{cheatography.com/hamza391} \\ \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 13th January, 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{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Rebooting and Shutting Down}} \tn % Row 0 \SetRowColor{LightBackground} shutdown at 10:00 & \$ sudo shutdown -h 10:00 \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} shutdown now & \$ sudo shutdown -h now \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} restart at 10:00 & \$ sudo shutdown -r 10:00 \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} restart now & \$ sudo shutdown -r now \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} with message "Shutting down for scheduled maintenance. & \$ sudo shutdown -h 10:00 "Shutting down for scheduled maintenance." \tn % Row Count 12 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.88666 cm} x{2.09034 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Locate application}} \tn % Row 0 \SetRowColor{LightBackground} locate application only & which "application name" \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} locates application , source and man & whereis "application name" \tn % Row Count 4 (+ 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}{Locate / Find}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{The locate utility program performs a search through a previously constructed database of files and directories on your system, matching all entries that contain a specified character string \newline % Row Count 4 (+ 4) updatedb to update the database \newline % Row Count 5 (+ 1) can use grep program as a filter; grep will print only the lines that contain one or more specified strings \newline % Row Count 8 (+ 3) \$ locate zip | grep bin% Row Count 9 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.88666 cm} x{2.09034 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Finding Files}} \tn % Row 0 \SetRowColor{LightBackground} Searching for files and directories named "gcc" & find /usr -name gcc \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Searching only for directories named "gcc": & find /usr -type d -name gcc \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} Searching only for regular files named "gcc" & \$ find /usr -type f -name gcc \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} *To find files based on time created "+\_ n" days & find / -ctime n \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} To find files based on size +- n & \$ find / -size n \tn % Row Count 12 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Another good use of find is being able to run commands on the files that match your search criteria. The -exec option is used for this purpose. \newline To find and remove all files that end with .swp: \newline \newline \$ find -name "{\emph{.swp" -exec rm \{\} ';' \newline }}mtime for modified/written time \newline atime for access time/read time} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{3.93183 cm} x{1.04517 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Accessing Directories}} \tn % Row 0 \SetRowColor{LightBackground} Displays the present working directory & pwd \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Change to your home directory & cd \textasciitilde{} or cd \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Change to parent directory & cd .. \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} Change to previous directory & cd - \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{4.23045 cm} p{0.74655 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Exploring the FileSystem}} \tn % Row 0 \SetRowColor{LightBackground} Changes your current directory to the root (/) directory (or path you supply) & cd / \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} List the contents of the present working directory & ls \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} List all files including hidden files and directories (those whose name start with . ) & ls –a \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} Displays a tree view of the filesystem & tree \tn % Row Count 10 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{3.38436 cm} x{1.59264 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Directories}} \tn % Row 0 \SetRowColor{LightBackground} to create a directory. & mkdir \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} create a sample directory named sampdir under the current directory, & mkdir sampdir \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} create a sample directory called sampdir under /usr & mkdir \seqsplit{/usr/sampdir}. \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} Removing a directory * & rmdir \tn % Row Count 7 (+ 1) % Row 4 \SetRowColor{LightBackground} To remove a directory and all of its contents & rm -rf \tn % Row Count 9 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\emph{ for rmdir The directory must be empty or it will fail \newline }} usage sample for rmdir and rm -rf is same as mkdir} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{4.32999 cm} p{0.64701 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Renaming / removing directory}} \tn % Row 0 \SetRowColor{LightBackground} Rename a directory & mv \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Remove an empty directory & rmdir \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} Forcefully remove a directory recursively & rm -rf \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.78712 cm} x{2.18988 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Basic Packagaing Commands}} \tn % Row 0 \SetRowColor{LightBackground} Install package & dpkg -{}-install foo.deb \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Install package, dependencies & apt-get install foo \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Remove package & dpkg -{}-remove foo.deb \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} Remove package, dependencies & apt-get autoremove foo \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} Update package & dpkg -{}-install foo.deb \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} Update package, dependencies & apt-get install foo \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} Update entire system & apt-get dist-upgrade \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} Show all installed packages & dpkg -{}-list \tn % Row Count 16 (+ 2) % Row 8 \SetRowColor{LightBackground} Get information on package & dpkg -{}-listfiles foo \tn % Row Count 18 (+ 2) % Row 9 \SetRowColor{white} Show packages named foo & apt-cache search foo \tn % Row Count 20 (+ 2) % Row 10 \SetRowColor{LightBackground} Show all available packages & apt-cache dumpavail foo \tn % Row Count 22 (+ 2) % Row 11 \SetRowColor{white} What package is file part of? & dpkg -{}-search file \tn % Row Count 24 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.53827 cm} x{2.43873 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Viewing Files}} \tn % Row 0 \SetRowColor{LightBackground} for viewing files that are not very long; it does not provide any scroll-back. & cat \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} o look at a file backwards, starting with the last line & tac \tn % Row Count 7 (+ 3) % Row 2 \SetRowColor{LightBackground} Used to view larger files & less (/ for forwad and ? for backward) \tn % Row Count 9 (+ 2) % Row 3 \SetRowColor{white} Used to print the last 10 lines & tail \tn % Row Count 11 (+ 2) % Row 4 \SetRowColor{LightBackground} Used to print the first 10 lines & head \tn % Row Count 13 (+ 2) % Row 5 \SetRowColor{white} Used to print the last X lines & tail -n X or tail -X \tn % Row Count 15 (+ 2) % Row 6 \SetRowColor{LightBackground} Used to print the first X lines & head -n X or head -X \tn % Row Count 17 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.73735 cm} x{2.23965 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{File Linking}} \tn % Row 0 \SetRowColor{LightBackground} Hardlink file1 and file2 & \$ ln file1 file2 \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Softlink file1 and file2 & \$ ln -s file1 file2 \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{3.03597 cm} x{1.94103 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{New file / change time of file}} \tn % Row 0 \SetRowColor{LightBackground} Create newfile & \$ touch "filename" \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} sets the "myfile" file's time stamp to 4 p.m., March 20th (03 20 1600). & \$ touch -t 03201600 myfile \tn % Row Count 5 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{3.93183 cm} x{1.04517 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Removing/Renaming file}} \tn % Row 0 \SetRowColor{LightBackground} Rename a file & mv \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Remove a file & rm \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} Forcefully remove a file & rm –f \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} Interactively remove a file & rm –i \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}