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?

Michael Ohlrogge
  • 809
  • 1
  • 8
  • 13
Joshua Salazar
  • 385
  • 5
  • 17
  • 1
    Related: http://unix.stackexchange.com/questions/154525/linux-command-line-move-all-files-and-directories-in-directory-except-some-fil?rq=1 – Elder Geek Nov 16 '16 at 18:45
  • Is this just inconsistent use of terminology or is there a difference for you between folders and directories? – Anthon Apr 15 '17 at 22:05

1 Answers1

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.

jayhendren
  • 8,224
  • 2
  • 30
  • 55