Tutorial2026-11-0812 min read

How to Rename Files in Linux: mv, rename, Bash Loops and GUI Tools

To rename a file in Linux, use the mv command: mv old-name.txt new-name.txt. The same command renames a directory: mv old-folder new-folder. To rename many files at once by pattern, use the rename command or a short bash loop, and in a desktop file manager just select the file and press F2.

There is no separate single-file rename command because, to Linux, renaming is just moving a file to a new name in the same place, which is why mv does both jobs. Below are the safe ways to use it, the two incompatible rename commands you will meet on different distributions, tested bash loops for common bulk renames, recursive renames with find, and the graphical file renamers that ship with GNOME, KDE and Xfce.

The mv, loop and find examples were tested with bash on Ubuntu 24.04. Try them on a copy of your files first.

Rename a File with mv

The basic form is mv SOURCE DEST:

mv report.txt report-2026.txt

If the file is somewhere else, give the path. The file stays in the same directory as long as the new path points there too:

mv ~/Documents/draft.md ~/Documents/final.md

mv prints nothing when it succeeds. It also does not ask before replacing a file that already has the new name: if report-2026.txt existed, it is silently overwritten. These options make it safer:

  • -i (interactive): asks before overwriting an existing file.
  • -n (no-clobber): never overwrites; if the target exists, the rename is skipped.
  • -v (verbose): prints each rename, for example renamed 'a.txt' -> 'b.txt'.
  • -b (backup): if the target exists, keeps the old one as name~ before overwriting.

A good habit for one-off renames is mv -iv:

mv -iv notes.txt meeting-notes.txt

Names with spaces and special characters

Quote any name that has spaces, brackets, quotes, &, * or other characters the shell treats specially:

mv "Quarterly Report (draft).pdf" quarterly-report-draft.pdf

Single quotes work too, and stop the shell from expanding $ or !. Pressing Tab to auto-complete a name will insert the right escaping for you.

Names that start with a dash

A file called -notes.txt confuses mv, which reads it as an option. Put -- before the file names to mark the end of options, or prefix the name with ./:

mv -- -notes.txt notes.txt
mv ./-notes.txt notes.txt

All the loops below use -- for the same reason.

Renaming vs moving

mv renames when the destination is a new name in the same directory and moves when the destination is a different directory. If the destination is an existing directory, the file goes inside it and keeps its name:

mv photo.jpg ~/Pictures/          # move, keeps the name photo.jpg
mv photo.jpg ~/Pictures/beach.jpg # move and rename in one step

Within one file system, a rename or move is instant regardless of file size, because only the directory entry changes.

Rename a Directory in Linux

Renaming a folder uses the same command, and you do not need -r:

mv old-folder new-folder

There is one trap. If new-folder already exists, mv moves old-folder inside it, leaving you with new-folder/old-folder instead of a rename. Check first with ls, or use GNU mv's -T option, which treats the destination as a name rather than a directory to move into:

mv -T old-folder new-folder

With -T, if new-folder exists and is not empty, mv refuses with "Directory not empty" instead of nesting the folder (if it exists and is empty, it is replaced). Renaming a directory needs write permission on the directory that contains it; use sudo only for system paths you are sure about.

The rename Command (Two Different Tools)

For pattern-based renames across many files, most distributions offer a command called rename. The confusing part is that there are two unrelated programs with that name and different syntax.

How to tell which rename you have

Run:

rename --version
  • If the output mentions File::Rename or Perl, you have the Perl rename. This is what Debian and Ubuntu install from the rename package.
  • If it says rename from util-linux, you have the util-linux rename, the default on Fedora, RHEL, CentOS Stream and Arch.
  • If you get "command not found", nothing is installed. On Ubuntu and Debian, sudo apt install rename installs the Perl version. Debian and Ubuntu also ship the util-linux version as rename.ul, and Arch packages the Perl version as perl-rename.

Perl rename (Debian, Ubuntu): rename 's/old/new/' files

The Perl version takes a Perl expression, usually a substitution, and applies it to each file name:

rename 's/\.jpeg$/.jpg/' *.jpeg

That changes the .jpeg extension to .jpg. The dot is escaped (\.) because in a regular expression an unescaped dot matches any character, and $ anchors the match to the end of the name.

Always do a dry run first with -n, which prints what would happen without renaming anything:

rename -n 's/\.jpeg$/.jpg/' *.jpeg

Useful Perl rename recipes:

rename -n 's/ /_/g' *            # spaces to underscores (g = every match)
rename -n 'y/A-Z/a-z/' *          # uppercase to lowercase
rename -n 's/^/2026-/' *.pdf      # add a prefix
rename -n 's/IMG_//' *.jpg        # remove text
rename -n 's/(\d+)/sprintf("%04d",$1)/e' *.png   # zero-pad the first number

