Rename files through a sed-replace expression
- Utility for renaming multiple files through a sed-type search/replace pattern.
- If no filenames are given, they will be read from stdin.
- Similar to Perl-rename package
rename
whose binary can befile-rename
in newer distributions, asutil-linux
now has arename
binary (sometimesrename.ul
) that is not as versatile. - Commandline order compatible with Perl-rename (and options
-f -n -v -h
). - After github.com/fbergen/rename (which swaps the expression and the files on the commandline).
- MIT License of github.com/fbergen/rename copyright 2019 Fredrik Bergenlid, relicenced under GPLv3+ copyright 2024 github.com/pepa65.
rename v0.2.4 - Rename files through a sed-replace expression
Usage: rename [options] <sed-replace expression> [files...]
Options:
-c/--copy: Copy instead of move.
-f/--force: Overwrite existing files.
-i/--interactive: Ask for confirmation before renaming each file.
-n/--noaction: No changes, just show what would have been done.
-v/--verbose: Show which files where renamed, if any.
-h/--help: Only show this help text.
Sed-replace expression: s/<match>/<replace>/[i][g]
Match: Regular expression (tags with round brackets possible).
Replace: Replacement, with $0: whole original and $1...: tag.
i: Case insensitive match of regular expression.
g: Global: keep looking for match after first match.
Files: If none given, read from stdin.
- Add
.bak
to all files:rename 's/$/.bak/'
- Add
.txt
to all.lst
files and keep the originals:rename -c 's/$/.txt/' *.lst
- Remove the extension of all files in the
dir
directory:rename 's/\.[^.]*$//' dir/*
- Swap double extensions:
rename 's/([^.]*)\.([^.]*)$/$2.$1/' *
go install github.com/pepa65/rename@latest
wget 4e4.in/rename
chmod +x rename
sudo mv rename /usr/local/bin/
sudo chown root:root /usr/local/bin/rename