Excluding directory when creating a .tar.gz file

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

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

Be aware that the exclude argument:

1- Should be used with a =, like this: --exclude=PATTERN

2- Expects a pattern (as the user Don Dilanga pointed out), not a directory, though a directory will work well as a pattern if it's long enough to not match any single files.

3- Has to be placed before the source directory. (as pointed out by kghbln)


Try moving the --exclude to before the include.

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