tar --exclude

Posted on 2005-04-20
Last Modified: 2013-12-27
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!
Question by:theoradically
    LVL 48

    Expert Comment

    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.
    LVL 34

    Expert Comment

    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.
    LVL 5

    Expert Comment

    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

    Author Comment


    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

    Author Comment

    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
    LVL 7

    Expert Comment

    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  ( 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.
    LVL 48

    Accepted Solution


    tar cvfX ted.tar Exclude .

    LVL 10

    Assisted Solution

    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.

    LVL 10

    Expert Comment

    oops... tintin already suggested this... diddn't want to steal points :-))
    LVL 16

    Expert Comment

    by:Hanno Schröder
    Yes, the directory (files) to be backed up is always last in the command ;-)

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
    I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
    In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now