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 thetar
command, such astar -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