Ads by ProfitSence

Using Tar Zip to exclude all files and directories .

Last Updated on Wednesday 5th Oct 2022

tar exclude directory

  • The --exclude flag should be placed before the source directory.

  • Some Linux distributions allow --exclude /path/to/excluded/, while others require = such as --exclude="/path/to/excluded".

  • All distributions I have used allow the = version.

  • Other flags like -czf should be added directly after the tar command, such as tar -czf

  • The exclusion directory doesn't have the trailing backslash like --exclude="./wpcontent/uploads".

Here's the Example for excluding the uploads folder in a WordPress installation.

					tar -czf backup.tgz --exclude="/var/www/wordpress/wp-content/uploads" /var/www/wordpress/wp-content/

  • You can use the above code to exclude files or directories from your archive.
  • You can use globbing patterns in the exclude flag. For example, `--exclude=*.mp4`.