How to avoid TAR of directory with no permissions?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to avoid TAR of directory with no permissions?
# 1  
Old 03-18-2013
How to avoid TAR of directory with no permissions?

Hi Users,

i have a situation as below;

Code:
-rw-r--r--   1 t1elkpe  cmptl          0 Mar 18 12:00 file2
----------   1 t1elkpe  cmptl          0 Mar 14 16:07 file1
d---------   3 t1elkpe  cmptl          3 Mar 18 11:23 fd


now when i am tarting the above files below is what i get as output.


HTML Code:
[t1elkpe@ /u01/appl/t1elkpe/pst/max/SCRIPTDIR$]> tar cf test.tar f*
tar: /u01/appl/t1elkpe/pst/max/SCRIPTDIR/fd: Permission denied
tar: file1: Permission denied
[t1elkpe@ /u01/appl/t1elkpe/pst/max/SCRIPTDIR$]> tar tvf test.tar
tar: blocksize = 4
d--------- 1005/250      0 Mar 18 11:23 2013 fd/
-rw-r--r-- 1005/250      0 Mar 18 12:00 2013 file2

As visible fd directory is still tar in the final tar. Is there any way i can avoid this completely.

Any help is appreciated.

Thanks and Regards
Rajan gupta

---------- Post updated at 07:52 AM ---------- Previous update was at 06:10 AM ----------

Hi Experts,

any suggestions???

Thanks.
# 2  
Old 03-18-2013
Depending on your OS version, there can be a -L flag on the tar command. This refers to a list file that you can populate beforehand. In you case:-
Code:
$ cat /tmp/my_tar_list
file2

Code:
$ tar -cL /tmp/my_tar_list -f /tmp/my_tar_file

It's not too common, but a really good option and it's in AIX at least. What OS are you using?

It's extremely useful for extracting lots of files from a huge tar-file, i.e.
Code:
$ tar -tf my_tar_file > /tmp/my_tar_list

...edit the list file created to keep just the ones you want, then ....
Code:
$ tar -xvL /tmp/my_tar_list -f my_tar_file


Another option might be to ignore or handle the backup error. The tar-file you create won't have it anyway, so is that all you really need?



I hope that this helps,
Robin
Liverpool/Blackburn
UK
# 3  
Old 03-18-2013
Why not use the -X (exclude file) option to tar, or, extended globbing in bash to unselect that directory?
You will now say "I don't use bash" or "My tar doesn't have -X" to which I'll respond "You didn't mention your system or versions or implementations"
# 4  
Old 03-18-2013
Hi Guys,

Thanks for reply. I am using solaris. And i am in process of design a shell script in bash which tar all the files mentioned as a regular expression and removes them from the location(just like recycle bin functionality) and when a particular file or directory is not able to tar completely it should ignore and tar rest of them. i have a seprate log which shows which files/dir have been tar or not tar.
Rest everything is working fine except that the when unable to tar the directory the tar file still kept the empty directory which on restoring replaces the original directory with contents which is incorrect.

If tar is not done it should not store this directory at all. How can i prevent the tar of such directories.

Hope this helps in better understanding of the issue here.

Thanks and Regards
Rajan Gupta

---------- Post updated at 09:50 AM ---------- Previous update was at 09:22 AM ----------

Another option that came in my mind is to remove the directory in tar. I know it is possible througfh exclude folder but in my case this is not working. Can anyone highlight the case how can i remove the exesting non permission empty directory from tha tar created so that i have a clean tar.

Regards
Rajan
# 5  
Old 03-18-2013
Solaris (along with the majority of UNIX systems) has pax. You could just use find with the appropriate arguments to exclude all directories with mode 0. Since pax can read the file list on stdin, you can use a simple pipe:
Code:
find . \! \( -type d -perm 0 -prune \) | pax -w > test.tar

Regards,
Alister
# 6  
Old 03-18-2013
Is the \ necessary before the ! ?
# 7  
Old 03-18-2013
Quote:
Originally Posted by ctsgnb
Is the \ necessary before the ! ?
In case you didn't get the memo, today is International Gratuitous Backslash Quoting Day. Don't forget to celebrate. Smilie

