Applies to: mv and rename on Ubuntu, Debian, AlmaLinux, Rocky Linux and other Linux systems
Linux has no separate “rename” command for single files: you rename a file or folder by moving it to a new name with mv. For many files at once there is rename, which works differently on Debian-based and Red Hat-based systems. We tested every example on Ubuntu 24.04, Debian 13 and AlmaLinux 9.
Rename a file or a folder
mv old-name.txt new-name.txt mv old-folder new-folder mv "my file.txt" my-file.txt # quote names that contain spaces
Renaming a folder with mv works the same as a file; you don’t need -r.
Don’t overwrite by accident
If the new name already exists, mv replaces it without asking. Use:
mv -i report.txt final.txt # ask before overwriting mv -n report.txt final.txt # never overwrite
If the new name is an existing folder, mv moves the item into that folder instead of renaming it.
Rename many files at once
Ubuntu and Debian use the Perl rename, which takes a search-and-replace expression. Install it with sudo apt install rename if it is missing:
rename -n 's/\.JPG$/.jpg/' *.JPG # -n shows what would change rename 's/\.JPG$/.jpg/' *.JPG # do it rename 's/ /-/g' * # replace spaces with dashes
AlmaLinux, Rocky Linux and RHEL have the simpler rename from util-linux: text to find, replacement, then the files:
rename -nv .JPG .jpg *.JPG # dry run, show changes rename .JPG .jpg *.JPG
Check which one you have with rename --version.
Rename with a loop (works everywhere)
for f in *.jpeg; do mv -n -- "$f" "${f%.jpeg}.jpg"; done
Rename in cPanel or an FTP program
In cPanel’s File Manager, select the file or folder and click Rename. In FileZilla, right-click it and choose Rename.
More examples: rename multiple folders from the command line and rename files and folders to lowercase.
Ucartz services for this topic
- 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.
- Linux server management: hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.
