Thursday, April 28, 2011

How do I use a shell command to tar a list of files and folders with exclusions

Hi,

How do I tar a list of files and folders (all in the same directory) with the exclusion of a single directory (which contains a huge amount of data)

From stackoverflow
  • tar --exclude=PATTERN xvzf nameof.tar.gz ./*

    PATTERN can be the directory name. GNU tar.

    deepwell : If you have part of a file/dir name that matches PATTERN, it will also get excluded from being backed up. This is a little dangerous.
  • I think it may depend on your version of tar. You can use 'man tar' or 'tar --help' to check for details on your version. But the options I found are:

    tar -X filename: excludes anything listed in the given text file
    tar --exclude=pattern: excludes anything matching the pattern

  • Hey thanks for the superfast response!

    1 quick question though - do I need to add the individual files/folders to this command that I want tar'd or can I do something like "tar --exclude=MYEXCLUDEDDIRECTORY xvzf mydirectoryiwant.tar.gz ./mydirectoryiwant/

    Zsolt Botykai : You can do --exclude=MYDIRECTORY.
  • actually just figured it out with your help - many thanks!

    Zsolt Botykai : Then it's time to mark my answer as correct, and close the question.

0 comments:

Post a Comment