# How to Rename Files and Folders in Linux

Canonical URL: https://pendrivelinux.com/linux-rename-file/
Published: 2023-05-02
Last modified: 2026-11-28
Description: Learn how to rename files and folders in Linux with mv, handle filenames with spaces, and batch rename files with the rename command or Bash.

---

To rename a file or directory in Linux, use the `mv` command followed by the current name and the new name. For example, `mv oldname.txt newname.txt` renames a file in the current directory. You can also use `mv` to rename a folder or move a file while giving it a new name.

## How to Rename Files and Folders in Linux

![linux rename file](https://pendrivelinux.com/wp-content/uploads/linux-rename-file-600x600.webp)

If you want to rename a file, or rename multiple files in batch, or automate Linux file renaming in bulk using scripts, this tutorial will show you the best ways to do so.

### Why Rename Files in Linux?

- **Standardizing file names** – Keeping files well-organized by following a consistent naming convention.
- **Fixing typos** – Correcting mistakes in file names.
- **Changing file extensions** – Converting files from one format to another.
- **Batch renaming** – Using scripts or wildcard characters to rename multiple files.
- **Removing spaces or special characters** – Ensuring compatibility with scripts and applications.
- **Updating version numbers** – Keeping track of different versions of files.
- **Enhancing security** – Renaming files to obscure their contents.
- **Automating renaming tasks** – Using scripts to rename files systematically.

## Rename Files in Linux Using mv Command

![Rename files in Linux using the mv command](https://pendrivelinux.com/wp-content/uploads/rename-files-in-linux-600x450.webp)

The [mv command in Unix based environments](https://en.wikipedia.org/wiki/Mv_%28Unix%29), including Linux is primarily used to move files, but when used correctly, it also serves as a file renaming tool. Below are some common scenarios where you may need to rename files:

### Basic Syntax of mv Command

The basic syntax of the **mv** command is:

```
mv [options] old_filename new_filename
```

For example, to rename a file called `document.txt` to `new_document.txt`:

```
mv document.txt new_document.txt
```

This command renames the file without changing its location. If a filename contains spaces, put each path in quotes:

```
mv "old report.txt" "new report.txt"
```

### How to Rename File in Terminal from Linux

Follow these steps to rename a file in Linux:

1. Open the terminal (**Ctrl+Alt+T** for Ubuntu/Debian Linux).
2. Navigate to the directory containing the file using the `cd` command:

```
cd /path/to/directory
```

3. Rename the file using the following command:

```
mv oldfilename.txt newfilename.txt
```

This renames `oldfilename.txt` to `newfilename.txt`.

### Rename a File While Moving it to a Different Directory

To rename and move a file at the same time, use:

```
mv filename.txt /new_directory/new_filename.txt
```

This moves `filename.txt` to `/new_directory/` and renames it to `new_filename.txt`.

### How to Rename a Folder in Linux

To rename a directory (folder) in Linux, use the following command:

```
mv old_folder new_folder
```

This changes the name of `old_folder` to `new_folder`.

## Advanced File Renaming Techniques

### Batch Rename Multiple Files Using mv and Shell Scripts

Renaming multiple files manually can be time consuming. You can use a simple shell script to rename Linux files in bulk.

For example, to rename all `.txt` files in a directory by adding a prefix `new_`, run:

```
for file in *.txt; do mv "$file" "new_$file"; done
```

This script loops through all `.txt` files and renames them.

### Batch Rename Files Using the rename Command

Some Linux distributions include a Perl-based `rename` utility for batch renaming, but it may need to be installed separately. The example below uses the Perl version; other programs named `rename` can have different syntax:

```
rename 's/old/new/' *.txt
```

This renames all `.txt` files, replacing "old" with "new" in filenames.

### Using find and mv for Complex Renaming

To rename all `.jpg` files in subdirectories and convert them to lowercase:

```
find . -type f -name "*.JPG" -exec rename 'y/A-Z/a-z/' {} \;
```

This command finds all `.JPG` files and renames them in lowercase.

## mv Command Options

The `mv` command comes with several useful options:

- `-i` : Prompts before overwriting an existing file.
- `-v` : Displays each file being moved.
- `-u` : Moves only if the source file is newer than the destination.
- `-f` : Forces move, overwriting without confirmation.

**Example with options:**

```
mv -i oldfile.txt newfile.txt
```

This prompts before renaming if `newfile.txt` already exists.

## Common Errors & Troubleshooting

### Permission Denied

If you get a "Permission Denied" error, try running the command as sudo:

```
sudo mv oldfile.txt newfile.txt
```

### File or Directory Not Found

Ensure you are in the correct directory by using:

```
ls
```

If the file is in another directory, specify the full path:

```
mv /home/user/oldfile.txt /home/user/newfile.txt
```

### mv Command Not Found

If you see `mv: command not found`, ensure your system has core utilities installed:

```
sudo apt-get install coreutils   # Debian/Ubuntu
sudo yum install coreutils      # CentOS/RHEL
```

#### Conclusion on using Linux to Rename Files

The `mv` command is a powerful tool for renaming files and directories in Linux. Whether renaming single files, batch renaming multiple files, or automating file renaming with scripts, Linux provides multiple ways to get the job done efficiently.

**Need more Linux command tips?** Check out [Loop Commands in Shell or Batch Scripts](https://pendrivelinux.com/for-linux-command/) to automate file renaming tasks!
