How to Run "tar" command to tar all files/folders but EXCLUDE other folders

Posted on 2011-10-24
Last Modified: 2012-05-12
I have a folder on Unix (AIX) called: Peoplesoft. The owner of this folder is the user I login with: PSFT811. It has a ton of files and folder under it. I have been trying to run tar command to tar all files/folders under this directory and copy it over to another server. But I keep getting permission errors even though I"m the owner of the folder.

If found out that there are 3 folders under that "Peoplesoft" folder that has a different owner. I suspect this is why I get the permission errors when i try to copy.

I was told I could run the tar command and use a: "-X" parameter provide an "exclude list" and specify the folders I want to exclude from the tar copy.

But when I try to run the command I still get permission errors. I don't think I"m running it right. See attached. Please advise on the correct tar command to specify my exclude list.

So for example, under that "Peoplesoft" folder I have 3 folders called: export, import & PrintQueue. I want to exclude these folders from the tar command so that it will allow me to tar.

Question by:matrix0511
    LVL 68

    Accepted Solution


    -X expects the name of a file containing the names of the directories to be excluded, one by line.

    The directories must appear in that file exactly as they would appear in the archive,
    so in your case the content of the exclude list could look like:


    Call this file e.g. /tmp/exclude.list and run

    tar -X /tmp/exclude.list -cvf PeopleSoft.tar PeopleSoft



    Author Comment

    @woolmilkporc: so you are saying I need to first create an exclude list file and add those folders to it?

    Im not very Unix savy, what's the best command to create this file and add those folders to the list?

    LVL 68

    Expert Comment

    Yes, you're right.

    There are several ways to create a file under Unix, maybe the simplest:

    cat >/tmp/catte <<EOF

    Type the above line by line at the command prompt (terminate each line with <ENTER>), and you're done.

    LVL 68

    Expert Comment

    Sorry, "/tmp/catte" is nonsense.

    Replace with "/tmp/exclude.list" !

    LVL 19

    Expert Comment

    It's erroring out because your user doesn't have permission to create the tar file in the folder you're running the command from

      $ tar -cvf PeopleSoft.tar PeopleSoft
      tar:  PeopleSoft.tar: Permission denied

    Change your command to:

      $ tar -cvf /tmp/PeopleSoft.tar PeopleSoft

    This will create your new tar file in /tmp.  Don't worry about the errors for the files you don't have permission to archive - the tar will still be created, but it just won't contain what you don't have access to.  You do not need to bother with the exclude list and X flag.
    LVL 68

    Expert Comment

    xterm, right you are.

    Seems I solely looked at the lower part of what matrix0511 posted.



    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    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…
    FreeBSD on EC2 FreeBSD ( is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

    734 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

    19 Experts available now in Live!

    Get 1:1 Help Now