Remove -n when the output looks right, and add -v to see each change as it happens. Perl rename will not overwrite an existing file unless you pass -f. If you know regular expressions from other tools, see our guide to renaming files with regex for more patterns.

util-linux rename (Fedora, RHEL, Arch): rename from to files

The util-linux version does plain text replacement, no regular expressions:

rename .jpeg .jpg *.jpeg

The syntax is rename FROM TO FILES: in each file name, the first occurrence of FROM is replaced with TO. Useful options:

  • -n (no-act): do not rename anything. On its own it prints nothing, so combine it with -v.
  • -v (verbose): show each rename.
  • -o (no-overwrite): skip renames that would replace an existing file.
  • -a (all): replace every occurrence of FROM, not just the first (util-linux 2.38 and later).

So the dry run is:

rename -nv .jpeg .jpg *.jpeg

Because util-linux rename only swaps fixed strings (no patterns), it is great for extensions and prefixes but cannot change case or match by pattern. Use a bash loop for those. For more on extensions specifically, see how to bulk rename file extensions.

Bulk Rename with Bash Loops

A for loop with mv works on every distribution, needs nothing installed, and is easy to preview. The pattern is always the same: loop over a glob, build the new name with bash parameter expansion, then mv -n -- the file.

To preview any loop, put echo in front of mv. The loop prints the commands instead of running them. Remove echo when the output is right.

Change file extensions

for f in *.jpeg; do
  mv -n -- "$f" "${f%.jpeg}.jpg"
done

${f%.jpeg} removes .jpeg from the end of the name.

Replace spaces with underscores

for f in *\ *; do
  mv -n -- "$f" "${f// /_}"
done