All joking aside, no; it's not necessary. I'd edit it, but it won't hurt anything. Thank you for bringing attention to it. It may have confused a novice.

However, in some circumstances an exclamation point can cause problems, e.g. in bash when history expansion is enabled (although even in this instance, if whitespace follows it, no expansion occurs).

Regards,
Alister

Last edited by alister; 03-18-2013 at 02:30 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Making Tar of directory and tar file is going to be placed

Quick question, is it possible to make a Tar of completely directory and placing the tar file in it (will this cause even the tar file to tarred ?) sample: /opt/freeware/bin/tar -cvf - /oracle | gzip > /oracle/backup.tgz will the tar file backup.tgz also include backup.tgz ? i tried... (5 Replies)
Discussion started by: filosophizer
5 Replies

2. Shell Programming and Scripting

Directoy Size - avoid cannot read directory

Hello, I need to write a script to check directory size on a linux server. I do not have access to some directories Inside the directory tree so I've got some warning in the output that say : du : cannot read directory .... Could you please help me. I did try Inside of my script to... (2 Replies)
Discussion started by: Aswex
2 Replies

3. UNIX for Dummies Questions & Answers

Directory permissions

i have an application that writes to a directory. let's call the directory: /var/app/ the permissions of this directory is: drwxrwxr-x Now the files that the application creates in this directory usually dont have read permissions for others. i know there's something called... (3 Replies)
Discussion started by: SkySmart
3 Replies

4. Solaris

Directory Permissions for 2 users on 1 directory

we want to allow user to FTP files into a directory, and then the program (PLSQL) will read and process the file, and then move the file to other directory for archiving. the user id: uftp1, group: ftp the program run in oracle database, thus have the user Id: oraprod, group: dba how to... (2 Replies)
Discussion started by: siakhooi
2 Replies

5. Shell Programming and Scripting

Checking directory permissions on UNIX directory

Hi, How do i check if I have read/write/execute rights on a UNIX directory? What I'm doing is checking read access on the files but i also want to check if user has rights on the direcory in whcih these files are present. if then...... And I check if the directory exists by using... (6 Replies)
Discussion started by: chetancrsp18
6 Replies

6. UNIX for Advanced & Expert Users

How to rsync or tar directory trees, with hidden directory, but without files?

I want to backup all the directory tress, including hidden directories, without copying any files. find . -type d gives the perfect list. When I tried tar, it won't work for me because it tars all the files. find . -type d | xargs tar -cvf a.tar So i tried rsync. On my own test box, the... (4 Replies)
Discussion started by: fld2007
4 Replies

7. Shell Programming and Scripting

tar command dont tar to original directory

HI, if I have a tarfile called pmapdata.tar that contains tar -tvf pmapdata.tar -rw-r--r-- 0/0 21 Oct 15 11:00 2009 /var/tmp/pmapdata/pmap4628.txt -rw-r--r-- 0/0 21 Oct 14 20:00 2009 /var/tmp/pmapdata/pmap23752.txt -rw-r--r-- 0/0 1625 Oct 13 20:00 2009... (1 Reply)
Discussion started by: borderblaster
1 Replies

8. Cybersecurity

Permissions ( to avoid unwanted things )

I want to make an automated system to compile & run the source codes from different persons and to tell if the output is the same with the standard one(wich is given by me). Ok, this is quite simple, but the tricky part is,how do I avoid the "bad intentions" that may result from running those... (2 Replies)
Discussion started by: spiriad
2 Replies

9. UNIX for Dummies Questions & Answers

permissions of a directory

Read and write bits make sense for a directory but what about the execute permission bit What does that imply?Is it just a filler? Saurabh (3 Replies)
Discussion started by: smehra
3 Replies

10. Shell Programming and Scripting

determine owner directory permissions from within the directory

From within a directory, how do I determine whether I have write permission for it. test -w pwd ; echo ? This doesn't work as it returns false, even though I have write permission. (4 Replies)
Discussion started by: Sniper Pixie
4 Replies
Login or Register to Ask a Question