Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I know how to tar a bunch of files, minus several I don't want:

tar --exclude=./*.jpg -pcjvf all.tar.gz ./

Here I tar all files, except any jpg extensions.

I want to do the opposite. I need to only tar certain files. After googling I haven't had too much luck finding examples.

Does an --include option exist with the tar command?

share|improve this question

migrated from stackoverflow.com Aug 20 '11 at 8:16

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

4 Answers 4

I would do it by piping 'find' output to tar:

find /your/directory -type f -name '*.jpg' | tar --files-from=- -cvf meow.tar

The 'find' command prints all jpg's stored in /your/directory recursively, and tar's magical --files-from option will read the files from '-', signifying stdin, and tar them. I find this particularly useful because rsync also has a --files-from option, so I have to remember only one file-specifying command. Furthermore, 'find' is more powerful than tar or rsync's file specifying abilities.

share|improve this answer

Something like this:

tar -pcjvf images.tar.gz ./*.jpg ./*.jpeg ./*.png
share|improve this answer

Am I missing something? Why not just do:

tar -pcjvf pictures.tar.gz ./*.jpg
share|improve this answer

There is no --include option, as you could simply attach all files you want to include as parameters to tar. If you want to include via wildcard, use find:

tar -pcjvf specific.tar.gz $(find -name *.jpg)
share|improve this answer

Your Answer

 
discard

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