Ubuntu 16.04
I'm pretty new to linux and have a large number of files an the directory dir
. These files have postfix _uploaded
.
Is there a way to rename all this files and set them postfix _handled
instead of _uploaded
?
Ubuntu 16.04
I'm pretty new to linux and have a large number of files an the directory dir
. These files have postfix _uploaded
.
Is there a way to rename all this files and set them postfix _handled
instead of _uploaded
?
Ubuntu has rename
(prename
), from directory dir
:
rename -n 's/_uploaded$/_handled/g' -- *_uploaded
-n
is for --dry-run
After getting the potential changes to be made, remove n
for actual action:
rename 's/_uploaded$/_handled/g' -- *_uploaded
You can also leverage bash
parameter expansion, within a for
loop over the filenames containing the string _uploaded
at the end, from directory dir
:
for f in *_uploaded; do new=${f%_uploaded}; echo mv -- "$f" "${new}_handled"; done
This will show you the changes to be made, remove echo
for actual action.
rename
regex allows using$
as "end of line" to make sure to replace only the suffix if a file was named likeA_foo_foo
- i.e.rename 's/_uploaded$/_handled/' *
is to be preferred. – FelixJN Nov 03 '16 at 21:56rename
supports PCRE, but matching the end of the line using$
is not the desired case here i am afraid. – heemayl Nov 03 '16 at 21:58