Rename Files in Linux

At first it might not be obvious, but you can use the mv command to rename files in Linux. From the terminal, this Linux command can be used to move a file or directory from one location to another or to rename a file or directory. It might also be used to move a file to a different directory whilst renaming it.

How to rename a file in Linux

To rename a file using the mv command in Linux:

  1. Open the terminal. (Ctrl+Alt+T) for Ubuntu/Debian Linux.
  2. Using the cd command, change directory to the location that contains the file you want to rename.
  3. To rename the file, type mv <filename> followed by the <new filename> and then press Enter to execute the command.
    mv name.txt newname.txt

The mv command can also be used to move a file to a different directory while renaming it during the move.

How to rename a file while moving in Linux

To rename file in terminal while moving it to another directory:

  1. Open a terminal.
  2. Type mv <filename> <directory/> to move it to, followed by <new filename>
    mv name.txt newdir/newname.txt

Or you can even use the mv command to rename a folder in Linux.

How to rename a folder in Linux

To rename folder in Linux:

  1. Open a terminal.
  2. Type mv <current folder name> followed by <name for new folder>
    mv folder newfolder

mv command options

Here are some common options you can use with the mv command:

-i : Prompt the user before overwriting an existing file.
-v : Display the name of each file or directory as it is being moved.
-u : Move only when the source file is newer than the destination file or when the destination file does not exist.
-f : Force move, overwrite any existing destination files without prompting.

The syntax is as follows: mv [options] source destination

WARNING: Be cautious when renaming files in Linux, as it can result in unintended consequences if done incorrectly. Always be sure to back up important files before experimenting and attempting to rename them.