php - Linux tar command: compressing a directory but exluding subdirectories -


Scenario: I have a directory that hosts on my website in which hundreds of user-rendered images are making a backup script that takes all the images from the directory and Compress them in a .tar.gz file I have the order till now:

tar -czpf / path / to / backups / my_backup.tar.gz path / to / images /

Problem: Not inside my path / images / images / I have a directory The tmp / I called when I run the command, I get a .tar.gz file containing all images are path / to / image / directory and subdirectories that TMP / said.

Question: How can I get an order to leave / leave the tmp / subdirectory in the .tar.gz file?

Thanks a million in advance.

You are searching for - deprecated argument

< Pre - exclude = PATTERN

Some users start to confuse the excluded option. Here are some common pitfalls:

  • The main operating mode of tar does not work on the command path explicitly listed on the command line if its file name components In the example above, if you create an archive and exclude those files which are *. , but after all the options clearly name the file dir.o / foo dir.o / foo excluded from the archive Will go

  • You can sometimes confuse the meaning of - exclude = PATTERN and - out-of-file = file-type ( -X file-of-patternN ). Be careful: use the - exclude = PATTERN to exclude files are given as a pattern on the command line. Use the to extract the name of a file that contains a list of patterns, one per line; file-file-file-pattern from the outside; Each of these patterns can exclude zero, one or several files.

  • When you use - exclude = PATTERN , then the PATTERN parameter, therefore GNU tar wildcard characters like < Code> * . If you do not do this, the shell can extend itself to * by using files in the hand, so tar can get a list of files instead of a pattern It is, or nobody, it may be to make the command illegal to some extent that it does not suit you.

For example, type:

  $ tar -c -f ARCHIVE.TAR - Instead of the '* .o' directory < / Code> 

Exclude:

  $ tar -c -f ARCHIVE.TAR --exclude * .o directory  
  • When using the deprecated options in tar you should use shell syntax or globbying instead of syntax instead of regexp . If you try to use the regexp syntax to exclude the file, your order may fail.

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -