How to rename files in a directory such as the following file: PMC21375.pdf.txt
, I need to be renamed to 21375.txt
. i.e, I need to remove both PMC
and pdf
from each file name.
Rename files in directory
rename
rename
How to rename files in a directory such as the following file: PMC21375.pdf.txt
, I need to be renamed to 21375.txt
. i.e, I need to remove both PMC
and pdf
from each file name.
Best Answer
With perl's
rename
:Demo :
from the
shell
prompt. It's very useful, you can put some perl code like I does in a substitution.You can remove the
-n
(dry-run mode switch) when your tests become valids.There are other tools with the same name which may or may not be able to do this, so be careful.
If you run the following command (
linux
)and you have a result like
then this seems to be the right tool =)
If not, to make it the default (usually already the case) on
Debian
and derivative likeUbuntu
:(replace
/path/to/rename
to the path of yourperl's rename
command.Last but not least, this tool was originally written by Larry Wall, the Perl's dad.