Datasheet

Task 1.2: Manage Files and Directories
13
Depending upon your configuration, you might or might not be prompted before rm deletes
each individual file. If you’re prompted and don’t want to be, you can add the -f option; if
you’re not prompted but you do want to be, you can add the -i option.
The contents of /etc/X11 vary somewhat from one system to another. Thus,
you might need to modify these examples on your system.
Moving and Renaming Files
Linux uses a single command to handle both the move and rename operations: mv. To use this
command, type it followed by the current name of a file and then the new name or location
of the file. For instance, to rename the /home/project7/X11/chooser.sh file to /home/
project7/X11/chooser, you’d type this:
# mv /home/project7/X11/chooser.sh /home/project7/X11/chooser
If the target name for the file is a directory, mv moves the file to that directory without
renaming the file. If the target name is a file in a directory other than the original directory, mv
moves and renames the file. You can specify more than one source file, but in that case the tar-
get must be a directory.
If the source and destination locations for the file are on the same partition, mv does its
work by rewriting directory entries; thus, it can operate quite quickly, even if it’s operating on
a large file. If you move a file from one partition or removable disk to another, though, mv
must copy the file and then delete the original. This operation is likely to take longer, partic-
ularly with large files.
Setting File and Directory Ownership
In Linux, all files and directories have owners. These owners are Linux accounts, such as your
user account or root. Files and directories are also tied to Linux groups, which are collections
of accounts. By default, mkdir creates directories that are owned by the user who issued the
command and with group ownership by that user’s default group. After you create a directory
as root, you can adjust the directory’s ownership by using the chown command:
# chown fred:users /home/project7
This example assumes the presence of the fred account and the users group.
You may need to adjust it for your system.
This command gives ownership of the /home/project7 directory to the user fred and the
group users. You may separate the username and group name with either a colon (:), as shown
in this example, or a dot (.). You may apply the chown command to both directories and files.
If you omit the username, chown changes the group of the file or directory without changing the
83484.book Page 13 Monday, September 18, 2006 8:58 AM