Link to home
Start Free TrialLog in
Avatar of matrix0511
matrix0511

asked on

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

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.

Thanks.
tar.JPG
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of matrix0511
matrix0511

ASKER

@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?

Thanks!
Yes, you're right.

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

cat >/tmp/catte <<EOF
PeopleSoft/PrintQueue
PepleSoft/export
PeopleSoft/import
EOF

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

wmp
Sorry, "/tmp/catte" is nonsense.

Replace with "/tmp/exclude.list" !

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.
xterm, right you are.

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

wmp