Updated: 28 September 2026 · Applies to: util-linux rename on AlmaLinux and Rocky Linux 9 and 10 and RHEL 9 and 10; Perl rename on Ubuntu 24.04 and 26.04 and Debian 13; bash on all

Renaming many folders (or files) by hand is slow and error-prone. Linux has a rename command for this, but two different programs share that name, with different syntax. Check which one you have first. We tested both versions below, on AlmaLinux 9 and Ubuntu 24.04.

Which rename do you have?

rename --version
  • Output mentioning util-linux: the simple version, standard on AlmaLinux, Rocky Linux and RHEL.
  • Output mentioning File::Rename or Perl: the Perl version, from the rename package on Ubuntu and Debian (apt install rename).

util-linux rename (AlmaLinux, Rocky Linux, RHEL)

Syntax: rename FROM TO FILES. It replaces the first occurrence of the text FROM in each name.

rename -n backup archive backup*     # preview: show what would happen
rename -v backup archive backup*     # do it and show each change

"backup 2024" becomes "archive 2024". On version 10 (util-linux 2.40), -a replaces every occurrence in a name and -l only the last one; version 9 (util-linux 2.37) does not have these options.

Perl rename (Ubuntu, Debian)

It takes a Perl expression, which allows much more:

rename -n 's/backup/archive/' backup*     # preview
rename 's/ /_/g' *                          # spaces to underscores
rename 'y/A-Z/a-z/' *                       # upper case to lower case
rename 's/^/2026-/' *                       # add a prefix

Without rename: a bash loop

This works everywhere and handles spaces in names safely:

for d in backup*/; do
  d=${d%/}
  mv -v -- "$d" "${d/backup/archive}"
done

backup*/ matches only folders. Test such a loop first by putting echo in front of mv.

Rename folders in all subfolders

find /data -depth -type d -name '*old*' -execdir rename -v old new {} +

-depth renames the deepest folders first, so the paths of the others stay valid while find works. With the Perl version, write -execdir rename 's/old/new/' {} + instead.

Tips

  • Always preview with -n (or echo) first.
  • If two names would become the same, the util-linux version overwrites the target unless you add -o; the Perl version refuses unless you add -f. Check the preview for clashes.

Official documentation: rename manual page (util-linux) and rename (Perl) manual page.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Managed dedicated servers

our engineers look after the server for you, from $135 a month.

Was this answer helpful?

Still stuck? Open a ticket