How to Rename a File in Linux: Commands, Options, and When to Use Each

Renaming files in Linux is one of those tasks that looks simple on the surface but opens up into a surprisingly rich set of tools and techniques. Whether you're managing a handful of config files or batch-renaming thousands of media files, Linux gives you multiple ways to get the job done — each with its own strengths depending on your workflow and comfort level.

The Core Command: mv

The primary tool for renaming files in Linux is the mv command — short for "move." While most people associate it with moving files between directories, renaming is technically just moving a file to the same location with a different name.

Basic syntax:

mv oldfilename.txt newfilename.txt 

That's it. If both filenames point to the same directory, the file stays put but gets a new name. If you include a different path in the destination, the file moves and gets renamed simultaneously.

Example — rename and move at the same time:

mv /home/user/documents/report_draft.txt /home/user/desktop/report_final.txt 

This is one of the reasons mv is so widely used: it handles two common operations in a single command.

Useful mv Flags to Know

FlagWhat It Does
-iPrompts before overwriting an existing file
-nNever overwrites an existing file silently
-vVerbose — prints what was renamed
-uOnly renames if the source is newer than the destination

The -i flag is worth building into your habits early, especially when working in directories with lots of similarly named files. Accidentally overwriting a file with mv is easy to do and hard to undo without a backup.

Renaming Files with a GUI File Manager

If you're running a desktop environment like GNOME, KDE Plasma, or XFCE, renaming files works much like it does on Windows or macOS:

  • Right-click the file → Rename
  • Or click once to select, then press F2

This is perfectly valid for occasional, manual renames. The GUI approach becomes limiting when you need to rename files in bulk or apply pattern-based naming rules — that's where the terminal earns its place.

Batch Renaming: The rename Command 🗂️

For renaming multiple files at once, the rename command is the standard tool. There are two common versions of it, and which one you have depends on your Linux distribution:

  • Perl-based rename (common on Debian, Ubuntu)
  • util-linux rename (common on Red Hat, CentOS, Fedora)

They work differently, so it's worth checking which version is installed:

rename --version 

Perl-based rename syntax:

rename 's/oldtext/newtext/' *.txt 

This uses a Perl regular expression to find and replace patterns in filenames. For example, replacing spaces with underscores across all .jpg files:

rename 's/ /_/g' *.jpg 

util-linux rename syntax:

rename oldtext newtext *.txt 

Simpler string-matching — no regex required. Less flexible, but faster to write for straightforward substitutions.

When batch renaming matters

Batch renaming comes up constantly in real-world Linux use:

  • Standardizing file extensions (.jpeg.jpg)
  • Adding date prefixes to log files
  • Stripping special characters from filenames before uploading to a server
  • Renaming sequences of photos, audio files, or video exports

The difference between doing this manually for 5 files versus 500 is the difference between an afternoon task and a two-second command.

Using find Combined with mv for Conditional Renaming

For more surgical work — renaming files only in specific subdirectories, or only files older than a certain date — combining find with mv gives you fine-grained control.

Example — rename all .log files older than 7 days:

find /var/logs -name "*.log" -mtime +7 -exec mv {} {}.old ; 

This appends .old to any .log file not modified in the last 7 days. It's a common pattern for archiving logs without deleting them outright.

find paired with -exec is powerful but requires care — always test with -print first to preview which files would be affected before making changes.

Case Sensitivity: A Linux-Specific Consideration 🔤

Unlike Windows, Linux filesystems are case-sensitive. This means Report.txt, report.txt, and REPORT.TXT can all coexist in the same directory as three separate files.

This matters when renaming because:

  • mv report.txt Report.txt may or may not work as expected depending on your filesystem
  • On case-sensitive ext4 filesystems, a two-step rename (mv report.txt temp.txt && mv temp.txt Report.txt) is often the safer route
  • Scripts or automated tools that assume case-insensitivity can produce unexpected results

Most Linux filesystems — ext4, XFS, Btrfs — are case-sensitive by default. Some network-mounted or cloud filesystems may behave differently.

Skill Level Shapes Which Tool Fits

A beginner renaming a single config file has completely different needs than a system administrator batch-processing thousands of log files on a remote server. The tools exist on a spectrum:

  • mv in a GUI terminal → low barrier, good for single files
  • rename with simple strings → moderate complexity, good for repetitive patterns
  • rename with regex → higher skill floor, handles complex pattern matching
  • find + mv pipelines → advanced, best for conditional or recursive operations

Where you land on that spectrum depends on your Linux experience, the volume of files you're working with, and how much time you want to invest in learning regex versus just getting the job done.

The right approach for renaming files in Linux isn't universal — it's specific to what you're actually working with, what your filesystem looks like, and how comfortable you are with the command line.