\chapter{Files}\index[concepts]{files} \section{Remove Part of a Filename from Multiple Files}\index[concepts]{files!manipulating names} \lettrine{S}{ome} applications can produce files that are similarly named, and for whatever reason, you want to remove the repetitive bits. You can use the \texttt{mmv}\index{mmv} package to do this. Assume you have a list of files that all start with ``foo'': \begin{Verbatim}[] foo143.txt fooabi.txt foo38r.txt \end{Verbatim} To remove the ``foo'', use this command: \begin{Verbatim}[frame=single, breaklines=true] mmv 'foo*' '#1' \end{Verbatim} To change ``foo'' to ``bar'', use: \begin{Verbatim}[frame=single, breaklines=true] mmv 'foo*' 'bar#1' \end{Verbatim} To exchange ``foo'' in our list above for the file extension, we would use: \begin{Verbatim}[frame=single, breaklines=true] mmv 'foo*.txt' 'txt#1.foo' \end{Verbatim} The \texttt{mmv} command uses this command structure: \vspace{3mm} \begin{Verbatim}[frame=single, breaklines=true, framesep=3mm, label=\fbox{mmv Command Structure}] mmv [-m|x|r|c|o|a|l|s] [-h] [-d|p] [-g|t] [-v|n] [--] [from to] \end{Verbatim} For a full discussion of those, see the ``man'' page. The key concept here is that wildcard characters in the ``from'' option get replaced with ``\#1'', ``\#2'' etc in the ``to'' option, in the order they are encountered. So it is possible to reorder elements of file names. To reverse the order of the last three characters of the filenames, we would use: \begin{Verbatim}[frame=single, breaklines=true] mmv 'foo???.txt' 'foo#3#2#1.txt' \end{Verbatim} That would produce this list of files:\index{mmv} \begin{Verbatim}[] foo341.txt fooiba.txt foor83.txt \end{Verbatim} \lettrine{T}{his} can also be accomplished by using the \textbf{rename}\index{rename} command. \section{Obtain a List of Files and their Paths}\index[concepts]{files!list of with paths} \lettrine{T}{he} \texttt{find} command\index{find} has options to obtain this list. To obtain this list with the full path, use: \input{bits/find_PWD}\index[concepts]{PWD} To obtain this list with a relative path, use:\index[concepts]{path, relative} \begin{Verbatim}[frame=single, breaklines=true] find . \end{Verbatim} To find only certain types of files (in this case jpgs) and redirect this information to a file, use something like this: \begin{Verbatim}[frame=single, breaklines=true] find . \( name "*.jpg" -o name "*.jpeg" \) > jpglist.txt \end{Verbatim} Because this is bash, the parentheses are not a capture group\index[concepts]{capture group} (as in regex\index[concepts]{regex}), but operators used to force precedence and need to be escaped, because parentheses are special to the shell. (Normally we would use quotation marks, but because we need to use quotation marks with the \texttt{name} test, we are using backslashes). Likewise, the \texttt{-o} is a Boolean ``or'', meaning that the second expression will not be evaluated if the first one is true. For more information, use \texttt{man find}. \ktcbox{Sometimes you need a list of files with their filepaths, and these tools will do that. Unfortunately, Linux does not have a way to put the file first, so the way to do this is to redirect \texttt{stdout} to a \texttt{.csv} file and manipulate the output in a spreadsheet.} \section{To Scale a pdf File} \lettrine{S}{ometimes} you need to scale the context of a pdf document.\index[concepts]{pdf documents!scaling} One easy way is to use the \texttt{pdfjam}\index{pdfjam} application, with this command: \begin{Verbatim}[frame=single] pdfjam --outfile output.pdf input.pdf --scale 0.XX \end{Verbatim} This will scale the document by XX percent. Note that this will not change the document size; it merely scales the content. A letter-size document will still be letter-sized, and an A3 document will still be an A3 document.\footnote{For more options (there are lots!) view the manual at \kref{https://github.com/pdfjam/pdfjam}{https://github.com/pdfjam/pdfjam}. For what it's worth, this program is a wrapper for the \LaTeX{} package \texttt{pdfpages}, so if you are handly with LaTeX, you can also accomplish these things that way as well.} To reduce both the document size and the content, use the \texttt{--papersize} option. This command will reduce a letter size document (8.5 inches x 11 inches) to a half-letter size document (5.5 inches x 8.5 inches): \begin{Verbatim}[frame=single] pdfjam --outfile output.pdf input.pdf --papersize '{5.5in,8.5in}' \end{Verbatim} To change to a conventional size that \LaTeX{} understands, use this command: \begin{Verbatim}[frame=single] pdfjam input.pdf --letterpaper --outfile output.pdf \end{Verbatim} \ktcbox{This is especially useful when scanning documents at a high dpi results in a document that has an extremely large page size.}