Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing a directory with no "." or ".." directories.

Status
Not open for further replies.

itr0754

Technical User
Dec 17, 2002
58
0
0
PR
I have a directory in which the user removed the "." and ".." entries and now when I do an "ls" all I get is:

ls: 0653-341 The file . does not exist.

I've tried to remove the directory altogether but I cannot do that either. Basically, I can't use or access the directory. I'd like to just delete it and recreate it. How can I do this ?? Thanks !!

Ivan
 
Never had a directory missing the . and .. entries. But I have had to remove directories by inode. Let's say I have a directory called test in /home/hallux

$ cd /home/hallux
$ ls -i # to get the inode number for test, it's 16479
$ find . -inum 16479 -exec rmdir {} \;

Now the directory should be gone.
-Hallux
 
You can use fsdb to zero out the ln and szl then run fsck on the FS and answer no to reconnect and yes to clear directory.
 
Hi itr0754

Whenever we create a directory by using unix command:mkdir
The two standard entries such as . and .. will be created.
They are very important entries.If any one deletes them ...the
directory will become invalid...neither u can access dir nor create any file in it...nothing can be done...For name sake u can see directory name....but no use..
Even u can't delete that directory depleted of . nad .. entries....
Bottom line is neither deletion of dir from disk nor recreating .(dot) and ..(dots) is feasible
There ends the matter....




sushveer
IBM certified specialist-p-series AIX5L System Administration
AIX/SOLARIS/WEBSPHERE-MQ/TIVOLI Administrator
 
Hi itr

As Hallux suggested u can delete the directory by using inode number only....That sysntax will 100% work to remove the directory by mentioning inode number of the dir in question.

sushveer
IBM certified specialist-p-series AIX5L System Administration
AIX/SOLARIS/WEBSPHERE-MQ/TIVOLI Administrator
 
I am curious as to how the person deleted . and .. .

The only way I could do it was to log on twice, cd into one of the directories and then in the other login window, remove the directory. And the ls did indeed show no . or .. .

But when I was in the second window and did a cd ../../, there was no problem and the directory (of course) was gone.

You may be in a heap of trouble, however, depending on where in relation to root or /usr or some other very important directory/filesystem the rm -r that caused the problem was done and who the user was signed in as when the rm -r was done.

I've seen operating systems deleted in this manner.

Good luck.
 
Hey thanks for all the help !! I've tried Hallox's recomendation but I am uncertain about the sintax of the last command. Should I literally type :

find . -inum 770048 -exec rmdir {} \;

When I do, I get these messages:

rmdir: 0653-611 Directory ./SABI.old is not empty.
find: 0652-023 Cannot open file ./SABI.old.
find: 0652-031 ./SABI.old is not a valid directory.

Obviously, the directory in question is SABI.old and its inum value is 770048.

I wish I knew how the "." and ".." entries were deleted !! This is a working directory that the DBA uses and only God knows what he does !!
 
Using `find` with "-exec cmd {} \; " is the old method. The new way and preferred is `find -inum 1234 | xargs rm` .
 
AIXSPadmin, wouldn't you have to use rm -r given the first error message itr075 received (the directory not empty message)?

And itr075: we could all probably write books about the mysterious jams DBAs get themselves into!
 
Ok, I tried the "find . -inum 770048 |xargs rm -r" and I still get the same message I mentioned earlier. It looks like I'll have to somehow fix the directory before I can make any changes to it.
 
Xargs is used to handle large amounts of arguments, avoiding the bothersome "Too many arguments" problem with overflowing the command-line buffer. I have received the "Too many arguments" error when trying to delete files in sendmail directories and other situations where there are hundreds/thousands of files to delete. I have never heard that using -exec is the "old" way (maybe my hearing isn't what it used to be :) ), but do know that "-exec" will handle the deletion of a single directory as I described without overflowing a buffer.

In case somebody wants to read more about xargs, go to the link:
 
And I am sure you still use [] instead of [[]] too. Read the KornShell documentation because -exec is superceded by xargs. And I am sure you use functionname() {} instead of functionname {} in Ksh too, even though the latter is more powerful.
 
it was my understanding that

funcname () {}

and

function funcname {}

were equivalent. but perhaps i have an older O'Reilly book, or just didn't understand what i read. =)

IBM Certified -- AIX 4.3 Obfuscation
 
Run an fsck on the filesystem that the directory is mounted on and it should repair the directories missing the . and .. links missing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top