summaryrefslogtreecommitdiff
path: root/unix-dev-refcard.tex
blob: f74fea3a7fcc257f209a37d352b914e6dc2f6a1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274

% unix-dev-refcard.tex - concise carte de référence pour le développement sous UNIX
%
% Copyright (C) 2017 Cyrille Bagard
%
%  This card is free software; you can redistribute it and/or modify
%  it under the terms of the GNU General Public License as published by
%  the Free Software Foundation; either version 3 of the License, or
%  (at your option) any later version.
%
%  This card is distributed in the hope that it will be useful,
%  but WITHOUT ANY WARRANTY; without even the implied warranty of
%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%  GNU General Public License for more details.
%
%  You should have received a copy of the GNU General Public License
%  along with this program; if not, write to the Free Software
%  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
%


\documentclass[landscape, 10pt]{article}

\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[a4paper, top=1.0cm, bottom=0.7cm, left=0.7cm, right=0.7cm]{geometry}

\usepackage{multicol}
\usepackage{url}
\usepackage{scrextend}
\usepackage{xcolor}


% Le code suivant permet de récupérer la police utilisée par les sections.
%
% Cf. http://tex.stackexchange.com/questions/73158/how-to-get-the-size-of-the-section-header

\newcommand{\getsectionfont}{\setbox0=\vbox{\section*{a\xdef\TheSectionFont{\the\font}}}}
\AtBeginDocument{\getsectionfont}

% Pas de numérotation de page
\pagestyle{empty}

\begin{document}

\title{Debugging --- Quick Reference Card}


% Les commandes suivantes permettent de mesurer une zone de texte, en particulier une pseudo section donc.
%
% Cf. https://en.wikibooks.org/wiki/LaTeX/Lengths#Examples

\newlength{\sectionheight}
\newsavebox{\hiddensection}
\savebox{\hiddensection}{\TheSectionFont
  ABC
}
\settoheight{\sectionheight}{ \usebox{\hiddensection} }

