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"
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.
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:
In case you didn't get the memo, today is International Gratuitous Backslash Quoting Day. Don't forget to celebrate.
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).
One wonders why you have a directory with no permissions. I suppose, if you can't see in it, then you can't back it up and you can't extract it anyway. As backups need to be able to set permissions when they are restored, this is a process for the superuser really.
If you have superuser access, then it seems to work fine:-
RBATTE1 @ /usr/home/RBATTE1/uf>sudo find . -exec ls -ld {} \;
drwxr-xr-x 3 RBATTE1 SYSSUP 256 19 Mar 09:29 .
d--------- 2 RBATTE1 SYSSUP 256 19 Mar 09:31 ./dufdir
-rw-r--r-- 1 RBATTE1 SYSSUP 5 19 Mar 09:31 ./dufdir/file3
-rw-r--r-- 1 RBATTE1 SYSSUP 6 19 Mar 09:29 ./file1
---------- 1 RBATTE1 SYSSUP 4 19 Mar 09:29 ./file2
RBATTE1 @ /usr/home/RBATTE1/uf>sudo tar -cvf ../uf.tar .
a .
a ./dufdir
a ./dufdir/file3 1 blocks
a ./file1 1 blocks
a ./file2 1 blocks
RBATTE1 @ /usr/home/RBATTE1/uf>sudo rm -r *
RBATTE1 @ /usr/home/RBATTE1/uf>sudo find . -exec ls -ld {} \;
drwxr-xr-x 2 RBATTE1 SYSSUP 256 19 Mar 09:35 .
RBATTE1 @ /usr/home/RBATTE1/uf>sudo tar -xvf ../uf.tar
x .
x ./dufdir
x ./dufdir/file3, 5 bytes, 1 tape blocks
x ./file1, 6 bytes, 1 tape blocks
x ./file2, 4 bytes, 1 tape blocks
RBATTE1 @ /usr/home/RBATTE1/uf>sudo find . -exec ls -ld {} \;
drwxr-xr-x 3 RBATTE1 SYSSUP 256 19 Mar 09:29 .
d--------- 2 RBATTE1 SYSSUP 256 19 Mar 09:31 ./dufdir
-rw-r--r-- 1 RBATTE1 SYSSUP 5 19 Mar 09:31 ./dufdir/file3
-rw-r--r-- 1 RBATTE1 SYSSUP 6 19 Mar 09:29 ./file1
---------- 1 RBATTE1 SYSSUP 4 19 Mar 09:29 ./file2
RBATTE1 @ /usr/home/RBATTE1/uf>
I am designing a script that worlks like recycle bin funtcionality in windows.
So if you accidently delete a directory which has no permission you would not able to do it and the tar file created should not contain any traces of this directory.
I am testing a senario. below are the cronological events i am testing for my script.
i created a directory with contents. change permissions to 0.
tried deleting it. TAR file contain the empty directory with the same name.
Now if i try to extract the tar and lets suppose the original directory has regained it access then this empty directory replaces the directory with contents.
So i am trying to identifyu this directory and remove from the tar that is created.