1

T would like to use the tar command in Linux to back up some files, but i would like to exclude a specific directory from the archive.

How can I do that?

voretaq7
  • 79,879
  • 17
  • 130
  • 214
haim evgi
  • 753
  • 1
  • 10
  • 15

2 Answers2

3

so, lets back up the directory /directory and everything in it, but ignoring any files called IGNORE-ME.

tar -cf backup.tar /directory --exclude "IGNORE-ME"

If it wasn't snowing out, i'd probably point out that man tar is as good as RTFM (and google 'tar exclude file' is even faster).

BuildTheRobots
  • 842
  • 5
  • 11
2

You can also put all of the patterns in a file and use:

-X, --exclude-from=FILE
              exclude files matching patterns listed in FILE
Kyle Brandt
  • 83,619
  • 74
  • 305
  • 448
  • much better answer than mine -well, far more practical assuming you want to mask more than the one file :) see, I read the man page, but obviously not all the way down to -X ;) – BuildTheRobots Jan 06 '10 at 20:22