Thursday, May 28, 2015

Exclude directories and files with Tar in Ubuntu Linux

I had problems with figuring out how to exclude directories with files and sub-directories with tar. I've tried several of ways to accomplish this but all of my effort ended with the exclude being ignored somehow.

But finally I found out how to do this. So my system is Linux Ubuntu 14.04 with Tar version 1.27.1.

tar --exclude=var/www -cvpjf /var/backups/vps/vpsBackup_$(date +"%F").tar.bz2 *
So what the above does: excludes the directory www in var with all it's files and sub directories. So no trailing slash after equal sign and no after in the end of path.

The whole manual for tar can be found here. Also with the command tar --help will show you a list of possible actions.

I hope this will help out somebody.

No comments:

Post a Comment