Mircea
Mircea

Reputation: 11623

Gzip only files containing "*foo*" over SSH

In a directory, is it possible to gzip only files containing "foo"? I can find them all by find . -name "*foo*" but i need a way to archive them.

Thank you.

Upvotes: 0

Views: 269

Answers (1)

StianE
StianE

Reputation: 3175

I assume you mean archive into a single tar file? Not individual .gz files? Try this: (assumes there aren't too many files)

find . -name "*foo*" | xargs tar cvzf archive.tar.gz

An alternative is to do something like:

find . -name "*foo*" > list.txt
tar cvzf archive.tar.gz -T list.txt #(works only with gnu tar, not bsd i think)

Upvotes: 1

Related Questions