Unix find, xargs and basename.


Xargs is great. If you want to know why use xargs over exec, have a read of this: xargs versus exec.

But, there is one problem. If the command that you are trying to execute on the results from find cannot take more than one file as param (basename for e.g, can take only one file), then use the -n 1 param with xargs (to process one file at a time) . In that case, xargs is probably going to be as quick as using exec.

find . -name "*.rar" | xargs -n 1 unrar e
find . -name "*.rar" | xargs -n 1 basename

And this will get the basename without using the basename function (I go it from this page).

find . -name "*.rar" -printf "%fn"

Leave a Reply

Your email address will not be published. Required fields are marked *