next up previous contents
Next: Removing Files Up: Basic File Commands Previous: Copying Files

Moving/Renaming Files

Moving a file to a new location and renaming a file are the two functions of the mv command:

  1. mv [options] fromfile tofile
  2. mv [options] fromfile todirectory
  3. mv [options] fromdirectory todirectory

The first form relocates the sourcefile to the location specified by the targetfile. If the sourcefile's name already exists at the destination, and the existing file's mode allows writing, then the existing file will be overwritten. If either interactive mode has been selected (-i argument) or the existing file is write-protected, then the user will be prompted to make certain that overwriting the existing file is the action intended.

The second form is like the first, except that no filename is specified, just a target directory. In this case the source file is moved to the target directory, and the name of the source file is preserved.

If the target directory exists, the third form moves the source directory so that it is a subdirectory of the target. If the target directory does not exist, then the source directory is moved to the path specified in naming the target directory, and is given the target directory's name.

In both the first and third form, if the destination file/directory is in the same directory as the source file/directory, and the source and destination names are different, then the mv command has the effect of renaming the file/directory.



Larry Latour
Fri Sep 12 08:12:59 EDT 1997