UNIX Renaming a File

Unix does not have a command specifically for renaming files. Instead, the mv command is used both to change the name of a file and to move a file into a different directory.

To change the name of a file, use the following command format (where thirdfile and file3 are sample file names):

mv thirdfile file3

This command results in the complete removal of thirdfile, but a new file called file3 contains the previous contents of thirdfile.

Like cp, the mv command also overwrites existing files. For example, if you have two files, fourthfile and secondfile, and you type the command

mv fourthfile secondfile

mv will remove the original contents of secondfile and replace them with the contents of fourthfile. As a result, fourthfile is renamed secondfile, but in the process secondfile is deleted.

原文地址:https://www.cnblogs.com/JasperZhao/p/12892822.html