How to use the SSH rename command
The rename command renames multiple files at once using Perl regular expressions. In particular, it’s useful for changing file extensions in bulk, replacing parts of filenames, or reformatting many files at once. Furthermore, rename is much faster than renaming files one by one -making it ideal for website migrations, log rotations, or organizing uploads on your Linux server via SSH. Note: some systems use prename instead of rename; both work the same way.
Change file extensions
To change all files with one extension to another, use a substitution pattern:
rename 's/\.txt$/.pdf/' *This changes all .txt files in the current directory to .pdf. The pattern s/old/new/ means “substitute old with new.” The \. escapes the dot, and $ anchors to the end of the filename. Example—convert HTML files to PHP:
rename 's/\.html$/.php/' *.htmlShow what’s being renamed (verbose)
Use -v to see each file as it’s renamed:
rename -v 's/\.txt$/.pdf/' *.txtOutput shows each file as it’s renamed (e.g. file1.txt → file1.pdf). Useful for confirming the changes.
Preview changes (dry run)
Use -n to preview renames without actually changing files:
rename -n 's/oldname/newName/' *This shows what would be renamed. Remove -n to apply the changes.
Replace text in filenames
To replace a string anywhere in the filename:
rename 's/old-prefix/new-prefix/' *Example—replace “backup-” with “archive-” in all files: rename 's/backup-/archive-/' *.
Rename single files with mv
For renaming one file, use mv instead: mv oldname.txt newname.txt. See our guide on the SSH mv command for moving and renaming single files.
Common use cases
Typical uses for rename on a Linux hosting account:
- Converting HTML files to PHP after a migration
- Adding or removing prefixes or suffixes from batch exports
- Standardizing image filenames (e.g. replacing spaces with hyphens)
- Renaming log files or backup archives in bulk
Always run rename -n first to preview. If rename is not installed, use a loop: for f in *.txt; do mv "$f" "${f%.txt}.pdf"; done.
Need more help?
Explore more SSH and hosting guides in our knowledgebase. JetHost web hosting includes SSH access for managing your server files directly.


