\chapter{More Tools} {\mns \renewcommand*{\bs}{\texttt{\char '134}} \subsection{Objectives} \label{sec:more-tools-objectives} Having completed this module you should be able use the following tools appropriately: \begin{itemize} \item {\pgn top} \item {\pgn ps} \item {\pgn find} \item {\pgn vmstat} \item {\pgn free} \item {\pgn ldd} \item {\pgn uptime} \item {\pgn xargs} \item {\pgn cpio} \item {\pgn tar} \item {\pgn gzip} \end{itemize} \section{Introduction} \label{sec:intro-more-tools} Tools covered in this module have these functions: \vspace{15pt} \begin{table}[htbp] {\mns %% \begin{tabular}[t]{|>{\PBS\rr}p{80pt}|>{\PBS\rr}p{283pt}|} \hline %% Command & Function \\ \hline \hline %% {\pgn top} & display top CPU processes \\ \hline %% {\pgn ps} & display process status \\ \hline %% {\pgn find} & find files in a directory hierarchy \\ \hline %% {\pgn vmstat} & display virtual memory statistics \\ \hline %% {\pgn free} & display free and used memory \\ \hline %% {\pgn ldd} & display shared library dependencies \\ \hline %% {\pgn uptime} & display system uptime \\ \hline %% {\pgn xargs} & build and exec commands from stdin \\ \hline %% {\pgn cpio} & copy files to and from archives \\ \hline %% {\pgn tar} & create and extract {\fn *.tar} archive files \\ \hline %% {\pgn gzip} & create and extract {\fn *.gz} archive files \\ \hline %% \end{tabular} \begin{tabular}[t]{>{\PBS\rr}p{80pt}>{\PBS\rr}p{283pt}} \toprule% Command & Function \\ \midrule {\pgn top} & display top CPU processes \\ {\pgn ps} & display process status \\ {\pgn find} & find files in a directory hierarchy \\ {\pgn vmstat} & display virtual memory statistics \\ {\pgn free} & display free and used memory \\ {\pgn ldd} & display shared library dependencies \\ {\pgn uptime} & display system uptime \\ {\pgn xargs} & build and exec commands from stdin \\ {\pgn cpio} & copy files to and from archives \\ {\pgn tar} & create and extract {\fn *.tar} archive files \\ {\pgn gzip} & create and extract {\fn *.gz} archive files \\ \bottomrule \end{tabular} } \caption{\normalsize More tools and their functions} \label{tab:more-tools-purposes} \end{table} \section{Displaying System Processes ({\pgn top})} \label{sec:more-tools-top} \begin{itemize} \item Displays ongoing processor activity in real time \item Shows processes for {\em all} users, unlike {\pgn ps} \item Has several modes: \begin{itemize} \item Secure Mode, disables potentially dangerous interactive commands \item Cummulative Mode, shows time for a process {\em and} its dead children \item No-idle Mode, ignores idle or zombie processes \end{itemize} \item Typical output may be: {\myts \begin{alltt} 12:37:53 up 11 days, 2:48, 13 users, load average: 1.71, 1.35, 0.76 143 processes: 137 sleeping, 3 running, 3 zombie, 0 stopped CPU states: cpu user nice system irq softirq iowait idle total 12.1% 0.0% 4.6% 0.0% 0.0% 0.0% 83.1% Mem: 255616k av, 251200k used, 4416k free, 0k shrd, 10148k buff 17452k active, 206676k inactive Swap: 1024120k av, 397956k used, 626164k free 81720k cached \colorbox{black}{ \textcolor{white}{\textbf{PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME CPU COMMAND}}} 4621 nicku 18 0 10164 9.9M 688 R 8.3 3.9 1:22 0 rsync 5519 nicku 17 0 1248 1248 848 R 3.7 0.4 0:00 0 top 1466 root 15 0 19552 3172 2636 S 2.7 1.2 1:03 0 spamd 1 root 16 0 492 464 440 S 0.0 0.1 0:14 0 init 2 root 15 0 0 0 0 SW 0.0 0.0 0:01 0 keventd 3 root 15 0 0 0 0 SW 0.0 0.0 0:00 0 kapmd 4 root 34 19 0 0 0 SWN 0.0 0.0 0:00 0 ksoftirqd/0 6 root 25 0 0 0 0 SW 0.0 0.0 0:00 0 bdflush 5 root 15 0 0 0 0 SW 0.0 0.0 3:35 0 kswapd 7 root 15 0 0 0 0 SW 0.0 0.0 1:06 0 kupdated 8 root 21 0 0 0 0 SW 0.0 0.0 0:00 0 mdrecoveryd 13 root 15 0 0 0 0 SW 0.0 0.0 1:13 0 kjournald 63 root 15 0 0 0 0 SW 0.0 0.0 0:00 0 khubd 786 root 15 0 0 0 0 SW 0.0 0.0 0:02 0 kreiserfsd 1097 root 15 0 584 564 524 S 0.0 0.2 0:33 0 syslogd 1101 root 16 0 440 380 380 S 0.0 0.1 0:00 0 klogd 1110 rpc 16 0 604 580 580 S 0.0 0.2 0:00 0 portmap 1129 rpcuser 18 0 644 568 568 S 0.0 0.2 0:00 0 rpc.statd 1182 root 15 0 496 444 444 S 0.0 0.1 0:00 0 apmd 1234 root 16 0 580 516 496 S 0.0 0.2 0:00 0 automount 1271 root 15 0 832 612 612 S 0.0 0.2 0:05 0 sshd \end{alltt} } \end{itemize} %% 1285 root 15 0 708 576 576 S 0.0 0.2 0:00 0 xinetd %% 1295 ntp 16 0 3888 3888 2204 S 0.0 1.5 0:01 0 ntpd %% 1312 root 18 0 312 240 240 S 0.0 0.0 0:00 0 rpc.rquotad \section{Options and Interactive Commands for {\pgn top}} \label{sec:more-tools-top-opts} Significant command-line options for {\pgn top} include: \begin{table}[htbp] {\myfs %% \begin{tabular}[t]{|>{\PBS\rr}p{80pt}|>{\PBS\rr}p{283pt}|} \hline %% Option & Function \\ \hline \hline %% {\cmdn -d} & delay between screen updates (seconds) \\ \hline %% {\cmdn -q} & Refresh without any delay. \\ \hline %% {\cmdn -S} & Specifies cumulative mode \\ \hline %% {\cmdn -s} & Secure mode \\ \hline %% {\cmdn -i} & Non-idle mode \\ \hline %% {\cmdn -c} & Show full {\em command line} instead of command name \\ \hline %% \end{tabular} \begin{tabular}[t]{>{\PBS\rr}p{80pt}>{\PBS\rr}p{283pt}} \toprule% Option & Function \\ \midrule% {\cmdn -d} & delay between screen updates (seconds) \\ {\cmdn -q} & Refresh without any delay. \\ {\cmdn -S} & Specifies cumulative mode \\ {\cmdn -s} & Secure mode \\ {\cmdn -i} & Non-idle mode \\ {\cmdn -c} & Show full {\em command line} instead of command name \\ \bottomrule \end{tabular} } \caption{\normalsize Command line options for {\pgn top}} \label{tab:options-for-top} \end{table} \vspace{10pt} The key interactive commands are: \begin{table}[h] {\myfs \begin{tabular}[t]{>{\PBS\rr}p{80pt}>{\PBS\rr}p{283pt}} \toprule% Command & Function \\ \midrule% {\cmdn } & Update display \\ {\cmdn fF} & add and remove fields \\ {\cmdn oO} & Change order of displayed fields \\ {\cmdn h} or {\cmdn ?} & Help on interactive commands \\ {\cmdn S} & Toggle cumulative mode \\ {\cmdn i} & Toggle display of idle proceses \\ {\cmdn c} & Toggle display of command name/line \\ {\cmdn l} & Toggle display of load average \\ {\cmdn m } & Toggle display of memory information \\ {\cmdn t } & Toggle display of summary information \\ {\cmdn k } & Kill a task (with any signal) \\ {\cmdn r } & Renice a task \\ {\cmdn P } & Sort by CPU usage \\ {\cmdn M } & Sort by resident memory usage \\ {\cmdn T } & Sort by time / cumulative time \\ {\cmdn u } & Show only a specific user \\ {\cmdn n } or {\cmdn \#} & Set the number of process to show \\ {\cmdn W } & Write configuration file ~/.toprc \\ {\cmdn q } & Quit \\ \bottomrule \end{tabular} } \caption{\normalsize Interctive commands for {\pgn top}} \label{tab:commands-for-top} \end{table} \section{Reporting process status ({\pgn ps})} \label{sec:more-tools-ps} \begin{itemize} \item {\pgn ps} prints info about a user's processes: {\myss \begin{verbatim} PID TTY STAT TIME COMMAND 22074 p0 S 0:02 Eterm -t trans 22075 p0 S 2:13 emacs -bg black 22081 p0 S 0:00 asclock 22590 p5 R 0:00 ps \end{verbatim} } \item Unlike {\pgn jobs} which only prints info about processes belonging to the current shell \item Various display formats: \begin{itemize} \vspace{10pt} \item Long format ({\kbk l}), e.g. {\myts \begin{alltt} $ \textbf{ps l} FLAGS UID PID PPID PRI NI SIZE RSS WCHAN STA TTY TIME COMMAND 0 512 19665 19653 0 0 7000 5616 12d63d S p2 0:19 /usr/bin/emacs 100000 512 23656 23652 0 0 1076 548 1897da S p5 0:00 /usr/bin/less -is \end{alltt} } \vspace{10pt} \item User format ({\kbk u}), e.g. \begin{alltt}\myts $ \textbf{ps u} $ ps u USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND nicku 15317 0.0 0.4 5940 1224 pts/26 S Nov20 0:00 bash nicku 4897 0.0 0.3 4260 828 pts/26 R 09:02 0:00 ps u \end{alltt} \vspace{10pt} \item Jobs format ({\kbk j}), e.g. {\myts \begin{alltt} $ \textbf{ps j} PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND 2374 15317 15317 15317 pts/26 4980 S 1000 0:00 bash 15317 4980 4980 15317 pts/26 4980 R 1000 0:00 ps j \end{alltt} } \vspace{10pt} \item Virtual Memory format ({\kbk v}), e.g. \begin{alltt}\myts $ \textbf{ps v} PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND 15317 pts/26 S 0:00 968 562 5377 1312 0.5 bash 4987 pts/26 R 0:00 173 62 4033 828 0.3 ps v \end{alltt}%$ \end{itemize} \end{itemize} \section{Options for Reporting process status ({\pgn ps})} \label{sec:more-tools-ps-options} More options to {\pgn ps}: \begin{itemize} \vspace{10pt} %% \item Show memory info ({\cmdn m}) %% {\myts %% \begin{verbatim} %% PID TTY MAJFLT MINFLT TRS DRS SIZE SWAP RSS SHRD LIB DT COMMAND %% 23656 p5 125 25 72 476 548 0 548 424 0 31 /usr/bin/less -is %% 19665 p2 1648 2613 2120 3672 5792 0 5792 2584 0 802 /usr/bin/emacs %% \end{verbatim} %% } %% \vspace{10pt} \item Show `family tree' ({\cmdn f}) for processes, e.g. {\myts \begin{alltt} $ \textbf{ps f} PID TTY STAT TIME COMMAND 19652 p2 S 0:00 /bin/login -h oakleigh gbdirect.co.uk -p 19653 p2 S 0:00 \_ -bash 19664 p2 S 3:02 \_ /home/lee/bin/emacs -f gnus-no-server 19665 p2 S 0:23 \_ /usr/bin/emacs 19668 p2 S 3:41 \_ /usr/lib/netscape/netscape-communicator 19681 p2 S 0:00 \_ (dns helper) \end{alltt}%$ } Try {\pgn pstree} also. %\vspace{10pt} \item Other important options: {\myts \begin{tabular}[t]{@{}>{\ttfamily}ll@{}} \toprule% \textnormal{Option} & Effect \\ \midrule% a & Show \textbf{a}ll processes\\ w & Show a \textbf{w}ider display (normally just 80 characters wide)\\ www & Show an even \textbf{w}ider display \\ wwww & Show an even \textbf{w}ider display \\ \bottomrule \end{tabular} } \medskip \item Show environment after command line: {\myts \begin{alltt} $ \textbf{ps e} PID TTY STAT TIME COMMAND 19653 p2 S 0:00 -bash DISPLAY=oakleigh:0.0 TERM=xterm HOME=/home/davef PATH= \end{alltt}%$ } \end{itemize} \section{Sorting output of ps} \label{sec:sorting-ps-output} \begin{itemize} \item Sort {\pgn ps} results by specific fields:% %% ~\footnote{You can get %% a full print-out of the sorting options by giving the erroneous command string {\cmdn ps -O+}} \providecommand{\VM}{\acro{VM}\xspace} \begin{table}[htbp] {\myfs \begin{center} %% \begin{tabular}[t]{p{75pt}p{75pt}p{75pt}p{75pt}} \toprule% %% Option & Function & Option & Function \\ \midrule% %% {\cmdn -Ou} & user & {\cmdn -Oc} & cmd \\ %% {\cmdn -OU} & uid & {\cmdn -Op} & pid \\ %% {\cmdn -OP} & pppid & {\cmdn -Ot} & tty \\ %% {\cmdn -Oo} or {\cmdn ?} & session & {\cmdn -Ok} & utime \\ %% {\cmdn -OK} & stime & {\cmdn -Oj} & cutime \\ %% {\cmdn -OJ} & cstime & {\cmdn -Oy} & priority \\ %% {\cmdn -OT} & start\_time & {\cmdn -Or} & rss \\ %% {\cmdn -Ov} & vsize & {\cmdn -Os} & size \\ %% {\cmdn -OC} & pcpu & {\cmdn -OS} & share \\ \bottomrule %% \end{tabular} \begin{tabularx}{\linewidth}[t]{lYlY} \toprule% Option & Function & Option & Function \\ \midrule% {\cmdn Ou} & user & {\cmdn Oc} & simple executable name\\ {\cmdn OU} & uid & {\cmdn Op} & \PID \\ {\cmdn OP} & parent \PID & {\cmdn Ot} & tty \\ {\cmdn Oo} & session \ID & {\cmdn Ok} & user time \\ {\cmdn OK} & system time & {\cmdn Oj} & cumulative user time \\ {\cmdn OJ} & cumulative system stime & {\cmdn Oy} & priority \\ {\cmdn OT} & start\_time & {\cmdn Or} & resident set size \\ {\cmdn Ov} & \VM size & {\cmdn Os} & size \\ {\cmdn OC} & full command line & {\cmdn OS} & share \\ \bottomrule \end{tabularx} \end{center} } \caption{\normalsize CLI options for sorting {\pgn ps} results} \label{tab:more-tools-ps-sort} \end{table} \item In \texttt{man ps}, search for SORT KEYS. \item See \url{http://mail.gnome.org/archives/gnome-list/1999-April/msg02337.html}, where Miguel de Icaza explains the memory usage options of \texttt{ps} Summary: \begin{description} \item[\emph{size}] is the total size of a process, including what is in swap. Not so useful. \item[\emph{resident set size} (rss)] is the total amount of \RAM memory actually used by a process, i.e., not in swap, but includes memory shared with other processes \item[\emph{share}] the amount of memory used by a process that is shared with other processes. \end{description} \item So actual \RAM used by a process is $\mbox{rss} - \mbox{share}$ \end{itemize} \section{Flavours of \texttt{ps} Options} \label{sec:flavours-of-ps-options} \begin{itemize} \item There are three \emph{flavours} of options for \texttt{ps}: \begin{itemize} \item \acro{BSD} options (that we use here), with no dash \item Unix98 options that must be preceded with a dash \item \GNU long options that must be preceded with two dashes \end{itemize} \item It is important to understand that there are \acro{BSD} options and Unix98 options that have the same letter but which do completely different things, e.g., the \acro{BSD} option \texttt{ef} \begin{alltt}\myts $ \textbf{ps ef} PID TTY STAT TIME COMMAND 6744 pts/3 S 0:00 bash SSH_AGENT_PID=6649 HOSTNAME=nicksbox.tyict.vtc.e27436 pts/3 R 0:00 ps ef SSH_AGENT_PID=6455 HOSTNAME=nicksbox.tyict.vtc. \end{alltt}%$ is completely different from the Unix98 option: \begin{alltt}\myts $ \textbf{ps -ef} UID PID PPID C STIME TTY TIME CMD root 1 0 0 Dec15 ? 00:00:04 init [5] root 2 1 0 Dec15 ? 00:00:00 [keventd] root 3 1 0 Dec15 ? 00:00:00 [kapmd] root 4 1 0 Dec15 ? 00:00:00 [ksoftirqd/0] root 6 1 0 Dec15 ? 00:00:00 [bdflush] \ldots nicku 27369 8764 0 07:03 pts/4 00:00:00 /bin/sh /usr/bin/xdvi masterfile nicku 27375 27369 0 07:03 pts/4 00:00:00 xdvi.bin -name xdvi masterfile nicku 27438 6744 0 07:12 pts/3 00:00:00 ps -ef \end{alltt}%$ \item You can mix these options together, e.g., to get a wider display of \texttt{ps -ef}: \begin{alltt}\myts $ \textbf{ps -ef www} UID PID PPID C STIME TTY STAT TIME CMD root 1 0 0 Dec15 ? S 0:04 init [5] root 2 1 0 Dec15 ? SW 0:00 [keventd] \ldots \end{alltt}%$ \item See \texttt{man ps} \end{itemize} \section{Examples using \texttt{ps}} \label{sec:tools-more-ps-examples} \begin{itemize} \item To determine information about the \texttt{yum} process: \begin{alltt}\myts $ \textbf{ps auxwww | grep yum} root 6440 2.2 2.8 14832 7284 pts/29 S 09:19 0:00 /usr/bin/python /usr/bin/yum update nicku 6542 0.0 0.1 968 332 pts/11 S 09:20 0:00 grep yum \end{alltt}%$ \item Hmm, how do we get rid of the line showing the ``\texttt{grep yum}'' process? One way is to exclude it using \texttt{grep -v}: \begin{alltt}\myts $ \textbf{ps auxwww | grep yum | grep -v grep} root 6440 4.7 5.0 20684 12960 pts/29 S 09:19 0:05 /usr/bin/python /usr/bin/yum update \end{alltt}%$ \item But we can do that more simply with: \begin{alltt}\myts $ \textbf{ps auxwww | grep [y]um} root 6440 2.6 5.0 20684 12960 pts/29 S 09:19 0:05 /usr/bin/python /usr/bin/yum update \end{alltt}%$ \end{itemize} \section{Finding Files using specified criteria ({\pgn find})} \label{sec:tools-more-find} \begin{itemize} \item {\cmdn find} searches your filesystem for files matching certain criteria, as we saw in section \$\vref{sec:basic-linux-unix-tools-find}. \item Can match on name, owner, size, modification/access time, name \begin{itemize} \item and many others \end{itemize} \item Can execute commands on files it finds \item Commonly used to archive sets of files, or clear out old files \end{itemize} \section{Criteria used in {\pgn find} expressions} \label{sec:tools-more-find-expressions} \providecommand*{\UID}{\acro{UID}\xspace} \begin{itemize} \item Basic syntax: \begin{alltt} find \meta{base directory}\ldots \meta{search criteria} \end{alltt} \vspace{-15pt} {\myts %% \begin{tabular}[t]{|p{100pt}|p{275pt}|} \hline %% -name string & Filename matches string (Shell metacharacters included) \\ \hline %% -mtime value & Modification time matches value \\ \hline %% -user UID/username & Owner matches UID or username\\ \hline %% -size size & Size of the file matches size\\ \hline %% -perm -/+ mode & Permissions of the file match mode\\ \hline %% -type t & File is of type {\cmdn t} (f --- normal file, x --- executable file etc. See man page for full details) \\ \hline %% \end{tabular} \begin{tabularx}{\linewidth}[t]{>{\ttfamily}lY} \toprule% Test & What It Does\\ \midrule% -name \meta{string} & Filename matches string (Shell metacharacters included) \\ -mtime -/+\meta{days} & Modification time matches \meta{days} \\ -user \meta{UID/username} & Owner matches \meta{UID} or \meta{username}\\ -size -/+\meta{size} & Size of the file matches \meta{size}\\ -perm -/+\meta{mode} & Permissions of the file match \meta{mode}\\ -type \meta{t} & File is of type \meta{t} (\texttt{f} --- normal file, \texttt{x} --- -executable file, \texttt{d} ---directory,\ldots. See man page for full details) \\ \bottomrule \end{tabularx} } \medskip \item The values to match are very flexible, e.g. to find all files below {\fn /home/lee} that were last modified less than 24 hours ago: \begin{alltt} $ \textbf{find /home/lee -mtime -1} \end{alltt}%$ \item Find all files below current directory greater than 1000k in size and with permissions {\cmdn 664} ({\cmdn -rw-rw-r---}) \begin{alltt} $ \textbf{find . -size +1000k -perm 664 -exec ls -l \{\} \bs;} \end{alltt}%$ \end{itemize} \section{Examples of using ({\pgn find})} \label{sec:more-tools-find-examples} \begin{itemize} \item Find all files ending in {\fn .jpg} under current dir: \begin{alltt} $ \textbf{find . -name "*.jpg"} \end{alltt}%$ \vspace{6pt} \item Find filenames ending in {\fn .jpg} {\em and} modified in the last 8 days below {\fn /etc}: \begin{alltt} $ \textbf{find /etc -name "*.jpg" -mtime -8} \end{alltt}%$ \vspace{6pt} \item Combine tests with {\cmdn -o} and negate with {\kbk !}, e.g: \begin{itemize} % Nick: Be careful to rephrase this unambiguously: \item To find all filenames {\em not} ending in {\fn .jpg} {\em or} modified in the last 8 days: \begin{alltt} $ \textbf{find . \bs! -name "*.jpg" -o -mtime -8} \end{alltt}%$ \end{itemize} \vspace{6pt} \item Execute commands on files found. For example, to find then gzip-compress tar files: \begin{alltt} $ \textbf{find . -name "*.tar" -exec gzip \{\} \bs;} \end{alltt}%$ i.e. found filenames substitute for {\cmdn \{\}} above~\footnote{Piping the {\pgn find} results to {\pgn xargs} (section~\ref{sec:more-tools-xargs} ) is a more efficent approach} \vspace{6pt} \item N.B. {\pgn find} searches the filesystem in real time; making disks work hard \end{itemize} \section{Reporting virtual memory statistics ({\pgn vmstat})} \label{sec:more-tools-vmstat} \begin{itemize} \item {\pgn vmstat} is used to identify system bottlenecks \item Reports on processes, memory, paging, block IO, interrupts ({\kwd traps}), and cpu activity \item SYNTAX: \begin{quote} {\cmdn vmstat [-n] [-V] [{\usb delay} [{\usb count}]]} \end{quote} \item If no {\cmdn delay} specified gives averages since last reboot \begin{itemize} \item Otherwise updates every {\usb delay} seconds \item Shows averages since last report \end{itemize} \item {\usb count} is the number of updates to give \begin{itemize} \item If no {\cmdn count} is specified, just keeps on running \end{itemize} \item Option {\cmdn -n} causes header display only once%% ~\footnote{Allegedly! Some versions do not implement this %% correctly} \end{itemize} \section{Output from {\pgn vmstat}} \label{sec:more-tools-vmstat-output} \begin{itemize} \item The headings in the output have very short names: \begin{table}[htbp] {\myfs \begin{center} \begin{tabular}[t]{ll>{\PBS\rr}p{240pt}} \toprule Section Head & Field & Description\\ \midrule {\sco Procs} & {\sco r} & no. of runnable processes \\ \ & {\sco b} & no. of processes sleeping \\ \ & {\sco w} & no. of processes swapped out but otherwise runnable \\ {\sco Memory} & {\sco swpd} & virtual memory used (kb) \\ \ & {\sco free} & idle memory (kb) \\ \ & {\sco buff} & memory used as buffers (kb) \\ {\sco Swap} & {\sco si} & memory swapped in from disk (kb/s) \\ \ & {\sco so} & memory swapped out to disk (kb/s) \\ {\sco IO} & {\sco bi} & Blocks sent to a block device (blocks/s) \\ \ & {\sco bo} & Blocks received from a block device (blocks/s) \\ {\sco System} & {\sco in} & interrupts per second, inc the clock \\ \ & {\sco cs} & context switches per second \\ {\sco CPU} & {\sco us} & user time (as \% of total CPU time) \\ \ & {\sco sy} & system time (as \% of total CPU time) \\ \ & {\sco id} & idle time (as \% of total CPU time) \\ \bottomrule \end{tabular} \end{center} } \caption{\normalsize Field descriptions for {\pgn vmstat} output} \label{tab:vmstat-output} \end{table} \end{itemize} \section{free} \label{sec:more-tools-free} \begin{itemize} \item Another tool to examine memory status \item Displays in kilobytes by default %% \begin{tabular}[t]{|p{70pt}|p{275pt}|} \hline %% {\cmdn -k} & Output in kilobytes \\ \hline %% {\cmdn -m} & Output in megabytes \\ \hline %% {\cmdn -b} & Output in bytes \\ \hline %% {\cmdn -s x} & Poll every x seconds \\ \hline %% {\cmdn -t} & Display a `total' line \\ \hline %% \end{tabular} \begin{tabular}[t]{p{70pt}p{275pt}} {\cmdn -k} & Output in kilobytes \\ {\cmdn -m} & Output in megabytes \\ {\cmdn -b} & Output in bytes \\ {\cmdn -s x} & Poll every x seconds \\ {\cmdn -t} & Display a `total' line \\ \end{tabular} \item Simpler alternative to {\pgn vmstat} \item May be useful if {\pgn vmstat} not available \item Quick check on overall memory usage \end{itemize} \section{ldd} \label{sec:more-tools-ldd} \begin{itemize} \item Modern operating systems support \emph{shared libraries} \begin{itemize} \item In Windows, they are called DLLs --- \textbf{d}ynamic \textbf{l}ink \textbf{l}ibraries \end{itemize} \item Link the program with dynamically loaded shared libraries \begin{itemize} \item instead of including a copy of the same executable library code in all applications \item Makes the application \emph{much} smaller \item But the application will not run correctly unless the correct version of each shared library is installed \begin{itemize} \item In Windows, this is sometimes called \emph{DLL hell} (Do a google search for ``dll hell'' or see \url{http://www.desaware.com/Articles/DllHellL3.htm} \item Linux shared libraries have the version number in their file name, solving the problem in a simple way. \end{itemize} \end{itemize} \item {\pgn ldd} prints out dependencies on shared libraries for a given executable \begin{alltt}\myts $ \textbf{ldd /bin/bash} libtermcap.so.2 => /lib/libtermcap.so.2 (0x40003000) libc.so.6 => /lib/libc.so.6 (0x40006000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x00000000) \end{alltt}%$ \item {\fn /bin/bash} requires three shared libraries to run correctly \item \texttt{ldd} is a very useful debugging tool \item \texttt{ldd} is also needed for setting up restricted ({\cmdn chroot}'d) environments \end{itemize} \section{uptime} \label{sec:more-tools-uptime} \begin{itemize} \item {\pgn uptime} prints out basic information about performace of system {\myts \begin{alltt} $ \textbf{uptime} 4:26pm up 165 days, 23:23, 9 users, load average: 0.23, 0.13, 0.10 \end{alltt}}%$ \item Shows: \begin{itemize} \item Current Time \item Time since last reboot (Days, Hours:Minutes) \item Number of logged-in connections \item Load average past minute, past 5 minutes and past fifteen minutes \begin{itemize} \item \emph{Load average} is the average number of processes that are ready to run, but no \CPU is available. \item A load average of 0.5 is light loading; a load average of 3 is a fairly heavy work load; a load average of 10 will make people complain about the system being ``slow''; a load average of 100 may result in a five minute wait between pressing a key on the keyboard and seeing the result. \end{itemize} \end{itemize} \item Same information given in \texttt{top} --- see section~\vref{sec:more-tools-top}. \end{itemize} \section{\texttt{xargs} --- Filters} \label{sec:xargs-background} \begin{itemize} \item Most tools we examine are \emph{filters}; they read standard input and, when no filename is specified, write to standard output: \begin{center} \includegraphics{../images/filters} \end{center} \item However, some, such as \texttt{ls}, \texttt{file}, \texttt{echo}, \texttt{find}, \texttt{rm}, \texttt{cp}, \texttt{mv} read the command line or file system, and do \emph{not} read standard input: \begin{center} \includegraphics{../images/filters-no-input} \end{center} \item Sometimes we still want to combine these tools into a pipeline: \vspace*{-1\baselineskip} \begin{center} \includegraphics[width=\textwidth]{../images/pipeline} \end{center} \item For example, how can we pipe data from the \texttt{find} command into the \texttt{file} command? \begin{center} \includegraphics{../images/find-file} \end{center} \item This doesn't work: \begin{alltt}\myfs $ \textbf{find /etc | file} Usage: file [-bcikLnNsvz] [-f namefile] [-F separator] [-m magicfiles] file... file -C -m magicfiles Try `file --help' for more information. \end{alltt}%$ \end{itemize} \section{\texttt{xargs} --- an Adapter} \label{sec:xargs-an-adapter} \begin{itemize} \item The \texttt{xargs} command works as an adapter to read standard input, execute another command by passing the intput data to the command line of the second command: \begin{center} \includegraphics{../images/xargs} \end{center} \item We can use \texttt{xargs} as an adapter between \texttt{find} and \texttt{file} to allow them to be part of en efficient pipeline: \begin{center} \includegraphics[width=\textwidth]{../images/find-xargs-file} \end{center} \item We can write it like this: \begin{alltt} $ \textbf{find /etc | xargs file} \end{alltt}%$ \end{itemize} \section{\texttt{xargs}} \label{sec:more-tools-xargs} \begin{itemize} \item Constructs and executes command-lines from information given on standard input \item Commonly used in conjunction with find \item Syntax: \begin{alltt} | xargs command \end{alltt} \item N.B. Data is normally piped to {\cmdn xargs} \item Example: Delete all files named {\fn core} not modified in the past 8 days \begin{alltt} $ \textbf{find / -name "core" -mtime +8 | xargs rm -f} \end{alltt}%$ \item This is more effient than \begin{alltt} $ \textbf{find / -name "core" -mtime +8 -exec rm -f \{\} \bs;} \end{alltt}%$ as it spawns fewer processes, therefore easing the load on the machine \end{itemize} % Nick: TODO: show the processes that are actually executed to make % this all clearer to the student. % Better: make an exercise to show the processes. % What I do is when do find /etc 2>/dev/null | xargs file, can see % each process, since the file types start in a different column. % There seem to be about nine separate file processes when I do it. \section{Options to {\cmdn xargs}} \label{sec:more-tools-xargs-options} %% \begin{tabular}[t]{|p{70pt}|p{275pt}|} \hline %% {\cmdn -p} & Interactive mode \\ \hline %% {\cmdn -t} & Verbose mode \\ \hline %% {\cmdn -n num} & Limit arguments used to command \\ \hline %% \end{tabular} \begin{tabular}[t]{p{70pt}p{275pt}} {\cmdn -p} & Interactive mode \\ {\cmdn -t} & Verbose mode \\ {\cmdn -n num} & Limit arguments used to command \\ \end{tabular} \begin{itemize} \item Verbose mode will print out the commands it executes \item Interactive mode prints out the command-line and awaits confirmation before executing \item {\cmdn -n} tells {\pgn xargs} to use at most {\cmdn num} arguments to the command you are running with {\pgn xargs} \item Example: {\myss \begin{alltt} $ \textbf{find / -name "core" -mtime +8 | xargs -p -n 2 rm -f} rm -f /home/lee/core /home/davef/core ?...\textbf{y} rm -f /usr/local/bin/core /root/core ?...\textbf{y} $ \end{alltt}} \end{itemize} \section{Positioning filenames with {\pgn xargs}} \label{sec:more-tools-xargs-replace} \begin{itemize} \item By default {\pgn xargs} places the filenames at the \emph{end} of the command you give \item If they need to be somewhere else you can use {\cmdn -{}-replace} \item Put {\cmdn \{\}} at the point that you want the filenames inserted \item Example: \begin{alltt}\myss $ \textbf{find /var/log -mtime -0.5 | xargs --replace cp \{\} /tmp} \end{alltt}%$ \item Disadvantage: execute new command process for each file, e.g., \begin{itemize} \item Here, when \texttt{xargs} executes \texttt{echo} just once, i.e., there is one \texttt{echo} process \begin{alltt} $ \textbf{ls} file1 file2 file3 $ \textbf{ls | xargs echo} file1 file2 file3 \end{alltt} \item But when we use \texttt{-{}-replace}, \texttt{xargs} executes \texttt{echo} three times, once for each file, i.e., we have three separate \texttt{echo} processes: \begin{alltt} $ \textbf{ls | xargs --replace echo \{\}} file1 file2 file3 \end{alltt}%$ \end{itemize} \end{itemize} \section{cpio} \label{sec:more-tools-cpio} \begin{itemize} \item Similar to {\pgn tar} \item Creates archives of files \item Operates in {\em copy-in} or {\em copy-out} mode \begin{itemize} \item Copy-out mode writes archives \item Copy-in extracts from them \end{itemize} \item Takes filelist on standard input \begin{itemize} \item Not given on the command line \item Can use \texttt{find} to feed it filenames \end{itemize} %% \begin{tabularx}{\linewidth}[t]{|l|X|} \hline %% {\cmdn -i} & ``Copy-in mode''---extract from archive \\ \hline %% {\cmdn -o} & ``Copy-out mode''---create an archive \\ \hline %% {\cmdn -A} & Append to an archive \\ \hline %% {\cmdn -F file} & Use {\fn file} instead of standard\\&input/output \\ \hline %% {\cmdn -H format} & Use archive format {\cmdn format} \\ \hline %% \end{tabularx} \begin{tabularx}{\linewidth}[t]{lX} {\cmdn -i} & ``Copy-in mode'' --- extract from archive \\ {\cmdn -o} & ``Copy-out mode'' --- create an archive \\ {\cmdn -A} & Append to an archive \\ {\cmdn -F \meta{file}} & Use \meta{file} instead of standard input/output \\ {\cmdn -H \meta{format}} & Use archive format \meta{format} \\ \end{tabularx} \item Example: make a \texttt{cpio} archive of \texttt{/etc}: \begin{alltt} $ \textbf{find /etc | cpio -o -F /tmp/etc.cpio} \end{alltt}%$ \item There are two main reasons for sometimes using {\pgn cpio} instead of {\pgn tar}: \begin{itemize} \item {\pgn cpio} will not include the contents of a directory if you list the directory name as a file. This is good when you want to include some but not all files from that directory. \item The \RPM Package Manager ({\pgn rpm}) provides the {\pgn rpm2cpio} command that allows you to extract individual files from an \RPM package. \end{itemize} \end{itemize} \section{{\cmdn gzip}} \label{sec:more-tools-gzip} \begin{itemize} \item Compresses data taken from {\cmdn stdin} or a file \item {\em`Lossless'} compression \begin{itemize} \item Safe on any file \end{itemize} \item Various compression levels, 1-9 \begin{itemize} \item[1] --- Fast, less compression \item[9] --- Slower, more compression \end{itemize} \item By default takes {\fn filename} and turns it into {\fn filename.gz} {\myss \begin{alltt} $ \textbf{ls foo*} foobar $ \textbf{gzip -9 foobar} $ \textbf{ls foo*} foobar.gz \end{alltt}} %$ \begin{itemize} \item Replaces original file \end{itemize} \item Can write compressed data to {\cmdn stdout} {\myss \begin{alltt} $ \textbf{ls foo*} foobar $ \textbf{gzip -9 -c foobar > foobar.gz} $ \textbf{ls foo*} foobar foobar.gz \end{alltt}}%$ \begin{itemize} \item Leaves original file intact \end{itemize} \end{itemize} \section{Unzipping} \begin{itemize} \item To unzip a file there are two methods \begin{itemize} \item {\cmdn gunzip} \item {\cmdn gzip -d} \end{itemize} \item Really one file linked to two names \item Uncompress all files in the current directory \begin{alltt} $ \textbf{gzip -d *.gz} \end{alltt}%$ \item {\pgn gzip} uses Lempel-Ziv coding \item Can also unpack files created with {\pgn zip}, {\pgn compress} and {\pgn pack} \end{itemize} \section{\texttt{tar}} \label{sec:more-tools-tar} \begin{itemize} \item {\pgn tar} creates archives of files \item Used for transferring files between machines \begin{itemize} \item Or from place to place \end{itemize} \item Options: \smallskip %% \begin{tabular}[t]{|p{90pt}|p{275pt}|} \hline %% {\cmdn -x} & Extract from an archive\\ \hline %% {\cmdn -c} & Create archive \\ \hline %% {\cmdn -t} & List files in an archive \\ \hline %% {\cmdn -v} & Be verbose \\ \hline %% {\cmdn -j} & Compress/decompress archive with {\fn bzip2} \\ \hline %% {\cmdn -z} & Compress/decompress archive with {\fn gzip} \\ \hline %% {\cmdn -d} & Find differences between archive and the filesystem \\ \hline %% {\cmdn -f} & Specifies a file name for the archive. Can be a device, %% such as \texttt{/dev/nst0} \\ \hline %% \end{tabular} \begin{tabularx}{\linewidth}[t]{cY} \toprule {\cmdn -x} & Extract from an archive\\ {\cmdn -c} & Create archive \\ {\cmdn -t} & List files in an archive \\ \midrule {\cmdn -v} & Be verbose \\ {\cmdn -j} & Compress/decompress archive with {\fn bzip2} \\ {\cmdn -z} & Compress/decompress archive with {\fn gzip} \\ {\cmdn -d} & Find differences between archive and the filesystem \\ {\cmdn -f} & Specifies a file name for the archive. Can be a device, such as tape device \texttt{/dev/nst0} \\ \midrule \end{tabularx} \item Can use with or without the dash \end{itemize} \section{\texttt{tar} Examples} \label{sec:more-tools-tar-examples} \begin{itemize} \item {\pgn tar} all files ending in {\fn .tex} into a gzipped~\footnote{Integrated gzipping is available with GNU {\pgn tar}, but may not be available on some proprietary versions of {\pgn tar}.} archive called {\fn alltex.tar.gz} \begin{alltt} $ \textbf{tar cvzf alltex.tar.gz *.tex} \end{alltt}%$ \item Check which files were included \begin{alltt} $ \textbf{tar tvzf alltex.tar.gz} \end{alltt}%$ \item Extract them again \begin{alltt} $ \textbf{tar xvzf alltex.tar.gz} \end{alltt}%$ Same again, but with {\pgn bzip2 compression}: \begin{alltt} $ \textbf{tar cvjf alltex.tar.bz2 *.tex} \end{alltt}%$ \item Check which files were included \begin{alltt} $ \textbf{tar tvjf alltex.tar.bz2} \end{alltt}%$ \item Extract them again \begin{alltt} $ \textbf{tar xvjf alltex.tar.bz2} \end{alltt}%$ \end{itemize} \section{Raw devices and {\pgn tar}} \label{sec:more-tools-tar-with-raw-devices} \begin{itemize} \item Originally designed to talk to magnetic tapes \begin{itemize} \item My SCSI tape device is \texttt{/dev/nst0} \item See kernel documentation in \texttt{/usr/\allowbreak share/\allowbreak{}doc/\allowbreak kernel-doc-2.4.22/\allowbreak{}devices.txt} \end{itemize} \item Can also write to other raw devices \item Useful to maximize use of the space on the floppy \begin{itemize} \item Fit 1.44Mb of data on a floppy \item Don't need any space for filesystem information \end{itemize} {\myss \begin{alltt} $ \textbf{tar cvj filelist > /dev/fd0} \end{alltt}}%$ or simply {\myss \begin{alltt} $ \textbf{tar cvjf /dev/fd0 filelist} \end{alltt}}%$ or simply \item Extract it again \begin{alltt}\myss $ \textbf{tar xvj < /dev/fd0} \end{alltt}%$ or \begin{alltt}\myss $ \textbf{tar xvjf /dev/fd0} \end{alltt}%$ \item A useful option with floppy disks or writable CDROMs is \texttt{-M} \ pro\textbf{M}pt for disk change when full \end{itemize} {\normalsize \section{Exercises} \begin{enumerate} \item Use {\pgn top} to show the processes running on your machine. See section~\vref{sec:more-tools-top}. \item Make {\pgn top} sort the list by memory usage. Press \key{h}, and also see section~\vref{sec:more-tools-top-opts} \item Try killing a process, a good example would be your top process itself! Note that you can only kill your own processes unless you are \texttt{root}. \item Use {\pgn top} to re-nice a process so that it gets more, or less CPU time. You can only lower the priority of your own processes. Only \texttt{root} can raise the priority of a process. Nice value of $-20$ is highest priority. Nice value of 19 gives lowest priority. See \texttt{man nice}. \item Find a full list of every process on your machine and their full command name using {\pgn ps}. See the table in section~\vref{sec:more-tools-ps-options} and the examples in section~\vref{sec:tools-more-ps-examples} \item Get the same view but tell {\pgn ps} to display the output in `family tree' mode. Use the options \texttt{axf} to see the family relationships. See section~\vref{sec:more-tools-ps-options}. \item Request that {\pgn ps} sort it's output by system time used. See section~\vref{sec:sorting-ps-output}. %% \item Display all the filenames under {\fn /usr/sbin} using {\pgn find}. %% \item Display all the filenames under {\fn /usr/sbin} begining with a lowercase `{\kbk c}'. %% \item Display all the files under {\fn /usr/sbin} which are over 5k in size in uppercase. \item Set {\pgn vmstat} running in a spare terminal updating every 5 seconds. See section~\vref{sec:more-tools-vmstat}. \item Set up {\pgn free} in another window doing the same thing. See section~\vref{sec:more-tools-free}. \item Use {\pgn ldd} (see section~\vref{sec:more-tools-ldd}) to find out what shared libraries some common applications use: \begin{enumerate} \item {\fn /sbin/halt} \item {\fn /usr/bin/gnome-session} \item {\fn /usr/bin/display} \item {\fn /bin/bash} \item {\fn /sbin/nash} \end{enumerate} \item See sections~\vref{sec:xargs-background} to \ref{sec:more-tools-xargs-replace} for more about \texttt{xargs}. See section~\vref{sec:more-tools-xargs} for examples of using \texttt{xargs} with \texttt{find}. Practice using {\pgn xargs} by finding sets of files and performing simple (Non-destructive!) operations on them, e.g., \begin{enumerate} \item Find all files in the file system modified in the last 24 hours (see \S\pageref{sec:tools-more-find-expressions}) and make copies of them in a directory called {\fn backup} in your home directory. See section~\vref{sec:more-tools-xargs-replace}. (You may want to redirect standard error to the null device, \path{/dev/null}, both for \texttt{find} and for \texttt{cp}.) Do this two ways: \begin{enumerate} \item Using the \texttt{--replace} option with \texttt{xargs}, described in section~\vref{sec:more-tools-xargs-replace}, and \item Using the \texttt{--target-directory} option to \texttt{cp}. See \texttt{man cp}. \item Which of the two methods is most efficient? See section~\vref{sec:more-tools-xargs-replace}. \end{enumerate} \item Find all files over 5000k and make copies of them in the {\fn backup} directory \item Find all files ending in {\fn .txt} in your home directory and below, and compress them using {\fn bzip2} \end{enumerate} \item Use {\pgn cpio} and {\pgn tar} to create an archive of the files you've copied in to the {\fn backup} directory. See section~\vref{sec:more-tools-cpio} and section~\vref{sec:more-tools-tar} to section \ref{sec:more-tools-tar-with-raw-devices}. % Which do you think is easier to use? Learn one \ldots forget the other! \item Write an archive of {\fn /etc} to a floppy as a raw archive. See section~\vref{sec:more-tools-tar-with-raw-devices}. \end{enumerate} \section{Solutions} \includeversion{Solutions}% \excludeversion{noSolutions}% \begin{Solutions} \begin{enumerate} \item Simply starting {\pgn top} from the command line will show all processes \item Hitting {\usb M} will sort the list by the \emph{resident set size}, which includes all \RAM used by each process, excludes the part that is paged out to the hard disk, but does include memory use shared with other programs. \item Find your top process in the list (It will probably be near the head of a CPU-sorted list. Press {\usb k}. You will be prompted for a process number, give the number from the PID column adjacent to your top process. You are then prompted for a signal to send the process. The default (15) should kill {\pgn top} and return you to your shell prompt. Signal 15 is the TERM signal. You can list all possible signals with the command \texttt{kill~-l}. \item Again find your top process, then press {\usb r}. You are prompted for the PID and a nice value. Unless you are super-user you can only lower the process priority (Give it a higher nice value). \item {\cmdn \$ \textbf{ps auxw}}\\Shows a full list of processes and doesn't truncate the command-line to fit on one output line \item {\cmdn \$ \textbf{ps axf}}\\ Shows the family-tree view. Processes can create child processes using the \texttt{fork()} system call. The family-tree view shows this parent-child relationship. The parent of all processes is the \texttt{init} process, which has process~\ID~1. \item Adding {\cmdn OK} to the first command line should sort the output by system time; to see the system time, you may need to tell \texttt{ps} tp show it, for eaxmple, llke this: \begin{alltt} $ \textbf{ps O user,%cpu,%mem,stime axOK} \end{alltt}%$ The option ``\texttt{O}'' has two purposes: it can be used to select what data \texttt{ps} shows, and it can tell \texttt{ps} how to sort the data. When the option ``\texttt{0}'' is the first option to \texttt{ps}, it tells \texttt{ps} what coluns to display. When it appears anywhere else, it tells \texttt{ps} how to sort the data. In the above exammple, the options \texttt{ax} mean to show data on all the processes, even those that are not attached to a terminal. \begin{alltt} $ \textbf{ps auxw OK} \end{alltt}%$ %% \item %% \begin{alltt} %% $ \textbf{find /usr/sbin -type f} %% \end{alltt}%$ %% \item %% \begin{alltt} %% $ \textbf{find /usr/sbin -type f -name "c*"} %% \end{alltt}%$ %% \item %% \begin{alltt} %% $ \textbf{find /usr/sbin -type f -size +5k | tr 'a-z' 'A-Z'} %% \end{alltt}%$ \item \begin{alltt} $ \textbf{vmstat 5} \end{alltt}%$ \item \begin{alltt} $ \textbf{free -s 5} \end{alltt}%$ \item \begin{enumerate} \item \begin{alltt} $ \textbf{ldd /sbin/halt} libc.so.6 => /lib/tls/libc.so.6 (0x00bd3000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x00d4d000) \end{alltt}%$ \item \begin{alltt} $ \textbf{ldd /usr/bin/gnome-session} libXrandr.so.2 => /usr/X11R6/lib/libXrandr.so.2 (0x0034f000) libXrender.so.1 => /usr/X11R6/lib/libXrender.so.1 (0x00611000) libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0x008ee000) \ldots librt.so.1 => /lib/tls/librt.so.1 (0x0063b000) libnsl.so.1 => /lib/libnsl.so.1 (0x0064f000) libexpat.so.0 => /usr/lib/libexpat.so.0 (0x0075d000) \end{alltt}%$ \item \begin{alltt} $ \textbf{ldd /usr/bin/display} libMagick-5.5.6-Q16.so.0 => /usr/lib/libMagick-5.5.6-Q16.so.0 (0x00701000) libtiff.so.3 => /usr/lib/libtiff.so.3 (0x00d22000) libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x00111000) \ldots libc.so.6 => /lib/tls/libc.so.6 (0x00371000) libdl.so.2 => /lib/libdl.so.2 (0x00c44000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x00e5e000) \end{alltt}%$ \end{enumerate} \item \begin{enumerate} \item \begin{enumerate} \item \begin{alltt} $ \textbf{find / -mtime -1 2>/dev/null | xargs --replace cp \{\} ~/backup 2>/dev/null} \end{alltt}%$ \item \label{que:xargs-with-cp-target-directory}% \begin{alltt} $ \textbf{find / -mtime -1 2>/dev/null | xargs cp --target-directory=~/backup 2>/dev/null} \end{alltt}%$ \item Using \texttt{cp~--target-directory} as shown in question~\ref{que:xargs-with-cp-target-directory} is much more efficient than \texttt{xargs --replace}. \texttt{xargs --replace} creates a separate \texttt{cp} process for each file, whereas using \texttt{cp~--target-directory} allows \texttt{xargs} to call \texttt{cp} only a very small number of times, but each time copying a large number of files. I have explained this in section~\vref{sec:more-tools-xargs-replace}. \end{enumerate} \item Note that it is better to create the \texttt{backup} directory in \texttt{/tmp}, otherwise you will probably cause your network home directory to exceed your allowed storage quota! \begin{alltt} $ \textbf{mkdir /tmp/backup} \end{alltt}%$ Then either: \begin{alltt} $ \textbf{find / -size +5000k 2>/dev/null | xargs --replace cp \{\} /tmp/backup}2>/dev/null \end{alltt}%$ Or better, \begin{alltt} $ \textbf{find / -size +5000k 2>/dev/null | xargs cp --target-directory=/tmp/backup 2>/dev/null} \end{alltt}%$ % \item %% \begin{alltt} %% $ \textbf{find / -name "*.txt" | xargs -n 1 gzip} %% \end{alltt}%$ \item \begin{alltt} $ \textbf{find \(\sim\) -name "*.txt" | xargs gzip} \end{alltt}%$ \end{enumerate} % If we didn't use {\cmdn -n 1} then {\pgn xargs} would produce command lines like % \begin{alltt} % $ \textbf{gzip /etc/foo.txt /var/log/bar.txt moo.txt} % \end{alltt} % Due to the way {\pgn gzip} works this will not produce the desired effect\\ \item \begin{alltt} $ \textbf{find /tmp/backup -type f | cpio -o > cpio_archive.cpio} \end{alltt}%$ and \begin{alltt} $ \textbf{tar czjf tar_archive.tar.bz2 /tmp/backup} \end{alltt}%$ or \begin{alltt} $ \textbf{tar czvf tar_archive.tar.gz /tmp/backup} \end{alltt}%$ \item \begin{alltt} $ \textbf{tar cvz /etc > /dev/fd0} \end{alltt}%$ or \begin{alltt} $ \textbf{tar cvzf /dev/fd0 /etc} \end{alltt}%$ \end{enumerate} \end{Solutions} \begin{noSolutions} We will provide solutions soon. \end{noSolutions} } % End of \normalsize at start of exercises } % end \mns \excludeversion{Solutions}% \includeversion{noSolutions}% %%% Local Variables: %%% mode: latex %%% TeX-master: "planet_masterfile" %%% End: