1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-08-05 12:55:45 +02:00
tldr/pages/common/rename.md
Rubens Altimari 02a086c29a
rename, file-rename, perl-rename, prename: rework pages (#17259)
Co-authored-by: Managor <42655600+Managor@users.noreply.github.com>
2025-07-26 23:17:25 +03:00

30 lines
877 B
Markdown

# rename
> Rename a file or group of files with a regular expression.
> WARNING: This command will overwrite files without prompting unless the dry-run option is used.
> Note: This page refers to the Perl version, also known as `file-rename`.
> More information: <https://manned.org/prename>.
- Replace `from` with `to` in the filenames of the specified files:
`rename 's/{{from}}/{{to}}/' {{*.txt}}`
- Dry-run - display which changes would occur without performing them:
`rename -n 's/{{from}}/{{to}}/' {{*.txt}}`
- Change the extension:
`rename 's/\.old$/\.new/' {{*.txt}}`
- Change to lowercase (use `-f` in case-insensitive filesystems):
`rename {{[-f|--force]}} 'y/A-Z/a-z/' {{*.txt}}`
- Capitalize first letter of every word in the name:
`rename {{[-f|--force]}} 's/\b(\w)/\U$1/g' {{*.txt}}`
- Replace spaces with underscores:
`rename 's/\s+/_/g' {{*.txt}}`