\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{michel.syska} \pdfinfo{ /Title (terminal-unix-et-ligne-de-commande.pdf) /Creator (Cheatography) /Author (michel.syska) /Subject (Terminal Unix et Ligne de Commande 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{Terminal Unix et Ligne de Commande Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{michel.syska} via \textcolor{DarkBackground}{\uline{cheatography.com/24922/cs/6350/}}} \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}michel.syska \\ \uline{cheatography.com/michel-syska} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 10th December, 2015.\\ Updated 5th November, 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*}{2} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Cheat Sheet indispensable en DUT INFO S3}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\emph{feuille publiée par erreur mais en cours d'amélioration :-)}}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Pour qui ?}}} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}les DUT INFO S3 de Nice - Fabron} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Dans quel module ?}}} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}M311 / principes des systèmes d'exploitations} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Pourquoi ?}}} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}être dix fois plus efficace en TP} \tn % Row Count 8 (+ 2) \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}{Ouvrir un terminal GNOME}} \tn % Row 0 \SetRowColor{LightBackground} Depuis le bureau GNOME & Cliquer en haut à gauche sur "Activités" puis \{\{fa-search\}\} Rechercher "terminal" dans la zone de recherche en haut du bureau. En profiter pour placer l'icône dans la barre "Activités" \tn % Row Count 10 (+ 10) % Row 1 \SetRowColor{white} Depuis un terminal GNOME & Menu "Fichier" puis "Ouvrir un terminal" \tn % Row Count 12 (+ 2) % Row 2 \SetRowColor{LightBackground} \{\{nobreak\}\}Depuis l'explorateur\{\{nl\}\}de fichiers & Clic droit dans le fond de la fenêtre et "Ouvrir dans un terminal" \tn % Row Count 16 (+ 4) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{Le clic droit dans l'explorateur permet d'ouvrir le terminal dans le bon répertoire} \tn % Row Count 18 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Ne pas hésiter à ouvrir plusieurs terminaux côte à côte pour tester les programmes multi processus et contrôler leur exécution depuis un autre terminal (avec `kill`, `ps`, `top`, `htop`, ..)} \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}{Taper des commandes dans le terminal}} \tn % Row 0 \SetRowColor{LightBackground} Copier / Coller & surligner le texte choisi à la souris puis clic gauche dans le terminal et clic milieu pour coller \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} Complétion & `tab` et/ou `tab tab` pour faire défiler les possibilités en boucle puis taper un ou plusieurs caractères pour choisir \tn % Row Count 12 (+ 7) % Row 2 \SetRowColor{LightBackground} Historique bash & taper la commande `history` \tn % Row Count 14 (+ 2) % Row 3 \SetRowColor{white} Commandes précédentes & \{\{fa-arrow-up\}\} ou `ctrl-p` \tn % Row Count 16 (+ 2) % Row 4 \SetRowColor{LightBackground} Commandes suivantes & \{\{fa-arrow-down\}\} ou `ctrl-n` \tn % Row Count 18 (+ 2) % Row 5 \SetRowColor{white} Début de ligne & `ctrl-home` ou `ctrl-a` \tn % Row Count 20 (+ 2) % Row 6 \SetRowColor{LightBackground} Fin de ligne & `ctrl-end` ou `ctrl-e` \tn % Row Count 22 (+ 2) % Row 7 \SetRowColor{white} Abandonner & `ctrl-c` \tn % Row Count 23 (+ 1) % Row 8 \SetRowColor{LightBackground} Rechercher la dernière commande contenant `mot` & `ctrl-r mot` puis `ctrl-r` autant de fois que nécessaire pour retrouver toutes les commandes contenant `mot` \tn % Row Count 29 (+ 6) % Row 9 \SetRowColor{white} Couper jusqu'à la fin de ligne & `ctrl-k` \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Taper des commandes dans le terminal (cont)}} \tn % Row 10 \SetRowColor{LightBackground} Coller le texte coupé & `ctrl-y` \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Pour les autres raccourcis, voir la documentation du mode emacs} \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}{Voir ses fichier Windows depuis Linux}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Dans l'explorateur de fichier, taper dans la barre du haut - location - (ou `ctrl-l`) et entrer la connexion \newline % Row Count 3 (+ 3) \seqsplit{`smb://dc-info-03/users/etudiant/login`} \newline % Row Count 4 (+ 1) domaine : `IUTNICE` \newline % Row Count 5 (+ 1) password : celui utilisé sous Windows \newline % Row Count 6 (+ 1) Les supports de cours des autres modules sont sur le partage : \newline % Row Count 8 (+ 2) \seqsplit{`smb://fs-info-01/SupportCours/S3T`}% Row Count 9 (+ 1) } \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}{Commandes bash de base}} \tn % Row 0 \SetRowColor{LightBackground} Afficher le contenu du répertoire `dir` & `ls -la dir` \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Se positionner à la racine de son espace personnel & `cd` ou `cd \textasciitilde{}` ou `cd \$HOME` \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{`\$HOME` et `\textasciitilde{}` désignent le même chemin, le répertoire défini comme racine du login correspondant, par exemple `/home/martin`} \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} Effacer le répertoire `dir` et ses sous-répertoires & `rm -rf dir` \tn % Row Count 11 (+ 3) % Row 4 \SetRowColor{LightBackground} Renommer `dir1` sous le nom de `dir2` & `mv dir1 dir2` \tn % Row Count 13 (+ 2) % Row 5 \SetRowColor{white} Effacer le terminal & `clear` \tn % Row Count 14 (+ 1) % Row 6 \SetRowColor{LightBackground} Ajouter `\$HOME/bin` au `PATH` & \{\{nobreak\}\}`export \seqsplit{PATH=\$PATH:\$HOME/bin`} \tn % Row Count 16 (+ 2) % Row 7 \SetRowColor{white} Changer l'invite de commande & `export PS1='\$ '` \tn % Row Count 18 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Les variables d'environnement comme `PS1`, `PATH`, ... sont à changer de préférence dans les fichiers de configuration de bash : `.bash\_login`, `.bash\_profile`, `.bashrc`, ...} \tn % Row Count 22 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{5.04 cm} x{2.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Gestion zéro des archives tar.gz}} \tn % Row 0 \SetRowColor{LightBackground} Extraire le contenu de `tp.tar.gz` & `tar zxvf tp.tar.gz` \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Créer une archive contenant le répertoire `tp` & `tar zcvf tp.tar.gz tp` \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Pour créer l'archive contenant tous les fichiers du répertoire `tp`, il faut se positionner avant au dessus de `tp`. Par exemple, si le chemin absolu de `tp` est `/home/login/ASR/tp`, alors les commandes sont: \newline `cd /home/login/ASR` \newline `tar zcvf tp.tar.gz tp`} \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}{Commandes de contrôle des processus}} \tn % Row 0 \SetRowColor{LightBackground} `ps axu` ou bien `ps -eF` & voir tous les processus en cours \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} `ps axjf` ou bien `ps -ejH` & voir aussi les arbres de filiation \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} `pstree` & affiche un arbre de tous les processus en cours \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} `ps -elfT` ou bien `ps axms` & avoir en plus les informations sur les threads \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} `top` ou bien `top U login` & affichage dynamique, `top -H` pour voir les threads \tn % Row Count 13 (+ 3) % Row 5 \SetRowColor{white} \{\{nobreak\}\} `htop` ou bien `htop -u login` & taper `H` pour voir les threads, `t` pour les arbres, `F4` pour filtrer un nom \tn % Row Count 17 (+ 4) % Row 6 \SetRowColor{LightBackground} `kill -SIGINT pid` & interrompre le processus numéro `pid` \tn % Row Count 19 (+ 2) % Row 7 \SetRowColor{white} `kill -SIGKILL pid` & tuer le processus numéro `pid` qui résiste à `SIGINT` \tn % Row Count 22 (+ 3) % Row 8 \SetRowColor{LightBackground} `killall -INT prog` & interrompre tous les exemplaires de processus de nom `prog` \tn % Row Count 25 (+ 3) % Row 9 \SetRowColor{white} `killall -KILL prog` & tuer tous les exemplaires des processus de nom `prog` \tn % Row Count 28 (+ 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}{Éditer, compiler et exécuter des programmes C}} \tn % Row 0 \SetRowColor{LightBackground} Éditer avec & nano, gedit, notepad++, emacs, vim \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\} ou un autre éditeur à partir du moment que le codage est UTF-8} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Compiler & `gcc -Wall -std=gnu99 prog.c -o prog` \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} Compiler avec un Makefile & `make` \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} Nettoyer le répertoire courant & `make mrproper` ou `make clean` \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} Exécuter `prog` & `./prog` \tn % Row Count 11 (+ 1) % Row 6 \SetRowColor{LightBackground} Interrompre le processus prog & `ctrl-c` ou `ctrl-\textbackslash{} ` \tn % Row Count 13 (+ 2) % Row 7 \SetRowColor{white} Formater un source C & `indent -linux prog.c` \tn % Row Count 15 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Réutiliser systèmatiquement les exemples de Makefile et de sources C donnés avec le sujet de TD} \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}{Exemple}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{8.4cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/michel-syska_1449706555_cheatsheet.PNG}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{sur cet exemple (PuTTY) on montre comment \newline 1 - changer l'invite de commande \newline 2 - se positionner dans un répertoire depuis son \$HOME (ou \textasciitilde{}) \newline 3 - effacer les exécutables avec la règle mrproper du Makefile pour \newline 4 - tout recompiler et \newline 5 - exécuter le programme somme} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4.24 cm} x{3.76 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Erreur de compilation bizzare}} \tn % Row 0 \SetRowColor{LightBackground} error stray '\textbackslash{}204' in program … & effacer puis retaper le texte \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Erreur souvent due à un copier/coller du web vers gedit : il faut télécharger les sources, pas faire des copier/coller} \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}{Trouver les `\#include\textless{}\textgreater{}`}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Pour chaque appel système ou routine de la libc, consulter le manuel} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Exemple pour `fork()` : taper \{\{nl\}\}`man fork` \{\{nl\}\} qui nous indique d'ajouter\{\{nl\}\}\#include \textless{}unistd.h\textgreater{}} \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Dans le cas où il existe des entrées multiples dans le manuel, alors il faut préciser la section. Exemple : \{\{nl\}\} `man 3 sleep` affiche la page de manuel de la fonction C `sleep()` \{\{nl\}\} `man sleep` affiche la page de manuel de la commande bash `sleep` qui est trouvée en premier car elle est dans la section 1 (et non 3) du manuel} \tn % Row Count 12 (+ 7) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Pour touver toutes les entrées (et les sections correspondantes) contenant `mot` : `man k mot`} \tn % Row Count 14 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}