Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here is my directory structure:

/home/folders/test (some directories) and files
images (directory)

/home/folders/test/images/( some directories ) and files

I have to copy the XML files and the images folder but exclude all other files.

In images, I only have to copy sub directories (with images inside) but exclude other files. How can I achieve this?

share|improve this question
up vote 1 down vote accepted

Perhaps a find command to identify subdirectories would help here:

cp *.xml ../destination
find images -type d -mindepth 1 -maxdepth 1 -exec cp -R \{\} ../destination/images/ \;
share|improve this answer
Ah - so if you want just the destination folder to contain the xml files and the subdirectories then drop the last "images/" from the end of the second command. Make sure that ../destination, and if required ../destination/images exist beforehand. "mkdir -f ../destination/images" – digitalsean Jun 18 '12 at 13:20

I think this command will work for you...

first go to /home/folders/test and try this command.

[max@localhost file]$ find . -name ".c" -o -name ".jpeg" | xargs -i cp {} /home/max/Desktop/jkm/

it will copy all the ".c" and ".jpeg" files under /test (including ".c" and ".jpeg" files in the subdirectories) to a destination directory /jkm/

share|improve this answer
i think you have not understood my requirement. – vvr Jun 18 '12 at 12:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.