*\ * matches names containing a space, and ${f// /_} replaces every space. Change _ to - for hyphens.

Convert names to lowercase

for f in *; do
  [ -f "$f" ] || continue
  new="${f,,}"
  [ "$f" != "$new" ] && mv -n -- "$f" "$new"
done

${f,,} lowercases the whole name (bash 4 or later, which every current Linux distribution has). The [ -f "$f" ] test skips directories, and the comparison skips names that are already lowercase.

Add a prefix or suffix

for f in *.jpg; do
  mv -n -- "$f" "trip-$f"
done

for f in *.pdf; do
  mv -n -- "$f" "${f%.pdf}-signed.pdf"
done

Number files sequentially

n=1
for f in *.jpg; do
  printf -v new 'photo-%03d.jpg' "$n"
  mv -n -- "$f" "$new"
  n=$((n + 1))
done

This produces photo-001.jpg, photo-002.jpg and so on, in alphabetical order of the old names. %03d pads to three digits so the files sort correctly; use %04d for more than 999 files. If some files are already called photo-001.jpg and so on, -n will skip those collisions, so start from a clean set or use a different base name. Our guide to renaming files in sequence covers ordering by date instead.

Why the quoting matters

Every "$f" is in double quotes. Without them, a file named my photo.jpg is split into two arguments and mv fails or, worse, acts on the wrong files. Never parse the output of ls in a loop; the glob (*.jpg) already handles every character safely.

If a glob matches nothing, bash passes the pattern itself (*.jpeg) to mv, which just reports "No such file or directory". Run shopt -s nullglob first if you want the loop to do nothing in that case.

Recursive Renames with find

Globs only match the current directory. To rename files in subdirectories too, use find with -execdir, which runs the command from inside each file's directory:

find . -type f -name '*.jpeg' -execdir sh -c 'mv -n -- "$1" "${1%.jpeg}.jpg"' _ {} \;

The _ fills $0, so the file name arrives as $1. Preview by changing mv to echo mv.

To replace spaces in both files and directory names, add -depth so find renames the contents of a directory before the directory itself (otherwise it loses track of paths it has just renamed):

find . -depth -name '* *' -execdir bash -c 'mv -n -- "$1" "${1// /_}"' _ {} \;

With the Perl rename installed, the same job is shorter:

find . -depth -name '* *' -execdir rename -n 's/ /_/g' {} +

Run it with -n, read the output, then run it again without -n.

mmv: Wildcard-to-Wildcard Renames

mmv lets you write the rename as a pair of patterns, where #1, #2 and so on refer to whatever the first, second wildcard matched. It is not installed by default; on Ubuntu, sudo apt install mmv.

mmv '*.jpeg' '#1.jpg'
mmv 'IMG_*.jpg' 'holiday-#1.jpg'

Quote both patterns so the shell does not expand them. mmv checks the whole set for collisions before it renames anything, and -n shows what it would do.

Edit File Names in a Text Editor

If you prefer editing names by hand but quickly, two tools open the directory listing in your text editor and rename whatever you change when you save: vidir from the moreutils package and qmv from renameutils. They are a good middle ground when each file needs a different name and a regex would be overkill.

Linux File Renamer Apps (GUI)

You do not need the terminal at all for most renames.

GNOME Files (Nautilus): Ubuntu, Fedora Workstation

  • One file: select it and press F2, or right-click > Rename. Type the name and press Enter.
  • Many files: select them and press F2. The batch rename dialog offers Rename using a template (base name plus automatic numbering, with options such as original name and creation date) or Find and replace text, with a live preview of the new names.

Dolphin (KDE Plasma)

Press F2 on one file to rename it inline. Select several files and press F2 to open the batch dialog, where # in the new name becomes a number: trip-### gives trip-001, trip-002 and so on.

Thunar (Xfce)

Select several files and choose Rename from the right-click menu to open Thunar's Bulk Renamer, which can insert or remove characters, number files, change case, and search and replace (optionally with regular expressions). You can also launch it directly with thunar --bulk-rename.

KRename

KRename is a dedicated batch renamer for KDE (installable on any desktop), with numbering, case changes, find and replace, and tokens for metadata such as photo EXIF dates and music tags. It is the closest Linux equivalent to Windows tools like Bulk Rename Utility; see our roundup of free file renamer tools for others.

Content-aware renaming

All of the above rename by pattern. None of them can look at scan_0042.pdf or IMG_2231.jpg and tell you it is a lease agreement or a photo of a whiteboard. For that, File Renamer AI runs in any browser on Linux: upload photos, PDFs or Office documents, review the descriptive names it suggests, and download the renamed files as a ZIP.

Safety: Dry Runs, Backups and Undo

Linux has no undo for mv or rename. A few habits prevent most mistakes:

  • Preview every bulk rename. Use rename -n (Perl), rename -nv (util-linux), mmv -n, or echo mv in a loop.
  • Never overwrite by accident. Use mv -n or mv -i in scripts; one bad pattern can map many files to the same name, and without -n each mv overwrites the last.
  • Work on a copy for big jobs. cp -a photos photos-backup takes seconds and makes any mistake recoverable.
  • Keep a log. Run the rename with -v and redirect the output to a file (mv -v ... >> rename.log). The log lists every old and new name, which is everything you need to reverse it.
  • Watch out for case-only renames on shared drives. On a case-insensitive file system such as a FAT32 or exFAT USB stick, renaming Photo.jpg to photo.jpg can fail or appear to do nothing. Rename to a temporary name first, then to the final one.

For naming patterns worth standardising on, see our file naming conventions guide. If you also work on other systems, the companion guide how to rename a file covers Windows, Mac and mobile.

Frequently Asked Questions

What is the Linux command to rename a file?

The command is mv, short for move. Type mv followed by the current name and the new name, for example mv old.txt new.txt. Linux has no separate single-file rename command because renaming a file is the same operation as moving it to a new name in the same directory.

How do I rename a directory in Linux?

Use mv with the old and new directory names: mv old-folder new-folder. No recursive flag is needed. If a directory with the new name already exists, mv moves the old directory inside it instead, so check first or use mv -T, which never nests it: it refuses if the existing directory has files in it.

What is the difference between mv and rename in Linux?

mv renames one file or directory to a name you type. rename changes many files at once using a pattern. On Debian and Ubuntu, rename is the Perl version and takes a substitution like rename 's/old/new/' files. On Fedora, RHEL and Arch, rename is the util-linux version and takes plain text: rename old new files.

Why does rename say "command not found" on Ubuntu?

The rename command is not always installed by default on Ubuntu. Install the Perl version with sudo apt install rename. Debian and Ubuntu also include the simpler util-linux version as rename.ul.

How do I rename multiple files at once in Linux?

Use the rename command with a pattern (for example rename 's/\.jpeg$/.jpg/' *.jpeg on Ubuntu), a bash for loop with mv, or a graphical tool: select the files in GNOME Files or Dolphin and press F2 to open the batch rename dialog. Always preview the result first with rename -n or by putting echo before mv in a loop.

How do I rename a file with spaces in its name?

Wrap the name in quotes: mv "my file.txt" my-file.txt. You can also escape each space with a backslash or press Tab to let the shell complete and escape the name for you.

Can I undo a rename in Linux?

Not automatically. mv and rename have no undo, so the only way back is to rename the files again. Before a bulk rename, preview it with a dry run, copy the folder as a backup, and run the real rename with -v so you have a record of every old and new name.

Ready to organize your files?

Try AI renaming right away. No sign-up needed until you download.

Try It Free