OSU Computational Physics - Landau Research Group (nacse) -
Next 5.I: Moving Directories  Up 5: Managing Files and Directories  Prev 5.G: Copying Directories  Contents

Basic

§ 5.H:  Moving Files


The mv command in Unix "moves" files and directories from one location (or name) to another. Its action is similar to copying with cp and then removing the original with rm. The "move" command mv is safer and more precise. It's safer because if Unix cannot create the new file, it will not remove the old one. It's more precise because it preserves the original creation date of the file.

The syntax for the "move" mv command is almost identical to that of the "copy" command cp. Simply enter the name of the file or directory you wish to move from, and then the name of the file or directory you wish to move to:

> mv -i a.out program
> mv -i a.out development/prog

The first command moves the file a.out in your working directory to the file program in your working directory. The second command moves the file a.out in your working directory to a file with the same name in the development/prog directory.

The interactive option -i is important as it may save you a lot of heartache. It makes Unix ask your permission before it writes over an existing file.

Like the cp command, the mv command also works for directories (except the -r option is not needed or permitted). To move the development/backup directory and its contents to the development/prog directory, enter:

> mv -i development/backup development/prog


5.I: Next 5.I: Moving Directories  Up 5: Managing Files and Directories  Prev 5.G: Copying Directories  Contents

Comments and questions to CP-unix@physics.orst.edu.