2014-02-23 17:08:04 +00:00
|
|
|
# rename
|
|
|
|
|
2019-07-18 13:08:49 +01:00
|
|
|
> Rename multiple files.
|
2024-02-05 07:04:49 +00:00
|
|
|
> Note: this page refers to the command from the `rename` Debian package.
|
2021-07-09 15:45:55 +01:00
|
|
|
> More information: <https://manned.org/file-rename>.
|
2014-02-23 17:08:04 +00:00
|
|
|
|
2016-01-20 11:41:12 +00:00
|
|
|
- Rename files using a Perl Common Regular Expression (substitute 'foo' with 'bar' wherever found):
|
2014-02-23 17:08:04 +00:00
|
|
|
|
2019-03-26 23:49:14 +00:00
|
|
|
`rename {{'s/foo/bar/'}} {{*}}`
|
2014-02-23 17:08:04 +00:00
|
|
|
|
2016-01-20 17:59:42 +00:00
|
|
|
- Dry-run - display which renames would occur without performing them:
|
2014-02-23 17:08:04 +00:00
|
|
|
|
2019-03-26 23:49:14 +00:00
|
|
|
`rename -n {{'s/foo/bar/'}} {{*}}`
|
2014-02-23 17:08:04 +00:00
|
|
|
|
2019-07-18 13:08:49 +01:00
|
|
|
- Force renaming even if the operation would remove existing destination files:
|
2016-07-20 06:47:32 +01:00
|
|
|
|
2019-03-26 23:49:14 +00:00
|
|
|
`rename -f {{'s/foo/bar/'}} {{*}}`
|
2016-07-20 06:47:32 +01:00
|
|
|
|
|
|
|
- Convert filenames to lower case (use `-f` in case-insensitive filesystems to prevent "already exists" errors):
|
2014-02-23 17:08:04 +00:00
|
|
|
|
2019-03-26 23:49:14 +00:00
|
|
|
`rename 'y/A-Z/a-z/' {{*}}`
|
2015-06-26 03:35:13 +01:00
|
|
|
|
2016-01-20 11:41:12 +00:00
|
|
|
- Replace whitespace with underscores:
|
2015-06-26 03:35:13 +01:00
|
|
|
|
2019-03-26 23:49:14 +00:00
|
|
|
`rename 's/\s+/_/g' {{*}}`
|