\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{jkeelan} \pdfinfo{ /Title (linux-tutorial.pdf) /Creator (Cheatography) /Author (jkeelan) /Subject (Linux Tutorial 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}{0066FF} \definecolor{LightBackground}{HTML}{EFF5FF} \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 Tutorial Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{jkeelan} via \textcolor{DarkBackground}{\uline{cheatography.com/55689/cs/14807/}}} \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}jkeelan \\ \uline{cheatography.com/jkeelan} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 20th February, 2018.\\ Updated 20th February, 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{2.64 cm} x{5.36 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Cluster commands}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{qstat}} & print list of all your jobs \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{qsub}} {\emph{\textless{}script\textgreater{}}} & submit {\emph{\textless{}script\textgreater{}}} as a job \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{qlogin}} & login to an interactive session on the cluster \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} {\bf{qdel}} {\emph{\textless{}job ids\textgreater{}}} & delete the jobs ({\emph{\textless{}job ids\textgreater{}}} can be a pattern) \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.36 cm} x{4.64 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Browsing files}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{cd}} {\emph{\textless{}destination\textgreater{}}} & change directory \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{ls}} {\emph{{[}pattern{]}}} & list all files or match pattern \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{pwd}} & print current directory \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{You can return to your home directory by using {\bf{cd \textasciitilde{}}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.76 cm} x{4.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Modifying files}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{rm}} {\emph{{[}pattern{]}}} & remove files (-r for recursive) \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{mv}} {\emph{{[}sources{]}}} {\emph{{[}destination{]}}} & move / rename file(s) or folder(s) \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{cp}} {\emph{{[}sources{]}}} {\emph{{[}destination{]}}} & copy file(s) (-r to create desination) \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.76 cm} x{4.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Modifying directories}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{mv}} {\emph{{[}sources{]}}} {\emph{{[}destination{]}}} & rename / move directory \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{mkdir}} {\emph{\textless{}directory\textgreater{}}} & create a directory \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{rmdir}} {\emph{\textless{}directory\textgreater{}}} & remove a directory \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} {\bf{rm -rf}} {\emph{\textless{}directory\textgreater{}}} & remove directory and all subdirectories \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.44 cm} x{4.56 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Finding files}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{find . -file -name "*.txt"}} & Find all .txt files in the current directory and below and print \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{locate}} {\emph{{[}pattern{]}}} & match files with pattern anywhere in the full path and print \tn % Row Count 6 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Can combine with {\bf{| grep}}. locate may require {\bf{sudo updatedb}} from time to time, and won't work on cluster without some modification.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.52 cm} x{4.48 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Viewing files}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{head}} {\emph{{[}filenames{]}}} & print first 10 lines of file \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{tail}} {\emph{{[}filenames{]}}} & print last 10 lines of file \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{cat}} {\emph{{[}filenames{]}}} & concatenate files and print \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.64 cm} x{5.36 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Task management}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{ps}} & See all of your active processes \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{top}} & Constantly updating list of ordered (by resources) processes \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{time}} {\emph{\textless{}command\textgreater{}}} & print time taken to complete after command finishes running \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} {\bf{kill}} {\emph{\textless{}pid\textgreater{}}} & terminate process with id {\emph{\textless{}pid\textgreater{}}} \tn % Row Count 10 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.12 cm} x{4.88 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Name Expansions}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{\{a..z\}}} or {\bf{\{1..100\}}} & expands to the series e.g a b c d ... \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{*}} & expands to match anything, any number of times \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{?}} & Match anything once \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} {\bf{\$((2 + 2))}} & Arithmetic expansion (evaluates to 2) \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{\$(}}{\emph{\textless{}command\textgreater{}{\bf{}})}} & expands to the result of the command \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} {\bf{\textasciitilde{}}} & absolute path to home directory \tn % Row Count 11 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\bf{ls *.txt}} - {\emph{list all .txt files}} \newline {\bf{cp *\{0..9\}}} - {\emph{list files which end in a number between 0 and 9}}} \tn \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}{Processing stdout}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{awk -F ","}} `'\{print \$\textless{}column number\textgreater{}\}'` & print only column n of files \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{sort}} {\emph{(-n)}} & sort alphabetically (alphanumerically) \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{uniq}} {\emph{(-c)}} & print only one instance of repeated lines (with count of lines) \tn % Row Count 9 (+ 4) % Row 3 \SetRowColor{white} {\bf{grep}} {\emph{(-i)}} {\emph{{[}pattern{]}}} & print lines which contain {\emph{pattern}} (ignore case) \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} {\bf{wc}} {\emph{-l}} & print number of lines \tn % Row Count 14 (+ 2) % Row 5 \SetRowColor{white} {\bf{sed}} /{\emph{\textless{}pattern\textgreater{}}}/{\emph{\textless{}replacement\textgreater{}}}/g & replace all instances matching {\emph{\textless{}pattern\textgreater{}}} with {\emph{\textless{}replacement\textgreater{}}} \tn % Row Count 18 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{To use on a collection of files, all commands would be prefixed by: \newline {\bf{cat}} {\emph{{[}files{]}}} {\bf{|}}} \tn \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}{Remote Managment}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{ssh}} {\emph{\textless{}username\textgreater{}}}@{\emph{\textless{}host\textgreater{}}} & login to multi-user machine \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{scp}} {\emph{\textless{}username\textgreater{}}}@{\emph{\textless{}host\textgreater{}}}:{\emph{{[}remote source{]}}} {\emph{\textless{}local\textgreater{}}} & Cope file(s) from {\emph{\textless{}host\textgreater{}}} to {\emph{\textless{}local\textgreater{}}} destination. \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{rsync -t}} {\emph{\textless{}username\textgreater{}}}@{\emph{\textless{}host\textgreater{}}}:{\emph{{[}remote source{]}}} {\emph{\textless{}local\textgreater{}}} & only copy updated files from {\emph{\textless{}host\textgreater{}}} to {\emph{\textless{}local\textgreater{}}} \tn % Row Count 9 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{For the multi-user linux machine, {\emph{\textless{}host\textgreater{}}} should be stem-ssu-linux} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.84 cm} x{4.16 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Useful}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{chmod +x}} {\emph{\textless{}file\textgreater{}}} & give executable priveleges to {\emph{\textless{}file\textgreater{}}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{seq}} {\emph{\textless{}start\textgreater{} \textless{}step\textgreater{} \textless{}stop\textgreater{}}} & print sequence of numbers from {\emph{\textless{}start\textgreater{}}} to {\emph{\textless{}stop\textgreater{}}} in increments of {\emph{\textless{}step\textgreater{}}} \tn % Row Count 6 (+ 4) % Row 2 \SetRowColor{LightBackground} {\bf{man}} {\emph{\textless{}command\textgreater{}}} & open the manual page for man \tn % Row Count 8 (+ 2) % Row 3 \SetRowColor{white} {\bf{more}} {\emph{\textless{}file\textgreater{}}} & print output in navigateable pages \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{fdisk -l}} & list all the connected drives and partitions \tn % Row Count 13 (+ 3) % Row 5 \SetRowColor{white} {\bf{mount}} {\emph{\textless{}partition\textgreater{}}} {\emph{\textless{}directory\textgreater{}}} & directory will now lead to the partiton (useful for usb storage) \tn % Row Count 17 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{stdout can be piped into {\bf{more}} to make long outputs readable.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}