\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{jcroughton} \pdfinfo{ /Title (linux-cli-commands.pdf) /Creator (Cheatography) /Author (jcroughton) /Subject (Linux CLI commands 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}{75A39E} \definecolor{LightBackground}{HTML}{F6F9F8} \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 CLI commands Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{jcroughton} via \textcolor{DarkBackground}{\uline{cheatography.com/86366/cs/20089/}}} \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}jcroughton \\ \uline{cheatography.com/jcroughton} \\ \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 10th December, 2019.\\ 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.56 cm} x{5.44 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{General}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{lsb\_release} -a & Linux version \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} alias & Show aliases attached to shell \tn % Row Count 4 (+ 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}{Locations}} \tn % Row 0 \SetRowColor{LightBackground} /var/www & Server www sites / pointers to \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} /var/log & System / auth / php etc. logs \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{/var/log/nginx/} & NGINX access / error logs \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \textasciitilde{}/.ssh & SSH config \tn % Row Count 7 (+ 1) % Row 4 \SetRowColor{LightBackground} /etc/php & PHP version installed \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4.48 cm} x{3.52 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Files}} \tn % Row 0 \SetRowColor{LightBackground} echo "xyz" \textgreater{} /somewhere/file.log & Write xyz to given file \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} touch myfile.txt & Create a file \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} nano myfile.txt & Edit myfile.txt with Nano \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} rm -rf /node\_modules & Remove node\_modules recursively \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} grep -r 'string to search' directory/to/search & Search for string in files \tn % Row Count 10 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.6 cm} x{4.4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{File system}} \tn % Row 0 \SetRowColor{LightBackground} ls -al -S & Directory list in file size order \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} ls -alt & directory list in time order \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} lsblk & Display volumes / partitions \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} df -i & inode usage \tn % Row Count 7 (+ 1) % Row 4 \SetRowColor{LightBackground} df -hT & File system memory usage \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} find / -size +20M & Find large files \tn % Row Count 10 (+ 1) % Row 6 \SetRowColor{LightBackground} find / -type d -name 'httpdocs' & Find folder \tn % Row Count 12 (+ 2) % Row 7 \SetRowColor{white} find / -name 'filename.html' & Find file \tn % Row Count 14 (+ 2) % Row 8 \SetRowColor{LightBackground} file -s /dev/xvd* & File system / partition types \tn % Row Count 16 (+ 2) % Row 9 \SetRowColor{white} growpart /dev/xvda 1 & Grow partition to newly added space \tn % Row Count 18 (+ 2) % Row 10 \SetRowColor{LightBackground} resize2fs /dev/xvda1 & Resize partition to new allocated size \tn % Row Count 20 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Permissions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{`chown -R root:www /var/www`} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Change ownership of /var/www to root user:www group} \tn % Row Count 3 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.68 cm} x{4.32 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Networking}} \tn % Row 0 \SetRowColor{LightBackground} ping -c 4 8.8.8.8 & Ping (Google) 4 times \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} ip addr & Network interfaces enabled? \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} sudo nano \seqsplit{/etc/network/interfaces} & Network config \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} route -n & Show kernal IP routing table \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} sudo ifdown -{}-force eth0 & Network interface off (force optional) \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} sudo ifup -{}-force eth0 & Network interface on (force optional) \tn % Row Count 11 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\seqsplit{https://upcloud.com/community/tutorials/troubleshoot-network-connectivity-linux-server/}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.16 cm} x{5.84 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{PHP}} \tn % Row 0 \SetRowColor{LightBackground} php -m & List installed modules / extensions \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} php -{}-version & PHP version on CLI \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.08 cm} x{5.92 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Weblish}} \tn % Row 0 \SetRowColor{LightBackground} CTRL A, Esc & Enter scroll mode (Esc to exit) \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.2 cm} x{4.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{User}} \tn % Row 0 \SetRowColor{LightBackground} whoami & Output current user context to CLI \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} groups & Show which groups user belongs to \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} adduser ubuntu www-data & Add user ubuntu to group www-data \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}{GIT}} \tn % Row 0 \SetRowColor{LightBackground} git remote -{}-verbose & Show remotes for currently checked out repo \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} git branch & List local branches \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Services}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{`sudo service /etc/init.d/mysqld restart`} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Restart service (full path)} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{`sudo service nginx restart`} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Restart service (short)} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{`sudo service -{}-status-all`} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Service status + running / - stopped / ? services without status command} \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{`sudo netstat -tulpn`} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Display port attachments} \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{`sudo fuser -k 80/tcp`} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Kill everything on given port (i.e. release 80 for NGINX restart)} \tn % Row Count 12 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.52 cm} x{6.48 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Process and jobs}} \tn % Row 0 \SetRowColor{LightBackground} jobs & List of background jobs \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} jobs -l & List with PID \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} fg & Bring most recent to front \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} fg \%2 & Switch to specific job in list \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{If you ctrl-z out of a command line program, such as man, it may leave a running process in the background \newline \newline \newline {[}3{]}+ Stopped man \newline \newline \newline 3 = Number of stopped jobs in background \newline man = program that was stopped \newline \newline \newline Find and kill it} \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}{Package management}} \tn % Row 0 \SetRowColor{LightBackground} sudo apt-get autoremove & Delete unused packages \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} sudo apt-get purge php7.* & Remove package \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} apt list —installed | grep your-package-name & List installed packages \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} apt-get install your-package-name & Install package \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} apt-get update & Update packages info about package from repo \tn % Row Count 12 (+ 3) % Row 5 \SetRowColor{white} apt-get upgrade & Update all packages \tn % Row Count 13 (+ 1) % Row 6 \SetRowColor{LightBackground} apt-get install -{}-only-upgrade \textless{}packagename\textgreater{} \textless{}anotherpackagename\textgreater{} & Update specific package \tn % Row Count 17 (+ 4) % Row 7 \SetRowColor{white} add apt-repository \seqsplit{name-of-your-repo-here} & Add apt repo \tn % Row Count 20 (+ 3) % Row 8 \SetRowColor{LightBackground} apt-cache search package-name-here & Search for packages \tn % Row Count 22 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{apt-get = older version of apt} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{MYSQL}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{`apt-get install mysql-server`} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Install mysql} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{\seqsplit{`mysql\_secure\_installation`}} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Secure installation} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{`mysql -u your-username -p`} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Connect on CLI} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{`CREATE DATABASE \seqsplit{database\_name\_cant\_use\_hyphens\_use\_underscores} CHARACTER SET utf8mb4 COLLATE utf8mb4\_unicode\_ci;`} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Create DB} \tn % Row Count 10 (+ 4) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{`SHOW TABLE STATUS;`} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Show collation of tables} \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{`ALTER TABLE \textless{}some\_table\textgreater{} convert to CHARACTER SET utf8mb4 COLLATE utf8mb4\_unicode\_ci;`} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Alter table collation} \tn % Row Count 15 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{`CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'a\_password\_here';`} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Create user} \tn % Row Count 18 (+ 3) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{`GRANT ALL PRIVILEGES ON db\_name\_here . * TO 'newuser'@'localhost';`} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Grant priviledges} \tn % Row Count 21 (+ 3) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{`FLUSH PRIVILEGES;`} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Reload priviledges} \tn % Row Count 23 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Follow \seqsplit{https://stackoverflow.com/a/42742610} Option 1 during \seqsplit{mysql\_secure\_installation} if required} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}