Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5467
  • Last Modified:

tar --exclude

I want to tar up a large directory.
I want to exclude some specific archive sub-directories and previous application release sub-directories.
My company does not allow open source tools like gnu tar, which I beieve has an --exclude option to tar.
How  is the best way to exclude specific sub-directories when making a tar of a directory.
Thanks for your help!
  • 2
  • 2
  • 2
  • +4
2 Solutions
If your company doesn't allow open source tools, then they will have to get rid of Solaris now that it has gone open source

What version of Solaris do you run?

In Solaris 9 at least, you have the -X option to specify a file exclude list.
Allow me to echo Tintin's rant. Modern Solaris, starting with v8 and especially v10, is loaded with F/OSS tools. Examples include the zlib compression library, OpenSSH, OpenSSL, gzip, bash, Apache and I'm sure more that I can't think of right this second. Guess the inmates are running the place where you are.
Hi all,

The -X option is available in Solaris 2.6.

You could also use find to exclude filename like this:

find /tmp ! -name 'banana*'

Hope this helps,

Regards, Nisus
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

theoradicallyAuthor Commented:

So, I created a file called Exclude, and put the directories that I wanted excluded in that file
then ran

tar cvfX ted.tar ./* Exclude

to create a tar file called ted.tar that excluded directories listed in the file called Exclude
Thanks for your help
theoradicallyAuthor Commented:
OK, my comment above worked on a Solaris 9 test box, but then when I went on to my
production Solaris 8 box, the

tar cvfX ted.tar ./* Exclude

format did not work.  It did not exclude the dirs in the Exclude file.
I listed them as relative path and then tried full path.
Any suggestions
Compile GNU tar and don't tell anyone?

That or explain to the company that by not allowing you to use common and standard tools, for which there is no licensing restrictions, costs, or practical IP concerns, that your productivity will be greatly reduced and you'll have to spend a good deal of time re-inventing the wheel.

If you don't believe they'll listen to reason, then I would seriously consider the use of GNU tools under a don't-ask-don't-tell model.  Linux has been used in that style in enterprise for a long time now.  Even Microsoft has had Linux boxes on their network  (linux.microsoft.com I believe, which presumably was there for testing, which was running RedHat Linux and was reachable by telnet from the outside world for about 5 hours...)

It might be possible to use tar from a newer version of Solaris, static compiled if necessary.

tar cvfX ted.tar Exclude .

Syntax is

    /usr/sbin/tar c [ bBefFhilvwX [ 0-7 ]] [ device ] [ block ]
          [ exclude-filename ... ] [ -I include-filename ]
          filename ...  [ -C directory filename ]

So I would say instead of

# tar cvfX ted.tar ./* Exclude

You should go for

# tar cvfX ted.tar Exclude ./*

Also important could be:

 When using r,u,x, orX, the named files must match exactly to
     the  corresponding  files  in  the tarfile.  For example, to
     extract ./filename, you must  specify  ./filename,  and  not
     filename.  The t option displays how each file was archived.

oops... tintin already suggested this... diddn't want to steal points :-))
Hanno P.S.IT Consultant and Infrastructure ArchitectCommented:
Yes, the directory (files) to be backed up is always last in the command ;-)

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now