Sunday, October 8, 2017

Batch rename files in Linux


How I can rename images with 'rename' command from "something_full.jpg" to "something_500.jpg" recursive?


Answer



Basically, you can use the rename tool for that. It should come in a Perl-based version with Debian-based Linux distros, but you can easily download it from source as well (obviously, you need to make it executable first with chmod +x).




The following command will replace the _full part with _500 on all JPG files in the current directory.


rename 's/_full/_500/' *.jpg

To do this recursively, starting from your current directory, use rename with find.


find . -type f -iname "*.jpg" -exec rename 's/_full/_500/' {} \;

Note: You may want to test the command before actually executing is. In order to do that, add the -n option to rename (e.g. between rename and the 's//' string).


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...