How To Compress a Directory with the tar Command and Exclude Certain Files, tarball exclude files

When creating a tar-ball (compressing a directory of files), you may exclude certain files by using the –exclude flag.

The –exclude flag will also work with a wild card “*”. Here is an example of how to tar-ball a directory from the parent directory and exclude certain files:

tar --exclude="node_modules"  --exclude=".*" -zcvf my-tar-ball.tar.gz ./<directory to compress>

IMPORTANT: Be sure to use the –exclude just after the tar command, NOT at the end of the command.

Leave a Reply

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