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.

posted @ 2020-05-15 08:52  Jasper2003  阅读(112)  评论(0编辑  收藏  举报