I have a directory hierarchy containing many images with .jpg file-extension, and there are multiple folders containing these images. There are many .json files as well in these folders.

Is there a way to scan all these subfolders and move the .jpg files to a specific destination/folder?


Create and open your destination folder.

Go to the base directory you want to scan in Finder. In the search field, enter kind:jpg. Select JPEG image when it shows up.

After it generates a list of all the JPEG images, you can select them all with Command-A and drag them to a folder. If you hold down ALT when you drop them on the folder, you'll get a copy instead of a move.

  • 1
    This is a much nicer idea than having to use command-line for it. Thanks! – arunsathiya May 10 at 16:47
  • 1
    I figured there was a reason why you're asking in the "Mac" exchange instead of the Unix/Linux exchange.I can sed and awk with the best of them, but I buy Macs because I don't WANT to remember cryptic regular expressions and commands. – Wilfred Smith May 10 at 17:09

If you are looking for a command-line solution, use the following:

find /source_root_directory_path -name '*.jpg' -exec mv {} /target_directory_path \;
  • Thank you, I will be sure to check this out as well. – arunsathiya May 10 at 16:55
  • I see two issues with your find command. The first is fine if one does not want .JPG as well as .jpg files moved, -name '*.jpg' should be -iname '*.jpg' to get all JPEG files (if that's whats really wanted). Your mv command will overwrite any file of same name found in the source directory structure when moving it to the destination directory. That said though, your -exec command is better formed then mine is! :) – user3439894 May 10 at 17:13
  • @user3439894 Thank you very much for pointing out and making me learn something new. I will refer to relevant manuals and amend the command to handle the cases appropriately. – Nimesh Neema May 10 at 17:17

In Terminal, the following bash compound command will move all found .jpg files in the "/path/to/source" directory to the "/path/to/destination/" directory, but will not overwrite existing files at the "/path/to/destination/" directory.

find "/path/to/source" -iname '*.jpg' -exec sh -c 'for f in "$@"; do mv -n "$f" "/path/to/destination/"; done' sh {} +

After running the above bash compound command, run the following bash compound command to see what is left at the "/path/to/source"` directory.

find "/path/to/source" -iname '*.jpg'

You must log in to answer this question.

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