Loop through folders and extract images (Caution Extremely Nerdy :) )

Screen Shot 2015-07-01 at 11.45.42 AM

Today we get a little bit “techy”. I am currently rebuilding my website and I needed to pull a bunch of files from several folders. After a little bit of tinkering I figured out that I could very easily do this with one line of code in terminal!



So what really helps me is talking through exactly what I need to do and then adding the code or commands that get me there.

The line of code is this:

sudo find . -mindepth 2 -type f -exec cp {} ./allSeniorImages \;;


Sudo allows us to have full access to each part of our machine. When you launch this code it will ask for your password to elevate your privileges.


Find is the command that will do just that! Find what you are looking for! in this case there are a few more arguments that you have to add in order to go through all of the files.

find arguments: -mindepth 2

This tells the computer how far into the file structure it needs to search in this case at least 2 folder levels

find argument: -type f

This tells the computer what you are looking for. In this case we are just looking for a regular file.

-exec cp {} ./allSeniorImages

This tells the computer what you want to do with all of the files you have found. In this case we are telling it to copy them to the allSeniorImages folder.

I know this was a bit confusing especially if you are not a techny or a geek 🙂 I am MORE then willing to help you out in any way that I can!

Leave a Reply