\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{kesavanbr} \pdfinfo{ /Title (50-most-frequently-used-unix-linux-commands.pdf) /Creator (Cheatography) /Author (kesavanbr) /Subject (50 Most Frequently Used UNIX / Linux 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}{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{50 Most Frequently Used UNIX / Linux Commands Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{kesavanbr} via \textcolor{DarkBackground}{\uline{cheatography.com/25369/cs/7441/}}} \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}kesavanbr \\ \uline{cheatography.com/kesavanbr} \\ \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 30th 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{2.53827 cm} x{2.43873 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{1.tar command examples}} \tn % Row 0 \SetRowColor{LightBackground} Create a new tar archive. & \$ tar cvf archive\_name.tar dirname/ \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Extract from an existing tar archive. & \$ tar xvf archive\_name.tar \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} View an existing tar archive. & \$ tar tvf archive\_name.tar \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{On Unix platform, tar command is the primary archiving utility.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.94103 cm} x{3.03597 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{4.ssh command examples}} \tn % Row 0 \SetRowColor{LightBackground} Login to remote host & ssh -l jsmith remotehost.example.com \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Debug ssh client & ssh -v -l jsmith remotehost.example.com \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Display ssh client version & \$ ssh -V OpenSSH\_3.9p1, OpenSSL 0.9.7a Feb 19 2003 \tn % Row Count 7 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{ssh (SSH client) is a program for logging into a remote machine and for \newline executing commands on a remote machine} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.63781 cm} x{2.33919 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{9. sort command examples}} \tn % Row 0 \SetRowColor{LightBackground} \$ sort names.txt & Sort a file in ascending order \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \$ sort -r names.txt & Sort a file in descending order \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \$ sort -t: -k 3n /etc/passwd | more & Sort passwd file by 3rd field. \tn % Row Count 6 (+ 2) \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}{10. export command examples}} \tn % Row 0 \SetRowColor{LightBackground} \$ export | grep ORACLE & To view oracle related environment variables. \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{declare -x \seqsplit{ORACLE\_BASE="/u01/app/oracle"}} \tn % Row Count 4 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{declare -x \seqsplit{ORACLE\_HOME="/u01/app/oracle/product/10}.2.0"} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{declare -x ORACLE\_SID="med"} \tn % Row Count 7 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{declare -x ORACLE\_TERM="xterm"} \tn % Row Count 8 (+ 1) % Row 5 \SetRowColor{white} \$ export \seqsplit{ORACLE\_HOME=/u01/app/oracle/product/10}.2.0 & To export an environment variable: \tn % Row Count 11 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{14. cd command examples}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Use "cd -" to toggle between the last two directories} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{Use "shopt -s cdspell" to automatically correct mistyped directory names on cd} \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.58804 cm} x{2.38896 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{15. gzip command examples}} \tn % Row 0 \SetRowColor{LightBackground} To create a *.gz compressed file: & \$ gzip test.txt \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} To uncompress a *.gz file: & \$ gzip -d test.txt.gz \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Display compression ratio of the compressed file using gzip -l & \$ gzip -l *.gz \tn % Row Count 8 (+ 4) % Row 3 \SetRowColor{white} compressed & uncompressed ratio uncompressed\_name \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} 23709 & 97975 75.8\% asp-patch-rpms.txt \tn % Row Count 12 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.68758 cm} x{2.28942 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{2.grep command examples}} \tn % Row 0 \SetRowColor{LightBackground} Search for a given string in a file (case in-sensitive search). & \$ grep -i "the" demo\_file \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Print the matched line, along with the 3 lines after it. & \$ grep -A 3 -i "example" demo\_text \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} Search for a given string in all files recursively & \$ grep -r "ramesh" * \tn % Row Count 9 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{The grep command is used to search text or searches the given file for lines containing a match to the given strings or words. By default, grep displays the matching lines} \tn \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}{5. sed command examples}} \tn % Row 0 \SetRowColor{LightBackground} When you copy a DOS file to Unix, you could find \textbackslash{}r\textbackslash{}n in the end of each line. This example converts the DOS file format to Unix file format using sed command. & \$sed 's/.\$//' filename \tn % Row Count 8 (+ 8) % Row 1 \SetRowColor{white} Print file content in reverse order & \$ sed -n '1!G;h;\$p' thegeekstuff.txt \tn % Row Count 10 (+ 2) % Row 2 \SetRowColor{LightBackground} Add line number for all non-empty-lines in a file & \$ sed '/./=' thegeekstuff.txt | sed 'N; s/\textbackslash{}n/ /' \tn % Row Count 13 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file, or input from a pipeline).} \tn \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}{8. diff command examples}} \tn % Row 0 \SetRowColor{LightBackground} \# diff -w name\_list.txt name\_list\_new.txt & 2c2,3 \textless{} John Doe -{}-{}- \textgreater{} John M Doe \textgreater{} Jason Bourne \tn % Row Count 3 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Ignore white space while comparing.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{13. pwd command}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{pwd is Print working directory. What else can be said about the good old pwd who has been printing the current directory name for ages.} \tn % Row Count 3 (+ 3) \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}{3.find command examples}} \tn % Row 0 \SetRowColor{LightBackground} Find files using file-name ( case in-sensitve find) & \# find -iname "MyCProgram.c" \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Execute commands on files found by the find command & \$ find -iname "MyCProgram.c" -exec md5sum \{\} \textbackslash{}; \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} Find all empty files in home directory & \# find \textasciitilde{} -empty \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{The Linux find command is very powerful. It can search the entire filesystem to find files and directories according to the search criteria you specify} \tn \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}{6.awk command examples}} \tn % Row 0 \SetRowColor{LightBackground} Remove duplicate lines using awk & \$ awk '!(\$0 in array) \{ array{[}\$0{]}; print \}' temp \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Print all lines from /etc/passwd that has the same uid and gid & \$awk -F ':' '\$3==\$4' passwd.txt \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} Print only specific field from a file. & \$ awk '\{print \$2,\$5;\}' employee.txt \tn % Row Count 9 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.68758 cm} x{2.28942 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{7.vim command examples}} \tn % Row 0 \SetRowColor{LightBackground} Go to the 143rd line of file & \$ vim +143 filename.txt \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Go to the first match of the specified & \$ vim +/search-term filename.txt \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Open the file in read only mode. & \$ vim -R /etc/passwd \tn % Row Count 6 (+ 2) \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}{11. xargs command examples}} \tn % Row 0 \SetRowColor{LightBackground} Copy all images to external hard-drive & \# ls *.jpg | xargs -n1 -i cp \{\} \seqsplit{/external-hard-drive/directory} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} Search all jpg images in the system and archive it. & \# find / -name *.jpg -type f -print | xargs tar -cvzf images.tar.gz \tn % Row Count 8 (+ 4) % Row 2 \SetRowColor{LightBackground} Download all the URLs mentioned in the url-list.txt file & \# cat url-list.txt | xargs wget –c \tn % Row Count 11 (+ 3) \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}{12. ls command examples}} \tn % Row 0 \SetRowColor{LightBackground} Display filesize in human readable format (e.g. KB, MB etc.,) & \$ ls -lh -rw-r-{}-{}-{}-- 1 ramesh team-dev 8.9M Jun 12 15:27 arch-linux.txt.gz \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} Order Files Based on Last Modified Time (In Reverse Order) Using ls -ltr & \$ ls -ltr \tn % Row Count 8 (+ 4) % Row 2 \SetRowColor{LightBackground} Visual Classification of Files With Special Characters Using ls -F & \$ ls -F \tn % Row Count 12 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}