Exclude large files from your tar with --exclude
If you go pretty much anything with data, learning the tar command is going to be worth your while. But suppose you do things with lots and lots of heavy data?
Well, one trick you’ll want to add to your arsenal is the –-exclude option.
Let’s say you want to tar a site with a ton of images in the image folder. So much so that it would take all night to tar that image folder… we’re talking really big.
Were there’s a will there’s a way. You can simply exclude the unwanted baggage and tar the rest by using --exclude.
It works like this…
Let’s say you want to tar the Green Crescent site, but let’s image that there’s that HUGE image folder located at /sites/all/files/images .
It’s really just this simple…
tar -pczf greenCresent.tar.gz /httpdocs --exclude "/httpdocs/sites/all/files/images"This will tar the whole site (which is located in /httpdocs) into a tar.gz file called greenCresent.tar.gz but won’t include the directory /httpdocs/sites/all/files/images.
The same works for individual files. To exclude more than one file or directory, just add more -- excludes.
For reference, here’s a bit more about some of the more common .tar commands.
c – create a new archive.
t - list the contents of an archive.
x - extract the contents of an archive.
f - the archive file name is given on the command line (required whenever the tar output is going to a file)
p – preserves the permissions.
v - print verbose output (lists file names as they are processed).
u - add files to the archive if they are newer than the copy in the tar file.
z - compress or decompress files automatically.
