How to rename files and directories in Linux?

You can use Linux mv command to rename a file or directory provided the destination file or directory does not exist.

In the case of a file, if the destination is a file and it exists, mv will try to overwrite the destination file with the content of the source file. If the destination is a directory, mv command will move the source file inside the destination directory.

In the case of a directory, if the destination directory exists, mv command will move the source directory inside the destination directory and if the destination directory does not exist, mv command will rename the destination directory with the source directory name.

Leave a Reply