47

I am looking for some help trying to get a command working. I want to find some files only and move them, but when I enter this command:

find /Volumes/NEXSAN/Engine\ Folders/Input/DTO_Proxy/* -type f -mtime +7 -exec mv -v {} /Volumes/NEXSAN/.2BeDeleted4realz/

I get this error

find: -exec: no terminating ";" or "+"

I know I probably have it wrong, but I can't figure out what's missing?

b4hand
  • 9,550
  • 4
  • 44
  • 49
user2983956
  • 499
  • 1
  • 4
  • 9
  • possible duplicate of [find: missing argument to -exec](http://stackoverflow.com/questions/2961673/find-missing-argument-to-exec) – b4hand Mar 19 '15 at 21:24
  • 1
    On a tangential note, I made the mistake of using `+` without `{}` which produced the same (misleading) error message on OSX 10.6.8. – tripleee Oct 18 '15 at 09:11

2 Answers2

77

Just terminate the find command with \;, making sure to include the space before the \;.

find /Volumes/NEXSAN/Engine\ Folders/Input/DTO_Proxy/* -type f -mtime +7 -exec mv -v {} /Volumes/NEXSAN/.2BeDeleted4realz/ \;
MrWonderful
  • 2,530
  • 1
  • 16
  • 22
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
  • 20
    To anyone who comes across this, make sure that there is a space before the terminating "\;", or find will still complain about no terminating ";" – kfriend Dec 22 '14 at 19:25
  • 12
    How does one do this for a terminating '+'? I tried "\+" and it didn't work (bash 4.3.46, find isn't telling me it's version !?, it's on osx) – drevicko Jan 13 '17 at 17:15
  • @drevicko It worked for me after adding `{}`, i.e. `-exec mv {} +`. – David Resnick Jun 17 '20 at 12:41
  • 1
    @DavidResnick was a while ago, but... I think I had some command parameters between `{}` and `\+`. This is not allowed by `find` --- I think because of the way it determines when it needs to run multiple commands (due to there being a lot of found files, hence the command line is too long to do in one go). – drevicko Jun 18 '20 at 00:22
  • And we all wonder why unix / linux isn't more widely adopted by regular people... – Locane Apr 20 '23 at 00:08
5

If you want to correct the find command that you had, it should look like this:

find . -name '*.xml' -exec SetFile -t TEXT {} \;

The *.xml needs to be quoted so it's passed as a parameter to find instead of expanded by the shell. The ; also needs to be escaped so it's passed as part of the parameter to find and not interpreted by the shell.

Keep in mind this will only work for files within the current directory (and subdirectories) and for any new files created, you would need to run the command again.

Michael Mior
  • 28,107
  • 9
  • 89
  • 113