0

I have what looks to be a directory directory dir2, I once moved it from another directory dir1 to back it up and created a new dir1.

Now I suddenly saw it again, realized I didn't need it and did rm -r -f dir2, and found out that my new dir1 is also empty.

I got my files back (is was a code repository, so just some changes lost - bummer), but I still want to remove this redundant link or whatever dir2 is.

When I tried rmdir (before I realized I deleted everything) I got an error Not a directory. What is it and how do I remove it? Using bash on OSX terminal.

Update: Per suggestions below:

ls -ld dir2 outputs drwxr-xr-x. 19 asaf users 4096 Mar 8 13:09 dir2/

file dir2/ outputs dir2/: directory

file dir2 outputs dir2: symbolic link to ...'

  • 5
    share the output of ls -l dir2 , – Gaurav Pundir Mar 8 '16 at 11:16
  • You can also use file dir2 to get more information on it. - From your description is might be a symlink. Maybe it already was a symlink in the beginning and you simply moved that symlink, but the actual files live somewhere else. - But to be sure we need the output of ls -l dir2 or file dir2. – michas Mar 8 '16 at 13:34
  • @GauravPundir Make that ls -ld dir2 (in case it is in fact a directory) – Gilles Mar 8 '16 at 22:40
  • @michas If it was a symlink, rm -r -f dir2 wouldn't have deleted anything but the symlink. (It's possible that the actual command was rm -r -f dir2/, which would have descended into the directory, or that the symlink was deleted and sprite's changes are still in whatever location the symlink pointed to.) – Gilles Mar 8 '16 at 22:43
  • 1
    @sprite As i thought, its a symlink. use unlink command unlink dir2. – Gaurav Pundir Mar 10 '16 at 12:02
4

It's impossible to know what happened given that the evidence is now deleted. Your descriptions of the symptoms is consistent with dir2 being a symbolic link to a directory. A symbolic link is a sort of special file that says “the real file is actually over there”. The symbolic link itself isn't a directory, so rmdir can't do anything with it. But accesses to the content of the symbolic link (files in the directory for a symbolic link pointing to a directory, file contents for a symbolic link pointing to a regular file) go to the target of the link transparently, so you wouldn't have noticed anything when using cd dir2 or when editing files in the directory.

If this is the case (which is plausible, but not at all certain!), then the command rm -r -f dir2 only deleted the symbolic link, and the directory containing your changes still exists… somewhere. Since you've deleted the link, it might be difficult to find where, but you can try looking for the file names that you know were in that directory with the locate command or with an equivalent GUI (Spotlight?).

In the future, run

ls -ld dir2

That would tell you what kind of file dir2 is. If the line begins with d, it's a directory. If the line begins with l, it's a symbolic link, and the output indicates where it points to (the part after ->).

  • Updated question with output. – sprite Mar 10 '16 at 7:04
  • 1
    @sprite I thought you'd deleted dir2? Anyway the output from ls and file shows that it is indeed now a symbolic link to a directory. – Gilles Mar 10 '16 at 9:29
3

If you run ls -ld dir2 it should tell us a lot about the situation.

It could be a symlink, or an odd type of file. I know at this point we're assuming it is a directory, but there are other options. It may even be a lost automount share.

Also try running file dir2. If it is anything but a true directory, you're likely going to to see an error with rmdir.

  • Updated question with output. – sprite Mar 10 '16 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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