Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I used to wonder why deleting directories via PHP or shell wasn't as easy as it was in Windows with just clicking delete. I realize now that deleting is simply unlinking files from the file allocation table, so to delete a directory, you must unlink all the files inside it.

Is it ever possible for the directory's entry to be removed, but not those of the files inside it? Do operating systems periodically check for files that can't be reached in the file system?

share|improve this question
add comment

2 Answers 2

up vote 4 down vote accepted

Many UNIXes have an unlink command which will allow user root to unlink a directory, but it does not recursively unlink the contents of the directory, so it's very dangerous. If that ever happens, use fsck to recover the disconnected directory, which will appear in the filesystem's lost+found folder with a random name (since the name was lost when the unlink happened).

share|improve this answer
add comment

Yes, it's possible, rather unlikely, since there are procedures in place in the OS to prevent this from happening, but disk errors and weirdness can cause things to happen.

This is generally what chkdsk, fsck, and a slew of other utilities are designed to do. They read the allocation tables and match them up with the known file entries... anything amiss causes some action to be taken.

In Windows, you can usually signal to Windows that you'd like a check done by looking in the Properties option when you right click on the drive icons. It might do the check then, although windows seems to be favoring startup disk checks, and it'll tell you that it'll do it on next reboot.

In Linux, ... you can seriously hurt yourself playing with the fsck utility on an active system, which is why Linux boxes generally always do their File-System ChecKs (fsck!) during startup. Simply rebooting will often cause a check to happen. (although I do know that yanking the power out from my home server when the UPS fails triggers one too!) (file system is marked dirty)

OS X? Not a clue. Kinda just figured you Sipped a Latté near the machine and it fixed whatever's wrong with itself by linking with the nearest GeniusBar. (You probably need to be in or near a Starbucks™ too I think)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.