Renaming and Moving Files

The mv command does double duty: It renames and moves files. Its syntax is much like that of cp:

mv [options] source destination

When you specify a complete filename for the destination, mv renames the file. When the destination is a directory, mv moves the file (keeping the old filename). When the destination is a complete filename in another directory, mv moves and renames the

You can use many of the same options with mv that you use with cp or In. In particular, from Table 5.2, -b, -f, -i, and -u all apply. The -p option isn't available because mv doesn't alter permissions, ownership, or time stamps.

You can apply mv to a directory, but only when the target location is on the same filesystem as the original. If you want to move an entire directory tree from one partition to another, you'll have to use cp with its recursive option (or better, -a, to preserve permissions, symbolic links, and so on), tar, or some other tool to copy the files, and then delete the original files with rm and its recursive option.

0 0

Post a comment