From d193c09e2152cd532b49fed9de21418678a0b3fc Mon Sep 17 00:00:00 2001 From: Kenneth Odle Date: Mon, 24 Aug 2026 17:16:10 -0400 Subject: [PATCH] Added redirecting stderr and stdout --- chapters/ch04-system.tex | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/chapters/ch04-system.tex b/chapters/ch04-system.tex index 6fbe5ac..63ea4f4 100644 --- a/chapters/ch04-system.tex +++ b/chapters/ch04-system.tex @@ -60,7 +60,7 @@ We can also use: apt search \end{Verbatim} -Which gives a more detailed listing with the available version of all related packages: +Which gives a more detailed listing with the available versions of all related packages: \begin{Verbatim}[] Sorting... Done @@ -183,4 +183,34 @@ If necessary, you can redirect this information to a file using apt list --installed > app_list.txt \end{Verbatim} -Which will produce a warning: ``\texttt{WARNING: apt does not have a stable CLI interface. Use with caution in scripts.}'' What that means is that the \texttt{apt} command is meant to be used in an interactive mode (it includes things like progress bars when downloading and installing software, for example) and its output is not really able to be parsed in a script. (These commands work fine, however, as the output has a simple structure.) For scripting purposes, you really want to use \texttt{apt-get} and \texttt{apt-cache}. \ No newline at end of file +Which will produce a warning: ``\texttt{WARNING: apt does not have a stable CLI interface. Use with caution in scripts.}'' What that means is that the \texttt{apt} command is meant to be used in an interactive mode (it includes things like progress bars when downloading and installing software, for example) and its output is not really able to be parsed in a script. (These commands work fine, however, as the output has a simple structure.) For scripting purposes, you really want to use \texttt{apt-get} and \texttt{apt-cache}. + +\section{Redirecting \texttt{stdout} and \texttt{stderr} Somewhere Else} + +\lettrine{E}{very} command in Linux has three components: + +\begin{enumerate}[noitemsep] +\item Something to work on (that is, input) which we call \texttt{stdin} +\item Something it spits out (that is, output) which we call \texttt{stdout} +\item Error messages if something isn't right, which we call \texttt{stderr} +\end{enumerate} + +\noindent{}To redirect \texttt{stdout} to a file, you can use + +\begin{Verbatim}[frame=lines] +command > file.txt +\end{Verbatim} + +or + +\begin{Verbatim}[frame=lines] +command 1> file.txt +\end{Verbatim} + +\noindent{}To redirect \texttt{stderr} to a file, you can use + +\begin{Verbatim}[frame=lines] +command 2> file.txt +\end{Verbatim} + +