Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

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 Aug 20 '11 at 8:16

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

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

Am I missing something? Why not just do:

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

Something like this:

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

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

You must log in to answer this question.