Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In ~/my/path, I want to move all files that contain string "(J)" and have file type of ".foo" to ~/my/path/j

I'm trying:

[me ~/my/path]$ find -type f -name "*(J)*.foo" -print0 | xargs mv -0 j/

No luck :(

share|improve this question
up vote 4 down vote accepted

How about

find ~/my/path -type f -name "*(J)*.foo" -exec mv {} ~/my/path/j \;
share|improve this answer
    
This worked great; thanks! – macek Feb 1 '10 at 3:42
    
Didn't know you actually wanted the brackets around the J, just added them. You're more than welcome. – John T Feb 1 '10 at 3:43
    
John T, This solution seems very elegant and efficient but I'm having trouble understanding what the {} really means. I understand that is the "variable" being used for the mv command, but what else can the {} do? And just for clarification, the \; is used to terminate the exec? – macek Feb 1 '10 at 3:50
    
When using -exec with \;, the {} is replaced with the current file or directory found that matches your criteria. \; will fork a new mv operation for each result found. HTH. – John T Feb 1 '10 at 3:53

The -0 needs to go right after the xargs.

find -type f -name "*(J)*.foo" -print0 | xargs -0 -I{} mv \{\} j/

By the way, posting an error message or other details instead of "no luck" helps diagnose problems.

share|improve this answer
    
I tried this too and I got this output: usage: mv [-f | -i | -n] [-v] source target mv [-f | -i | -n] [-v] source ... directory – macek Feb 1 '10 at 3:40
    
Sorry, I forgot to put the curly braces in. Fixed. – Dennis Williamson Feb 1 '10 at 3:43

How about

mv `find -name *(J)*.foo` -t /my/path
share|improve this answer
    
Although with this solution you might get the "argument list too long" error; in this case, the one proposed by Dennis worked for me. – user38328 May 26 '10 at 9:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .