Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I downloaded a bunch of images files but they are ordered recursively by month and day so there is a folder and a file for the day of the month, I am trying to loop through all the files found by the find command and move them to just one folder in my home directory. mv find ~/Downloads/skydrive* -name *.jpg -exec mv ~/temp {} \;

it's not working it says directory doesn't exist, I have also tried a for loop but I get the same result. any light on this? Thanks in advance.

share|improve this question

migrated from stackoverflow.com Mar 5 '13 at 0:18

This question came from our site for professional and enthusiast programmers.

1  
Something looks wrong about "mv dest src". Also, consider when the filename contains spaces .. –  pst Mar 4 '13 at 18:56
    
can you use $1 as a variable for the input source? –  Alex Mar 4 '13 at 18:57

3 Answers 3

You were close - you just got the arguments to mv in the wrong order - try:

$ find ~/Downloads/skydrive* -name \*.jpg -exec mv {} ~/temp/ \;
share|improve this answer
    
I have tried that the exit status is 0 but all I get is a unix file called temp, instead of all the images in the folder temp –  Alex Mar 4 '13 at 19:00
2  
Make sure you actually have a directory at ~/temp. Also note that I've now added a trailing / to ~/temp/ to make sure you don't write a file if it's missing. –  Paul R Mar 4 '13 at 19:46

try to put your name between single quotes: find '~/Downloads/skydrive*' -name '*.jpg' -exec mv ~/temp {} \;

share|improve this answer

This can also be done if your shell is bash version 4+ (which I believe is the case on OSX) using the globstar shell option and a for loop:

shopt -s globstar
for f in ~/Downloads/skydrive/**/*.jpg; do mv "$f" ~/temp/; done

This will break if you have several hundred thousand jpg files, while the find solutions won't, but for anything else it should work perfectly well.

share|improve this answer
    
I don't know about 10.9, but the latest public version of OS X (10.8) still comes with bash 3.2. –  Lri Jul 31 '13 at 21:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.