I have a server backup of a WordPress site that has about 1000 images in the uploads directory. When an image was uploaded through WordPress it would create multiple sizes of the image such as:
foobar.jpg
foobar-170x170.jpg
foobar-250x250.jpg
I'm familiar with using find
to move all files from a directory and its subfolders with something like find . -mindepth 3 -type f -print -exec mv {jpe?g|png|gif} . \;
but I was curious to know if an exclusion along the lines of "don't move this" can be added. I'd like to give a pattern and then exclude filenames containing that pattern.
Something like !(\d{2,5}x\d{2,5}\.(jpe?g|png|gif))
.
Ideally, I would like to do this in a single command without running it in a loop or using rm
to delete the files after I've moved them all. Any better suggestions to reduce multiple terminal commands would be great.
You can use find's
-not
or!
expressions:So, to move
foobar.jpg
but not the other two, you could use:You can also make it match only 2-5 digits on either side with