Tar (Compress) a Directory without Images via Terminal

Sometimes you need to compress an entire directory, but sometimes you want to ignore specific file types.

Here is a basic command that you can use to remove specific file types before you compress it. In this example we use the find command to look for, and ignore, all image file types. That then gets piped into the tar command:

find ./ -type f | egrep -v "\.(jpg|gif|png|wmv|flz|zips)$" | xargs tar -czf directory.tgz

The command above creates a new compress file called directory.tgz and you’ll find it doesn’t any of files that meet the file type above.

Happy compressing!

Sharing is caring!

Leave a Reply

Your email address will not be published. Required fields are marked *