\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{adampasz (adampasz)} \pdfinfo{ /Title (shell-secrets.pdf) /Creator (Cheatography) /Author (adampasz (adampasz)) /Subject (Shell Secrets 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}{A33641} \definecolor{LightBackground}{HTML}{F9F2F3} \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{Shell Secrets Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{adampasz (adampasz)} via \textcolor{DarkBackground}{\uline{cheatography.com/20640/cs/3361/}}} \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}adampasz (adampasz) \\ \uline{cheatography.com/adampasz} \\ \uline{\seqsplit{www}.pasz.com} \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 12th May, 2016.\\ 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} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{File Management}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Bulk rename files in a folder: \newline % Row Count 1 (+ 1) `for i in FILE*; do mv \$i \$\{i/FILE1/FILE2\}; done` \newline % Row Count 2 (+ 1) Add a prefix to all files: \newline % Row Count 3 (+ 1) `for f in*;do mv "\$f""PRE\_\$f";done` \newline % Row Count 4 (+ 1) Delete everything {\emph{except}} matching file/folder \newline % Row Count 5 (+ 1) `ls | grep -v '\{file\_or\_folder\}' | xargs rm -rf`% Row Count 6 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Misc}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{IP address \newline % Row Count 1 (+ 1) `ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d\textbackslash{} -f2` \newline % Row Count 3 (+ 2) List Daemons and orphaned processes \newline % Row Count 4 (+ 1) `ps -ef | awk '\$3 == 1'`% Row Count 5 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Call Function From Shell}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\$ cat test.sh \newline testA() \{ \newline echo "TEST A \$1"; \newline \} \newline \# call arguments verbatim: \newline \$@ \newline \newline \$ bash test.sh \newline \$ bash test.sh testA \newline TEST A} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Search}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{restrict search by file type \newline % Row Count 1 (+ 1) `grep -{}-include={\emph{.js 'some string' {[}path{]}/}}` \newline % Row Count 2 (+ 1) find by filename \newline % Row Count 3 (+ 1) `find {[}path{]} -name {[}filename{]}` \newline % Row Count 4 (+ 1) restrict shell to basic letters (ASCII-7) \newline % Row Count 5 (+ 1) `export LC\_CTYPE=C \&\& export LANG=C` \newline % Row Count 6 (+ 1) find and replace string in multiple files \newline % Row Count 7 (+ 1) `grep -rl 'wl:' app | xargs sed -i ".js" -e 's/wl:/working-list:/g'` \newline % Row Count 9 (+ 2) find occurrences of 'word-' and sort them \newline % Row Count 10 (+ 1) `grep -rohw 'word{[}a-z|0-9{]}*' ./ | sort | uniq` \newline % Row Count 11 (+ 1) recursively remove file \newline % Row Count 12 (+ 1) `find . -name "*.swo" -type f -delete`% Row Count 13 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Git}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{tag a version \newline % Row Count 1 (+ 1) git tag -a v1.4 -m 'my version 1.4' \newline % Row Count 2 (+ 1) remove untracked files and directories \newline % Row Count 3 (+ 1) `git clean -f -d` \newline % Row Count 4 (+ 1) delete remote branch \newline % Row Count 5 (+ 1) `git branch -d \{the\_local\_branch\}` \newline % Row Count 6 (+ 1) `git push origin :\{the\_remote\_branch\}` \newline % Row Count 7 (+ 1) save password (OSX only) \newline % Row Count 8 (+ 1) `git config -{}-global credential.helper osxkeychain` \newline % Row Count 10 (+ 2) erase password - use Keychain Access.app or ... \newline % Row Count 11 (+ 1) git credential-osxkeychain erase \newline % Row Count 12 (+ 1) host=github.com \newline % Row Count 13 (+ 1) protocol=https \newline % Row Count 14 (+ 1) revert an individual file in working directory \newline % Row Count 15 (+ 1) `git checkout HEAD \textless{}file\textgreater{}` \newline % Row Count 16 (+ 1) in staging area \newline % Row Count 17 (+ 1) `git reset HEAD \textless{}file\textgreater{}` \newline % Row Count 18 (+ 1) reset everything \newline % Row Count 19 (+ 1) `git fetch origin` \newline % Row Count 20 (+ 1) `git reset -{}-hard origin/master` \newline % Row Count 21 (+ 1) undo last commit in working branch \newline % Row Count 22 (+ 1) `git reset -{}-soft HEAD\textasciitilde{}1` \newline % Row Count 23 (+ 1) log deletes \newline % Row Count 24 (+ 1) `git log -{}-diff-filter=D -{}-summary` \newline % Row Count 25 (+ 1) search for \textless{}string\textgreater{} in commit messages \newline % Row Count 26 (+ 1) `git log -g -{}-grep=\textless{}string\textgreater{}` \newline % Row Count 27 (+ 1) checkout a tagged version \newline % Row Count 28 (+ 1) ` git checkout tags/0.0.1` \newline % Row Count 29 (+ 1) log all branches \newline % Row Count 30 (+ 1) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Git (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`git log -{}-source -{}-all`% Row Count 1 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Heroku}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Adding to existing git project \newline % Row Count 1 (+ 1) `heroku create` \newline % Row Count 2 (+ 1) `heroku apps:rename {[}app-name{]}` \newline % Row Count 3 (+ 1) `git push heroku master` \newline % Row Count 4 (+ 1) `heroku open` \newline % Row Count 5 (+ 1) DNS \newline % Row Count 6 (+ 1) a-f.dns.zerigo.net \newline % Row Count 7 (+ 1) \seqsplit{http://stackoverflow.com/questions/17586017/where-do-i-find-nameservers-of-my-heroku-app/29320779\#29320779}% Row Count 10 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{SVN}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{add all unrevisioned files \newline % Row Count 1 (+ 1) `svn add -{}-force -{}-depth infinity \{path\}` \newline % Row Count 2 (+ 1) if you want to see what the last commit did: \newline % Row Count 3 (+ 1) `svn diff -r PREV:COMMITTED \{path\}` \newline % Row Count 4 (+ 1) last change revision \newline % Row Count 5 (+ 1) `svn info \{path\}` \newline % Row Count 6 (+ 1) Edit ignore props for current dir. \newline % Row Count 7 (+ 1) svn propedit svn:ignore . \newline % Row Count 8 (+ 1) Patching: \newline % Row Count 9 (+ 1) svn diff \textgreater{} \textasciitilde{}/fix\_ugly\_bug.diff \newline % Row Count 10 (+ 1) patch -p0 -i \textasciitilde{}/fix\_ugly\_bug.diff \newline % Row Count 11 (+ 1) revert working copy \newline % Row Count 12 (+ 1) svn revert -{}-recursive . \newline % Row Count 13 (+ 1) remove uncommited files \newline % Row Count 14 (+ 1) `svn st | grep '\textasciicircum{}?' | awk '\{print \$2\}' | xargs rm -rf` \newline % Row Count 16 (+ 2) create diffs for 224453 and 224462 (e.g. by svn diff -r 224452:224453 \textgreater{} diff1.patch). \newline % Row Count 18 (+ 2) check out 224446 (svn up -r224446) \newline % Row Count 19 (+ 1) apply the diffs (e.g. patch -p0 -i diff1.patch) \newline % Row Count 21 (+ 2) create a diff of that against 224445 (svn diff -r 224445 \textgreater{} diff2.patch)% Row Count 23 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}