Linux – How to only tar files in a directory based on a specific file name

linuxredhattar

I want to create a tar ball and include only the files in the directory that start with a specific filename. For instance I have apples-x.x.x and oranges-x.x.x, and I only want to tar the files beginning with "apple". How can I do this?

Thanks!

Best Answer

Ummm, I may be overlooking something, but how about

tar cf /path/tarfile appl*

Unless you have directories which are also called ./appl*, in which case they'll get trawled up, with their contents, that should do it. If the latter pertains, you can stop that with --no-recursion.