How to Exclude Files and Folder when Make a tar archive

If you want to make an archive of your files and folders, but you want to exclude some files or folders, this tutorial explains how to do this.

In this tutorial, using the tar command, we want to archive all the files and folders in the directory where we are. But “wp” folders and files with the “tar.gz” extension are excluded.

The procedure is very simple, in general, if you want to archive all the contents of your folder, we run the following command:

$ tar -zcvf /backup/filename.tgz .

In the example above, -zcvf is to apply the command settings, “/backup/filename.tgz” is to specify the name and path of the archive storage. And “.” To specify the folder we want to archive.

But since we want to exclude the “wp” folder, adding exclude is done as follows:

$ tar --exclude='./wp' -zcvf /backup/filename.tgz .

If we want to add more than one template to the set of exceptions, we do the following:

$ tar --exclude='./wp' --exclude='./upload/folder' -zcvf /backup/filename.tgz .

 

If we want to add more than one template to the set of exceptions, we do the following:

$ tar --exclude='./wp' --exclude='*.tar.gz' -zcvf /backup/filename.tgz .

 

Attention :

Make sure to put --exclude before the source and destination items.

Leave a Reply

Your email address will not be published. Required fields are marked *