Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excluding directory when creating a .tar.gz file

I have a /public_html/ folder, in that folder there's a /tmp/ folder that has like 70gb of files I don't really need.

Now I am trying to create a .tar.gz of /public_html/ excluding /tmp/

This is the command I ran:

tar -pczf MyBackup.tar.gz /home/user/public_html/ --exclude "/home/user/public_html/tmp/"  

The tar is still being created, and by doing an ls -sh I can see that MyBackup.tar.gz already has about 30gb, and I know for sure that /public_html/ without /tmp/ doesn't have more than 1GB of files.

What did I do wrong?

like image 752
suresh Avatar asked Nov 27 '10 04:11

suresh


People also ask

How do I exclude a directory in tar?

You can exclude directories with --exclude for tar. To clarify, you can use full path for --exclude.

How do you exclude a directory?

Go to Start > Settings > Update & Security > Windows Security > Virus & threat protection. Under Virus & threat protection settings, select Manage settings, and then under Exclusions, select Add or remove exclusions. Select Add an exclusion, and then select from files, folders, file types, or process.

How do I exclude a directory in Linux?

Method 1 : Using the option “-prune -o” We can exclude directories by using the help of “path“, “prune“, “o” and “print” switches with find command. The directory “bit” will be excluded from the find search!

How do I change a directory to a tar file?

To change the working directory in the middle of a list of file names, either on the command line or in a file specified using ' --files-from ' (' -T '), use ' --directory ' (' -C '). This will change the working directory to the specified directory after that point in the list.


2 Answers

Try removing the last / at the end of the directory path to exclude

tar -pczf MyBackup.tar.gz /home/user/public_html/ --exclude "/home/user/public_html/tmp"  
like image 51
Victor Parmar Avatar answered Sep 28 '22 07:09

Victor Parmar


Try moving the --exclude to before the include.

tar -pczf MyBackup.tar.gz --exclude "/home/user/public_html/tmp/" /home/user/public_html/  
like image 32
Martin Algesten Avatar answered Sep 28 '22 06:09

Martin Algesten