Copy Files & Create Missing Directories

I needed to find all the image files in a large directory tree and then copy them to a new directory tree while preserving the directory structure. Here’s my solution:

1. Find the files and save list to a file:

This command demonstrates using the -exec option on “find” to feed the “file” command.

2. Copy each file on the list, creating sub directories as needed:

This command demonstrates a one line while loop feed by input redirection. Also notice the “–parents” option on the “cp” command.

Have a project or a problem?

Talk with a senior engineer for practical recommendations—no obligation.

Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Categories

Get a free consultation from Reliable Penguin

Submit the form—or for immediate service call 866-649-7984.