up vote 2 down vote favorite
1
share [g+] share [fb]

I have a directory structure of which I wish to recursively go through the folders and copy any .jpg I find into another directory.

I think I had the wrong idea with:

cp -R photos/*.jpg /cpjpg

I am usin Ubuntu.

Thanks.

link|improve this question
You'll get a better response on superuser.com. But you don't have to do anything - if enough people agree the question will be moved automatically. – ChrisF Jan 4 '10 at 22:00
Do you want them all to end up in one directory (flatten) or do you want to preserve the stucture? – gbarry Jan 4 '10 at 22:01
feedback

migrated from stackoverflow.com Jan 4 '10 at 22:02

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

3 Answers

This will copy all files ending in .jpg or .jpeg (case insensitive as well) in the current directory and all its subdirectories to the directory /cpjpg.

find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -exec cp '{}' /cpjpg \;
link|improve this answer
feedback

This will do the same thing as above, but will preserve the directory structure.

find photos/ -type f \( -iname '*.jpg' -o -iname '*.jpeg' \) -print0 |xargs -0 tar c |(cd /cpjpg ; tar x)
link|improve this answer
feedback
% rsync -av --include='*.jpg' --exclude='*' SRC DST
link|improve this answer
feedback

Your Answer

 
or
required, but never shown