Added redirecting stderr and stdout

This commit is contained in:
Kenneth John Odle 2026-08-24 17:16:10 -04:00
parent 0c4d8fb3b3
commit d193c09e21

View File

@ -60,7 +60,7 @@ We can also use:
apt search <package> apt search <package>
\end{Verbatim} \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}[] \begin{Verbatim}[]
Sorting... Done Sorting... Done
@ -184,3 +184,33 @@ apt list --installed > app_list.txt
\end{Verbatim} \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}. 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}