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.

How run MySQL dump inside mysql console

Sometimes it may be necessary to use the mysqldump command in the mysql command line. As you know, this command is an external command and must be executed separately, but with the method we teach, you can also use it in the mysql command line.

 

For this purpose, it is enough to use the phrase \!at the beginning of the command.

\! mysqldump -u username -p database > database_dump.sql

How to Install Zip and Unzip in Linux

Zip is a command-line utility tool used for compressing files and folders. Compression of files & folders enables faster and more efficient transfer, storage, and emailing of files and folders. On the other hand, unzip is a utility tool that helps you decompress files and folders.

Benefits of zipping files:

  • Compressed/zipped files take up less disk space, leaving you with more space to work with.
  • Zipped files are easy to transfer including uploading, downloading, and attaching them on email.
  • You can easily decompress zipped files on Linux, Windows, and even mac.

In this topic, we focus on how you can install the zip and unzip utilities on various Linux distributions.

Read More