There are multiple files in a directory that begin with prefix fgh, for example:
fghfilea
fghfileb
fghfilec
I want to rename all of them to begin with prefix jkl. Is there a single command to do that instead of renaming each file individually?
There are multiple files in a directory that begin with prefix fgh, for example:
fghfilea
fghfileb
fghfilec
I want to rename all of them to begin with prefix jkl. Is there a single command to do that instead of renaming each file individually?
There are several ways, but using rename
will probably be the easiest.
Using one version of rename
:
rename 's/^fgh/jkl/' fgh*
Using another version of rename
(same as Judy2K's answer):
rename fgh jkl fgh*
You should check your platform's man page to see which of the above applies.
This is how sed and mv can be used together to do what Stephan202 is thinking?
for f in fgh*; do mv $f $(echo $f | sed 's/^fgh/jkl/g'); done
rename might not be in every system. so if you don't have it, use the shell this example in bash shell
for f in fgh*; do mv "$f" "${f/fgh/xxx}";done