% On recrée une section artificielle. Elle n'apparaîtra pas dans un sommaire
% (qui n'existera de toute façon jamais), mais comporte des bordures plus minces
% que celles par défaut pour une section.

\newcommand{\fakesection}[1]{
  \vskip 1em
  \noindent
  \colorbox{black!70}{\parbox[c][1.6\sectionheight]{1.0\linewidth}{
      \begin{addmargin}[1em]{1em}\TheSectionFont
        {\color{white}#1}
      \end{addmargin}
    }
  }
}

\begin{multicols}{3}


% Création d'un titre

\begin{center}
  \huge{Happy UNIX developer life\\Quick Reference Card}
  \vskip 1em
  \large{@laughing\_bit --- \url{http://git.0xdeadc0de.fr/}}
\end{center} 

\vskip 1em
\hrule
\vskip 1em


% Définition des commandes

\newcommand{\cmd}[2]{
  \begin{small}{\tt#1}\dotfill{#2}\par\end{small}
}

\newcommand{\alias}[1]{
  {\tt alias #1}\par
}


\fakesection{Bash Basics}

\cmd{!!}{Refer to the previous command}
\cmd{!*}{Refer to all the arguments of the last command}
\cmd{!\^{}}{Refer to the first word of the last command}
\cmd{!\$}{Refer to the last word of the last command}

\cmd{cmd1 \textbar\& cmd2}{Pipe stdout and stderr of \textit{cmd1} to \textit{cmd2}}

\cmd{echo \$RANDOM}{Display a random number}
\cmd{echo \$(( 0x10 + 1 ))}{Compute math formulas}

\cmd{source \textasciitilde/.bashrc}{Reload the bash initialization file}

\cmd{pushd / popd}{Stack working directories}
\cmd{cp myfile\{,.bak\}}{Skip some writing}
\cmd{ls -lhd !(*avi|*mkv)}{List all files which do not match}

\cmd{\textbackslash command}{Escape any aliases for \textit{command}}

\fakesection{Terminal shortcuts}

\cmd{Ctrl-l}{Clear the screen}
\cmd{Ctrl-a}{Go to the beginning of line}
\cmd{Ctrl-e}{Go to the end of line}

\cmd{Ctrl-k}{Delete from cursor to the end of line}
\cmd{Ctrl-u}{Delete from cursor to the start of line}
\cmd{Ctrl-w}{Delete from cursor to the start of word}
\cmd{Ctrl-y}{Paste text cut using one of the above shortcuts}

\cmd{Esc c / Alt-c}{Capitalize from cursor to end of word}
\cmd{Esc u / Alt-u}{Upcase from cursor to end of word}
\cmd{Esc l / Alt-l}{Downcase from cursor to end of word}

\cmd{Alt-t}{Swap the current word with the previous one}
\cmd{Ctrl-t}{Swap the current character with the previous one}

\cmd{Esc Ctrl-e}{Expand the line content}

\cmd{Ctrl-r}{Enter the reverse-search history}

\fakesection{Useful tools}

\cmd{colorgcc}{Colorize GCC compilation output}
\cmd{hexedit}{View and edit binary files, in hex or ASCII}
\cmd{vbindiff}{Visually compare binary files}
\cmd{kcachegrind}{Visualize valgrind profiling output}
\cmd{kompare}{View file differences using a nice GUI}
\cmd{kmag}{Magnify a part of the screen}
\cmd{screenruler}{Measure objects on the screen}
\cmd{cloc / sloccount}{Count physical source lines of code}


\fakesection{Shell tricks}

\cmd{cat /proc/self/environ | tr "\textbackslash0" "\textbackslash n"}{Same as {\tt env}}
\cmd{sed "s\#//\#/\#"}{Same as {\tt sed "s/\textbackslash/\textbackslash//\textbackslash//"}}
\cmd{mount | column -t}{Show filesystems in a nice layout}
\cmd{getconf LONG\_BIT}{Tell if the system is 32 bits or 64 bits}
\cmd{sed -n 5p file}{Print the 5th line of \textit{file}}
\cmd{tar tf file | xargs rm -rf}{Remove all extracted files}


\fakesection{GDB - \textasciitilde/.gdbinit}

\cmd{set confirm off}{Disable confirmation requests}
\cmd{set disassembly-flavor intel}{Set the disassembly style}
\cmd{set print pretty on}{Print structures in a nice way}
\cmd{set history save}{Record command history in a file}
\cmd{set print array on}{Print one item per line}


\fakesection{GDB commands}

\par{Commands can be run at startup using {\tt gdb -ex cmd}.}

\medskip

\cmd{target remote :1234}{Connect to a local server}

\cmd{b where [if cond]}{Set a breakpoint (triggered if \textit{cond})}
\cmd{commands id}{Run commands when the breakpoint \textit{id} is hit}
\cmd{rb regexp}{Break on functions matching \textit{regexp}}

\cmd{bt [full] [N/-N]}{Show \textit{N} frames of the call stack}
\cmd{t a a cmd}{Apply \textit{cmd} to all threads (e.g. \textit{t a a bt 3})}
\cmd{info f}{Print verbose info about the current frame}
\cmd{finish}{Continue till end of function}

\cmd{pt var}{Print info about the type of \textit{var}}
\cmd{p *array@count}{Print the \textit{count} first items of \textit{array}}
\cmd{info locals}{View all local variables}
\cmd{info args}{View all function arguments}


\fakesection{Valgrind options}

\cmd{-{}-trace-children=yes}{Track wrapped binaries}
\cmd{-{}-vgdb=full}{Activate the "gdbserver" functionality}
\cmd{-{}-vgdb-error=0}{Break the program at startup}

\cmd{-{}-fullpath-after=directory}{Extend path in stack traces}

\cmd{-{}-suppressions=file}{Specify one list of errors to hide}
\cmd{-{}-gen-suppressions=all}{Print error definitions}

\cmd{-{}-read-var-info=yes}{Read variable info from DWARF3}


\fakesection{Valgrind -{}-tool=memcheck}

\cmd{-{}-leak-check=full}{Show each individual leak in detail}
\cmd{-{}-show-reachable=yes}{Track all kinds of memory leak}
\cmd{-{}-track-origins=yes}{Track the origin of uninitialised values}

\fakesection{Valgrind -{}-tool=callgrind}

\cmd{-{}-callgrind-out-file=dest}{Choose \textit{dest} as output}
\cmd{-{}-dump-instr=yes}{Collect at per-instruction granularity}
\cmd{-{}-collect-jumps=yes}{Collect info for conditional jumps}


\fakesection{Valgrind -{}-tool=massif}

\cmd{-{}-massif-out-file=dest}{Choose \textit{dest} as output}

\cmd{-{}-depth=100}{Increase depth of recorded allocation trees}
\cmd{-{}-threshold=0.05}{Set threshold as \% of total memory}

\cmd{-{}-alloc-fn=g\_malloc}{Handle GLib allocations \#0}
\cmd{-{}-alloc-fn=g\_malloc0}{Handle GLib allocations \#1}
\cmd{-{}-alloc-fn=g\_realloc}{Handle GLib allocations \#2}
\cmd{-{}-alloc-fn=g\_try\_malloc}{Handle GLib allocations \#3}
\cmd{-{}-alloc-fn=g\_mem\_chunk\_alloc}{Handle GLib allocations \#4}

\medskip

\par{Use {\tt ms\_print -{}-threshold=X} to process stored data.}


\fakesection{Alias advices}

\cmd{man ascii}{Display the ASCII table}

\cmd{gcc -dM -E - < /dev/null}{Dump preprocessor defines}
\cmd{make -j\$( nproc )}{Run make using all found CPUs}

\cmd{find -name "*\textasciitilde" -delete}{Remove backup files}
\cmd{find -type d -empty -delete}{Remove empty directories}

\cmd{xclip -selection clipboard}{Copy from stdin}
\cmd{xclip -selection clipboard -o}{Paste to stdout}

\cmd{kill -STOP \$( pidof firefox )}{Save some CPU usage}
\cmd{kill -CONT \$( pidof firefox )}{Go to surf on the Web}

\cmd{grep -{}-color=always}{Enjoy colors using {\tt less -R}}
\cmd{grep -{}-include="*.[ch]"}{Search in code source only}

\cmd{readelf -aW file}{Display wide info about \textit{file}}


\vskip 2em
\hrule
\vskip 1em

\centerline{This card may be distributed under the terms of the GPL v3}
\centerline{Copyright \copyright\ {2017} Cyrille BAGARD}

\end{multicols}
\end{document}