Datasheet
Task 1.7: Use Streams, Pipes, and Redirection
33
Don’t modify a user account when that user is logged in; certain changes are
likely to wreak havoc with work the user is doing. Wait for the user to log out,
or if a change must be implemented immediately, ask the user to log out.
Changing the account’s home directory won’t move the files in the directory. To do that,
you must use the cp command. In this case, the -a option to cp will copy the entire directory
tree and preserve ownership, permissions, and other file characteristics. You’ll then delete the
original directory:
# cp -a /home2/dsmith /home/dsmith
# rm -r /home2/dsmith
To be 100 percent safe, though, you might want to check that the new directory contains
all the files it should before deleting the old one. If possible, wait for the user to log in and use
the account before deleting the old directory.
Criteria for Completion
To complete this task, you should have created a new account (tbrown), deleted an old account
(sjones), and changed the home directory location of a third account (dsmith), including mov-
ing its files. The three commands used to perform this task (useradd, userdel, and usermod)
are at the core of Linux account management. The passwd command is also critical in that it
enables you to set a password on new accounts so that they’re usable. File-manipulation com-
mands such as cp and rm help you manage the files that are associated with accounts.
Task 1.7: Use Streams, Pipes,
and Redirection
The command-line tools introduced earlier enable you to interact with your Linux system at the
command line, typing commands and viewing their output. Sometimes, though, you might want
to do more with that output than simply view it; for instance, you might want to store it in a file
or pass it as input to another program. Fortunately, Linux provides the means to do just that. In
Linux, input and output operations are described as streams. Standard input and output streams
may be redirected to send output to or read input from a regular file, or piped between two pro-
grams. These capabilities provide a great deal of flexibility, as you’ll soon learn.
Part of the Unix philosophy to which Linux adheres is, whenever possible, to
do complex things by combining multiple simple tools. Redirection and pipes
help in this task by enabling simple programs to be combined together in
chains, each link feeding off of the output of the preceding link.
83484.book Page 33 Monday, September 18, 2006 8:58 AM










