I'm using the following command to move all files (non-recursively) ended in _128.jpg into the 128x160 subdir. This works great.

find . -iname '*_128.jpg' | xargs -I '{}' mv {} 128x160

But I also need to remove the _128 suffix from each file. Also, I must keep my current xargs method, making an exec for each would make the process extremely longer.

Thanks in advance for your cooperation!

  • Is this really faster than using exec? I believe it would be faster if you used find ..... | xargs mv -t 128x160 because in that case it would move as many files it could with one mv command. The way you call it it runs mv as many times as there are files to be moved. Compare find . -iname '*_128.jpg' | xargs -I '@' echo @ bla to find . -iname '*_128.jpg' | xargs echo bla
    – Marki
    Feb 9, 2014 at 16:56

1 Answer 1


Something like this should do the trick :

find . -iname '*_128.jpg' | xargs -I % sh -c 'newname=$(echo % | sed "s/_128//"); mv % 128x160/$newname'

Here i have used a multiple commands approach using sh -c 'command1; command2' and sed to clear _128 in the filename.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.