2

This question already has an answer here:

I want to move all the files, but not the folders, inside a folder to another directory.

I have been using this command:

find . -maxdepth 1 -type f -exec mv {} destination_folder \;

But now I want to move all the files except the ones that start with "exe_", so I tried:

find . -maxdepth 1 -type f -exec mv !(exe_*) part1a_si_atom-exp001 \;

But now it also moves directories. What can I do?

marked as duplicate by thrig, Anthon, Michael Durrant, G-Man, roaima Apr 16 '17 at 11:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4

!(exe_*) is getting interpreted by your shell and expanded before your find command is even run. Instead, try the -name flag to find:

find . -maxdepth 1 -type f -not -name 'exe_*' -exec mv {} destination_folder \;

I also recommend using + instead of ; as the terminator for your -exec command to reduce overhead.

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