\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{edgarchavc} \pdfinfo{ /Title (bashcheatsheet.pdf) /Creator (Cheatography) /Author (edgarchavc) /Subject (BashCheatSheet 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}{95A382} \definecolor{LightBackground}{HTML}{F8F9F7} \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{BashCheatSheet Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{edgarchavc} via \textcolor{DarkBackground}{\uline{cheatography.com/122036/cs/22640/}}} \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}edgarchavc \\ \uline{cheatography.com/edgarchavc} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 5th May, 2020.\\ Updated 5th May, 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{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Comandos Bash}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{COMANDOS BASICOS}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{mkdir \textless{}nuevo folder\textgreater{} / mkdir \textless{}folder1/folder2/.../nuevo folder\textgreater{} }} {\emph{crear folder en la ruta actual / crear folder en la ruta especificada}}} \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{cd \textless{}folder1/folder2/.../folder destino\textgreater{} }} {\emph{cambiar de ubicación}}} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{cd .. }} {\emph{subir un nivel referente a la ubicación actual}}} \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{cd \textasciitilde{} }} {\emph{regresar a la ruta "home"}}} \tn % Row Count 9 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{cp \textless{}archivo\textgreater{} \textless{}archivo nuevo\textgreater{} }} {\emph{copiar un archivo a archivo nuevo dentro de una ruta especificada, o no (en caso se quiera hacer en la misma ruta)}}} \tn % Row Count 13 (+ 4) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{mv \textless{}archivo \textless{}archivo nuevo\textgreater{} }} {\emph{ mover un archivo a archivo nuevo dentro de una ruta especificada, o no (en caso se quiera hacer en la misma ruta). Es similar al cp pero cuando se hace mv el archivo original no se mantiene}}} \tn % Row Count 18 (+ 5) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{rm \textless{}ruta/archivo\textgreater{}}} {\emph{elimina un folder especificado en una ruta o un archivo}}} \tn % Row Count 20 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{history}} {\emph{lista los comandos utilizados durante la sesión}}} \tn % Row Count 22 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{cat \textless{}archivo\textgreater{}}} {\emph{muestra el contenido del archivo}}} \tn % Row Count 24 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{head -n \textless{}archivo\textgreater{}}} {\emph{muestra las primeras n filas de un archivo especifico}}} \tn % Row Count 26 (+ 2) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{tail -n \textless{}archivo\textgreater{}}} {\emph{muestra las ultimas n filas de un archivo especifico. Se pueden usar ambos comandos (head/tail) para combinar su efecto. Por ejemplo, head -n1 \textless{}archivo | tail -n2 devuelve las ultimas n2 filas de las primeras n1 filas de un archivo}}} \tn % Row Count 32 (+ 6) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Comandos Bash (cont)}} \tn % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{ls \textless{}ruta\textgreater{}}} {\emph{devuelve el listado de elementos de la ruta especificada. Si no se especifica, devuelve el listado de la ruta actual}}} \tn % Row Count 3 (+ 3) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{man \textless{}comando\textgreater{}}} {\emph{muestra el manual de uso del comando especificado}}} \tn % Row Count 5 (+ 2) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{grep \textless{}valor buscado\textgreater{} \textless{}archivo\textgreater{}}} {\emph{selecciona las lineas de un archivo que tengan el valor buscado. Se pueden emplear las siguientes opciones:-v: invierte la búsqueda mostrando las lineas que no son iguales al valor. -c: muestra la cantidad de lineas que cumplen con la busqueda -n: muestra los números de línea que cumplen con la búsqueda -h: no imprime los nombres de los archivos cuando se buscan múltiples archivos -l: imprime los nombres de los archivos que contienen la búsqueda -i: para tratar las mayúsculas y minúsculas como iguales (Algebra=algebra)}}} \tn % Row Count 17 (+ 12) % Row 15 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{\textless{}linea de comando\textgreater{} \textgreater{} \textless{}archivo\textgreater{}}} {\emph{el comando "\textgreater{}" guarda el resultado de la ejecución de un comando a un archivo}}} \tn % Row Count 20 (+ 3) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Comodines: * , ? }} * *: reemplaza todos los caracteres. Si coloca antes de una cadena reemplaza todos los caracteres desde el inicio has} \tn % Row Count 23 (+ 3) % Row 17 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{} \tn % Row Count 23 (+ 0) % Row 18 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{COMANDOS SHELL}}} \tn % Row Count 24 (+ 1) % Row 19 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{echo \textless{}\$variable/"cadena"\textgreater{}}} {\emph{imprime en pantalla el valor de la variable o candena que se coloca}}} \tn % Row Count 26 (+ 2) % Row 20 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{\#\textless{}cadena\textgreater{}}} {\emph{se utiliza \# para colocar un comentario dentro de una shell. Al momento de la ejecución lo que este a la derecha de este caracter se ignorará}}} \tn % Row Count 30 (+ 4) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Comandos Bash (cont)}} \tn % Row 21 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{ejemplos de bucle (for, while)}}\{\{nl\}\}{\emph{for anio in 2018 2017 2016;\{\{nl\}\}~~~~do echo \$anio;\{\{nl\}\}done\{\{nl\}\}\{\{nl\}\}for ((x=2;x\textless{}=12;x+=3))\{\{nl\}\}~~~~do echo \$x\{\{nl\}\}done\{\{nl\}\}\{\{nl\}\} x=1\{\{nl\}\}while {[} \$x -le 12 {]};\{\{nl\}\}do \{\{nl\}\}echo \$x\{\{nl\}\}((x+=3))\{\{nl\}\}done\{\{nl\}\}\{\{nl\}\}\#usando wildcards:\{\{nl\}\}\{\{nl\}\}for archivo in \$files\_ventas;\{\{nl\}\}do echo \$archivo;\{\{nl\}\}done}}} \tn % Row Count 8 (+ 8) % Row 22 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{bloques if:}} {\emph{\{\{nl\}\}if {[}\textless{}validacion1\textgreater{}{]} then \{\{nl\}\}\textless{}bloque if 1\textgreater{} \{\{nl\}\}elif (( validacion2 )) then \#se pueden usar {[}{]} o (())\{\{nl\}\}\textless{}bloque if 2\textgreater{}\{\{nl\}\}else\{\{nl\}\}\textless{}bloque else\textgreater{}\{\{nl\}\}fi\{\{nl\}\}fi}}} \tn % Row Count 12 (+ 4) % Row 23 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{división de decimales: echo \$(echo "15/3600" | bc -l )}} {\emph{para realizar operaciones decimales se debe usar el comando "bc". Antes de ello, se debe instalar la librería necesaria con la siguiente linea: sudo apt-get install bc}}} \tn % Row Count 17 (+ 5) % Row 24 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{\$1 \$2 .. \$n}} {\emph{para capturar variables externas en nuestra shell, se usan "\$n" donde n es un numero entero desde 1 sucesivamente hasta n valores necesarios para nuestra lógica.}}} \tn % Row Count 21 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \end{document}