-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path02-cli.tex
111 lines (102 loc) · 3.08 KB
/
02-cli.tex
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
% !TeX root = bash.tex
\section{II. CLI}
\begin{frame}
\frametitle{The CLI}
\textbf{CLI} stands for \textbf{command line interface}, as opposed to a GUI.
\begin{figure}[h]
\centering
\includegraphics[height=5cm]{cli}
\caption{A stereotypical, Hollywood-like CLI.}
\end{figure}
\end{frame}
\begin{frame}[fragile]
\frametitle{Anatomy of a command}
\begin{lstlisting}[language=bash]
# get first 5 lines of file
$ head -n 5 longfile.txt
\end{lstlisting}
\begin{tabular}{ll}
\tt{head} & Executable file somewhere \\
\tt{-n} & Option (aka flag) \\
\tt{5} & Argument to \tt{-n} \\
\tt{longfile.txt} & Argument to \tt{head}
\end{tabular}
\end{frame}
\begin{frame}[fragile]
\frametitle{Anatomy of a command}
Anatomy of a command:
\begin{lstlisting}[language=bash]
# list all files but *.o recursively in reverse
$ ls -Rr --ignore='*.o'
\end{lstlisting}
\begin{tabular}{ll}
\tt{ls} & Executable in \tt{\$PATH} \\
\tt{-Rr} & Two options: \tt{-R -r} \\
\tt{--ignore=} & Long option \\
\tt{'*.o'} & Argument to \tt{--ignore}
\end{tabular}
\begin{block}{Notes}
\begin{itemize}
\item Not every program uses this \tt{--long-option} convention
\item The equal sign after \tt{--ignore} is optional in this command
\item \tt{'*.o'} does \textit{not} expand to a list of files.
It is simply a string.
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[fragile]
\frametitle{I can't possibly remember all \tt{--this} and \tt{--that}!}
You don't need to, thanks to \textbf{man pages}! (Short for manual pages)
\newline \newline
Try:
\begin{lstlisting}[language=bash]
$ man ls
\end{lstlisting}
If it doesn't work, try \url{https://man.archlinux.org/man/ls.1}
\end{frame}
\begin{frame}[fragile]
\frametitle{Challenge}
\begin{itemize}
\item Read the man page for \tt{head}
\item Experiment with files in \tt{02-cli/}
\item Find a command to generate the following:
\end{itemize}
\begin{lstlisting}[language=bash]
==> p0.txt <==
MANIFESTO OF THE COMMUNIST PARTY.
==> p1.txt <==
I. BOURGEOIS AND PROLETARIANS.
\end{lstlisting}
\pause
\begin{block}{Solution}
\begin{lstlisting}[language=bash]
$ head -n1 -v p0.txt p1.txt
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]
\frametitle{Learning by doing}
Inside \tt{02-cli/}, run:
\begin{lstlisting}[language=bash]
$ diff sway.1.conf sway.2.conf
\end{lstlisting}
Congratulations, you just learned how to use \tt{diff}!
\newline \newline
Now, what does this command do?
\begin{lstlisting}[language=bash]
$ comm -12 sway.1.conf sway.2.conf
\end{lstlisting}
\end{frame}
\begin{frame}
\frametitle{Lifehacks\footnote{Should work in most shells.}}
\begin{itemize}
\item Use $\uparrow \downarrow$
\item \tt{Ctrl-W}: delete one word to the left
\item \tt{Ctrl-U}: delete everything to the left
\item \tt{Ctrl-K}: delete everything to the right
\item \tt{Ctrl-7}: undo (might not work in Git Bash)
\item \tt{Ctrl-C}: abort
\item \tt{Ctrl-R}: search history
\item \tt{Ctrl-L}: clear screen
\end{itemize}
\end{frame}