0

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.

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

3 Answers 3

3

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

$ find ~/Downloads/skydrive* -name \*.jpg -exec mv {} ~/temp/ \;
2
  • 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, 2013 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, 2013 at 19:46
1

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

0

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.

1
  • 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, 2013 at 21:05

You must log in to answer this question.