1

I'd like to find some file with mdfind and move it to another directory. So I tried like below but it makes an error caused by the space in the path.

> mdfind somefile.numbers 
/Users/hugh/Library/Mobile Documents/com~apple~Numbers/Documents/somefile.numbers
> mv $(!!) ~/Documents/
mv: rename /Users/hugh/Library/Mobile to /Users/hugh/Documents/Mobile: No such file or directory
mv: rename Documents/com~apple~Numbers/Documents/somefile.numbers
  to /Users/hugh/Documents/somefile.numbers: No such file or directory

So I tried to escape the space with printf %q, but it escapes everything.

> mv $(printf %q $(mdfind somefile.numbers)) ~/Documents/
mv: rename /Users/hugh/Library/MobileDocuments/com\~apple\~Numbers/Documents/somefile.numbers 
  to /Users/hugh/Documents/somefile.numbers: No such file or directory

There must be a good way to handle this but I cannot find one. Any ideas?

  • You should test the results of mdfind before attempting to move the file. But if you want to live dangerously then mv "$(mdfind somefile.numbers)" ~/Documents. – fd0 Sep 14 '15 at 15:45
1

Quote the variable:

mv "$(!!)" ~/Documents/

You must log in to answer this question.

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