Datasheet

Task 1.2: Manage Files and Directories
11
Setup
You need perform no special setup to do this task; just log into your computer and acquire
root privileges.
Caveats
Because this task is performed as root and uses powerful file-manipulation commands, a
potential for devastating errors exists. Certain typos, when entered as root, can obliterate an
entire Linux installation. Be very careful when performing this task, or any other task that
requires root privileges. When you type a command, remove your hands from the keyboard,
proofread the command, and be sure it’s the correct command before you press the Enter key
to finalize it.
All of these commands can be used by ordinary users, with the partial exception of chown;
only root may use chown to change the primary owner of a file, although ordinary users may
use chown to change the group of a file. These examples show root using the commands
because the task is an administrative one that requires root privileges because of the locations
of the files.
Procedure
To perform this task, you must create a shared directory, copy files to the new directory,
remove extraneous files, and set the ownership and permissions on the new directory and the
files you’ve copied. These actions utilize some of the most important Linux file-manipulation
commands, such as mkdir, cp, rm, chown, and chmod.
Creating a Shared Directory
To create the shared directory, use the mkdir command, which creates (makes) a directory
(hence the command’s name). This command takes the name of the directory you want to create
as an argument. For instance, to create a directory called /home/project7, you’d type this:
# mkdir /home/project7
Thereafter, the /home/project7 directory should exist. By default, this directory is owned
by the user who issued the mkdir command and has permissions based on the defaults for that
user. You can tell mkdir to create a directory with specific permissions by adding the -m mode
option between mkdir and the directory name. Another method of adjusting permissions is
described shortly, in “Setting File and Directory Permissions.”
Ordinarily, mkdir doesn’t create directories in the path up to the final directory specified;
for instance, if /home didn’t exist, the preceding command would return an error message.
Adding the -p or --parents option, though, causes mkdir to create intervening directories.
This can be handy, but it also means that if you mistype a directory name (say, /hom instead
of /home), mkdir will merrily create a new directory tree named after your typo.
83484.book Page 11 Monday, September 18, 2006 8:58 AM