Ubuntu – Find and exec in found folder

directoryexecute-commandfindmv

I'm trying to find files containing *.nef and move them to a subdirectory name NEF of the folder in which the file is found.

I've started testing with the following command, but this always copies to my current directory, which is my home folder.

find testfolder/*.nef -exec mv NEF \;

In the man find section i've read about using -execdir, but using this instead of -exec still has the same result.

So the question is: how can i dynamically assume the currently found directory and mv found files to a sub-directory folder named NEF? (which does not yet exist)

Thanks in advance!

Best Answer

You were right in considering -execdir. Something simple like the below should work

find testfolder/ -name '*.nef' -execdir mkdir -p NEF \; -execdir mv {} NEF/ \;