Rename File In Unix

Unix operating system provides different commands in order to rename single or multiple files. The Unix operating systems like FreeBSD, NetBSD, OpenBSD, macOS, HP-UX, Solaris, AIX provide the rename and mv commands in order to rename files.

mv Command

The mv command is created to move files and folders but it can work as a file renaming tool perfectly. We can use the mv command to move files in the same directory and specify different names which simply changes the file name. The mv command is provided by default in Unix. The syntax of the mv command is like below.

mv OPTION OLD_NAME NEW_NAME
  • OPTION is used to specify different options. This is optional.
  • OLD_NAME is the previous name of the file. This is required.
  • NEW_NAME is the new name of the file. This is required.

Let’s make some examples about how to rename a file. In the following example, we change the name of the file “myfile.txt” into the “backup.txt”.

mv myfile.txt backup.txt

rename Command

The original command to rename files is the rename command. But mv is so popular and useful it is generally not used regularly. Even it is not installed by default in most of the Unix operating systems. In order to use rename command, it should be installed. The rename command has the following syntax.

rename OPTION OLD_NAME NEW_NAME
  • OPTION is the option for the rename operation. This is optional.
  • OLD_NAME is the previous name of the file. This is required.
  • NEW_NAME is the new name of the file. This is required.

Let’s make some examples about how to rename a file. In the following example, we change the name of the file “myfile.txt” into the “backup.txt”.

mv myfile.txt backup.txt

Leave a Comment