-exec: no terminating

Hello everyone

I have a home folder with a lot of stuff that I want to move to a folder "Trash" so I've done it this way:
find . -type d -exec mv trash
but the shell keeps saying:
Code:
find: -exec: no terminating ";" or "+"

Can you please explain to me my error and how to solve it and if there is any other way to do it.

Thanks in advance
 
Thanks for the reply but it doesn't help so much since I've already read the man pages and I don't see any other argument to add and even by adding the ; I still have the same error, for me to move a folder I simply have to specify the source and destination and it's already done.
I still don't got it.
 
I'm going to provide a partial answer and I hope that someone can help answer my questions as well.

There is a way to sort of do what you want using xargs. For example, to delete all directories under ZeroRadiant/ that are named '.svn', you could do:

Code:
find ZeroRadiant/ -type d -name '\.svn' -print0 | xargs -0 rm -rf

Now the problem I have with this xargs approach is that the output of the stuff before the '|' is tacked on to the end of the "rm -rf" command. So if I wanted to move files instead of delete them, for example "mv <arg> ~/Trash", I'm not sure how to do that. Presumably you could create a quick function that takes one argument, and the function would then move your input argument directory to ~/Trash. I actually tried this and was not able to get it to work with xargs.

In general, how do you use xargs when you want the arg to come somewhere in the middle of your command, not at the end of the command?
 
abdelilah said:
... for me to move a folder I simply have to specify the source and destination and it's already done.
I still don't got it.

find . -type d -exec mv trash
There is nowhere your source file in your command

Code:
  -exec utility [argument ...] ;
	     True if the program named utility returns a zero value as its
	     exit status.  Optional arguments may be passed to the utility.
	     The expression must be terminated by a semicolon (``;'').	[B]If you
	     invoke find from a shell you may need to quote the semicolon if
	     the shell would otherwise treat it as a control operator.	If the
	     string ``{}'' appears anywhere in the utility name or the argu-
	     ments it is replaced by the pathname of the current file.[/B]
	     Utility will be executed from the directory from which find was
	     executed.	Utility and arguments are not subject to the further
	     expansion of shell patterns and constructs.

You've read it but visibly you have not seen it.

Something like this sould do the trick

find . -type d -exec mv {} trash \;
 
Thanks a lot but I thought that the point was enough to specify that we are working on the current directory???
 
DutchDaemon said:
@rambetter: I would use a 'while read file; do' loop for that.

Seems like -exec would be faster, at least with a final plus rather than semicolon:
% find ZeroRadiant/ -type d -name .svn -exec mv {} ~/Trash \+

Come to think of it, that probably ought to have some quoting in case there are spaces in the filenames.
 
Back
Top