\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{jhaley32} \pdfinfo{ /Title (linux.pdf) /Creator (Cheatography) /Author (jhaley32) /Subject (Linux 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{Linux Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{jhaley32} via \textcolor{DarkBackground}{\uline{cheatography.com/123058/cs/23103/}}} \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}jhaley32 \\ \uline{cheatography.com/jhaley32} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 4th June, 2020.\\ Updated 4th June, 2020.\\ 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}{Adding a new blk device}} \tn % Row 0 \SetRowColor{LightBackground} 1. Device discovery & follow dmesg, or fdisk -l, of lsblk. find location or new device in /dev/ \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} 2. format device to create partition & fdisk, gpart; several options. \tn % Row Count 6 (+ 2) % Row 2 \SetRowColor{LightBackground} 3. create a file system for the newly made partition & mkfs -t ext4 /dev/sda* \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} 4. create mount dir & mkdir {\emph{mount directory}} \tn % Row Count 11 (+ 2) % Row 4 \SetRowColor{LightBackground} 5. mount drive & mount /dev/sda{\emph{ }}mount directory* \tn % Row Count 13 (+ 2) % Row 5 \SetRowColor{white} 6. add entry into fstab & try using blkid to find UUID, then add device with UUID to /etf/fstab. UUID; mount point; FS type; options; backup infomation(0); FS integrity test order \tn % Row Count 21 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4177 cm} p{0.75186 cm} x{1.08602 cm} x{1.92142 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{5.377cm}}{\bf\textcolor{white}{Process Signals}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{Signal} & \seqsplit{Portable} Number & Default Action & Description \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \seqsplit{SIGHUP} & 1 & Terminate & Hangup \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{SIGINT} & 2 & Terminate & Terminal interrupt signal \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{SIGQUIT} & 3 & Terminate (core dump) & Terminal quit signal \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} \seqsplit{SIGILL} & 4 & Terminate (core dump) & Illegal instruction \tn % Row Count 13 (+ 3) % Row 5 \SetRowColor{white} \seqsplit{SIGTRAP} & 5 & Terminate (core dump) & Trace/breakpoint trap \tn % Row Count 16 (+ 3) % Row 6 \SetRowColor{LightBackground} \seqsplit{SIGABRT} & 6 & \seqsplit{Terminate(core} dump) & Process Abort Signal \tn % Row Count 18 (+ 2) % Row 7 \SetRowColor{white} \seqsplit{SIGFPE} & 8 & Terminate (core dump) & Erroneous arithmetic operation \tn % Row Count 21 (+ 3) % Row 8 \SetRowColor{LightBackground} \seqsplit{SIGKILL} & 9 & Terminate & Kill (cannot be caught or ignored) \tn % Row Count 23 (+ 2) % Row 9 \SetRowColor{white} \seqsplit{SIGSEGV} & 11 & Terminate (core dump) & Invalid memory reference \tn % Row Count 26 (+ 3) % Row 10 \SetRowColor{LightBackground} \seqsplit{SIGPIPE} & 13 & Terminate & Write on a pipe with no one to read it \tn % Row Count 29 (+ 3) % Row 11 \SetRowColor{white} \seqsplit{SIGALARM} & 14 & Terminate & Alarm Clock \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{p{0.4177 cm} p{0.75186 cm} x{1.08602 cm} x{1.92142 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{5.377cm}}{\bf\textcolor{white}{Process Signals (cont)}} \tn % Row 12 \SetRowColor{LightBackground} \seqsplit{SIGTERM} & 15 & Terminate & Termination signal \tn % Row Count 2 (+ 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}{Inode breakdown}} \tn % Row 0 \SetRowColor{LightBackground} Size of File & Size of the file \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{Device ID} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} UID & User ID \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} GID & Group ID \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} TIMESTAMPS & access, modify, change(inode) \tn % Row Count 6 (+ 2) % Row 5 \SetRowColor{white} MODE & permissions \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} 12 Direct Pointers & points to first 12 data blocks of the file \tn % Row Count 9 (+ 2) % Row 7 \SetRowColor{white} Indirect & points to a table of addresses for next blocks in a file \tn % Row Count 12 (+ 3) % Row 8 \SetRowColor{LightBackground} x2 Indirect & points to a series of tables with extrea data blocks, \tn % Row Count 14 (+ 2) % Row 9 \SetRowColor{white} x3 Indirect & same as above x3 \tn % Row Count 15 (+ 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}{systemctl}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{starting and stopping services}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`sudo systemctl start application.service`} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} `sudo systemctl start application` & systemctl looks for *.service already, not necessary to actually place in command. \tn % Row Count 7 (+ 5) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`sudo systemctl stop application.service`} \tn % Row Count 8 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{restarting and reloading}}} \tn % Row Count 9 (+ 1) % Row 5 \SetRowColor{white} `sudo systemctl restart \seqsplit{application.service`} & fully restart srevice. \tn % Row Count 12 (+ 3) % Row 6 \SetRowColor{LightBackground} `sudo systemctl reload \seqsplit{application.service`} & reload config files without restarting. \tn % Row Count 15 (+ 3) % Row 7 \SetRowColor{white} `sudo systemctl reload-or-restart \seqsplit{application.service`} & if unsure that it can reload, this will try reload first then restart. \tn % Row Count 19 (+ 4) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{Enabling and Disabling Services}}} \tn % Row Count 20 (+ 1) % Row 9 \SetRowColor{white} `sudo systemctl enable \seqsplit{application.service`} & creates a sym link from the system's copy of the service file (usually in \seqsplit{`/lib/systemd/system`} or \seqsplit{`/etc/systemd/system`)} into the location on disk where systemd looks for autostart files. \tn % Row Count 30 (+ 10) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{systemctl (cont)}} \tn % Row 10 \SetRowColor{LightBackground} `sudo systemctl disable \seqsplit{application.service`} & removes sym link \tn % Row Count 3 (+ 3) % Row 11 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{{\bf{Checking the Status of Services}}} \tn % Row Count 4 (+ 1) % Row 12 \SetRowColor{LightBackground} `systemctl status \seqsplit{application.service`} & This will provide you with the service state, the cgroup hierarchy, and the first few log lines. \tn % Row Count 9 (+ 5) % Row 13 \SetRowColor{white} `systemctl is-active \seqsplit{application.service`} & This will return the current unit state, which is usually active or inactive. exit code 0 if true \tn % Row Count 14 (+ 5) % Row 14 \SetRowColor{LightBackground} `systemctl is-enabled \seqsplit{application.service`} & This will output whether the service is enabled or disabled. Exit code 0 if true. \tn % Row Count 19 (+ 5) % Row 15 \SetRowColor{white} `systemctl is-failed \seqsplit{application.service`} & This will return active if it is running properly or failed if an error occurred. If the unit was intentionally stopped, it may return unknown or inactive. Exit code `0` if failure has occurred. \tn % Row Count 29 (+ 10) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{Listing Current Units}}} \tn % Row Count 30 (+ 1) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{systemctl (cont)}} \tn % Row 17 \SetRowColor{LightBackground} `systemctl list-units` & This will show you a list of all of the units that systemd currently has active on the system \tn % Row Count 5 (+ 5) % Row 18 \SetRowColor{white} `systemctl list-units -{}-all` & This will show any unit that systemd loaded or attempted to load, regardless of its current state on the system. \tn % Row Count 11 (+ 6) % Row 19 \SetRowColor{LightBackground} systemctl list-units -{}-all -{}-state=inactive & Another common filter is the -{}-type= filter. We can tell systemctl to only display units of the type we are interested in. \tn % Row Count 18 (+ 7) % Row 20 \SetRowColor{white} `systemctl list-unit-files` & Units are representations of resources that systemd knows about. Since systemd has not necessarily read all of the unit definitions in this view, it only presents information about the files themselves. \tn % Row Count 29 (+ 11) % Row 21 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{Displaying a Unit File}}} \tn % Row Count 30 (+ 1) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{systemctl (cont)}} \tn % Row 22 \SetRowColor{LightBackground} `systemctl cat atd.service` & The output is the unit file as known to the currently running systemd process. \tn % Row Count 4 (+ 4) % Row 23 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{{\bf{Displaying Dependencies}}} \tn % Row Count 5 (+ 1) % Row 24 \SetRowColor{LightBackground} `systemctl list-dependencies sshd.service` & This will display a hierarchy mapping the dependencies that must be dealt with in order to start the unit in question. \tn % Row Count 11 (+ 6) % Row 25 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{{\bf{Checking Unit Properties}}} \tn % Row Count 12 (+ 1) % Row 26 \SetRowColor{LightBackground} `systemctl show sshd.service` & To see the low-level properties of a unit, you can use the show command. \tn % Row Count 16 (+ 4) % Row 27 \SetRowColor{white} systemctl show sshd.service -p Conflicts & To display a single property, you can pass the -p flag with the property name. \tn % Row Count 20 (+ 4) % Row 28 \SetRowColor{LightBackground} {\bf{Masking and Unmasking Units}} & mark a unit as completely unstartable, automatically or manually, by linking it to /dev/null. \tn % Row Count 25 (+ 5) % Row 29 \SetRowColor{white} `sudo systemctl mask nginx.service` & This will prevent the Nginx service from being started, automatically or manually, for as long as it is masked. \tn % Row Count 31 (+ 6) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{systemctl (cont)}} \tn % Row 30 \SetRowColor{LightBackground} `sudo systemctl unmask nginx.service` & This will return the unit to its previous state, allowing it to be started or enabled. \tn % Row Count 5 (+ 5) % Row 31 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{{\bf{Editing Unit Files}}} \tn % Row Count 6 (+ 1) % Row 32 \SetRowColor{LightBackground} `sudo systemctl edit nginx.service` & This will be a blank file that can be used to override or add directives to the unit definition. A directory will be created within the /etc/systemd/system directory which contains the name of the unit with .d appended. For instance, for the nginx.service, a directory called nginx.service.d will be created. \tn % Row Count 22 (+ 16) % Row 33 \SetRowColor{white} `sudo systemctl edit -{}-full nginx.service` & This will load the current unit file into the editor, where it can be modified. \tn % Row Count 26 (+ 4) % Row 34 \SetRowColor{LightBackground} `sudo rm -r \seqsplit{/etc/systemd/system/nginx}.service.d` & remove snippet created \tn % Row Count 29 (+ 3) % Row 35 \SetRowColor{white} `sudo rm \seqsplit{/etc/systemd/system/nginx}.service` & To remove a full modified unit file, we would type: \tn % Row Count 32 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{systemctl (cont)}} \tn % Row 36 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{Adjusting the System State (Runlevel) with Targets}}} \tn % Row Count 2 (+ 2) % Row 37 \SetRowColor{white} `systemctl get-default` & find the default target for your system \tn % Row Count 4 (+ 2) % Row 38 \SetRowColor{LightBackground} `sudo systemctl set-default graphical.target` & If you wish to set a different default target, you can use the set-default. For instance, if you have a graphical desktop installed and you wish for the system to boot into that by default, you can change your default target accordingly: \tn % Row Count 16 (+ 12) % Row 39 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{{\bf{Listing Available Targets}}} \tn % Row Count 17 (+ 1) % Row 40 \SetRowColor{LightBackground} systemctl list-unit-files -{}-type=target & You can get a list of the available targets on your system by typing \tn % Row Count 21 (+ 4) % Row 41 \SetRowColor{white} systemctl list-units -{}-type=target & To see all of the active targets, type: \tn % Row Count 23 (+ 2) % Row 42 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{Isolating Targets}}} \tn % Row Count 24 (+ 1) % Row 43 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`systemctl list-dependencies multi-user.target`} \tn % Row Count 25 (+ 1) % Row 44 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`sudo systemctl isolate multi-user.target`} \tn % Row Count 26 (+ 1) % Row 45 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{{\bf{Using Shortcuts for Important Events}}} \tn % Row Count 27 (+ 1) % Row 46 \SetRowColor{LightBackground} `sudo systemctl rescue` & put the system into rescue (single-user) mode, you can just use the rescue command \tn % Row Count 32 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{systemctl (cont)}} \tn % Row 47 \SetRowColor{LightBackground} `sudo systemctl halt` & To halt the system, you can use the halt command: \tn % Row Count 3 (+ 3) % Row 48 \SetRowColor{white} `sudo systemctl poweroff` & To initiate a full shutdown, you can use the poweroff command: \tn % Row Count 7 (+ 4) % Row 49 \SetRowColor{LightBackground} `sudo systemctl reboot` & A restart can be started with the reboot command: \tn % Row Count 10 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}