2

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?

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.

| improve this answer | |

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