How in the world do you delete a symbolic link named "."?

Discussion in 'macOS' started by Undecided, Sep 26, 2014.

  1. Undecided, Sep 26, 2014
    Last edited: Sep 26, 2014

    Undecided macrumors 6502a

    Joined:
    Mar 4, 2005
    Location:
    California
    #1
    FML. I accidentally created a symbolic link named "." :eek: :eek:

    Yeah.

    It's not visible in Finder, so we're playing in terminal.

    Any idea how to remove this?

    EDIT: it was a comma, actually.
     
  2. fehhkk macrumors 6502a

    fehhkk

    Joined:
    Jun 11, 2009
    Location:
    Chicago, IL
    #2
    Doing "rm ." doesn't work?

    It shouldnt remove the current directory since its not an rmdir command.
     
  3. Undecided thread starter macrumors 6502a

    Joined:
    Mar 4, 2005
    Location:
    California
    #3
    No, because it thinks you're trying to use . to delete the directory.

    But I figured it out.

    Delete by inode number instead of file name. OMG.

    find . -inum inodenumber -exec rm -i {} \;

    Whew.
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    I'm glad you figured out how to delete it, but I'd like to know how you created a symlink named "." in the first place.

    I'm not doubting you, because I can think of at least one obscure way. But nothing I can think of is something that happens by accident.
     
  5. Undecided thread starter macrumors 6502a

    Joined:
    Mar 4, 2005
    Location:
    California
    #5
    ln -s /source/file/to/link/to .
     
  6. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #6
    On which OS version? And what file-system format is the destination disk?

    Whatever OS version or file-system I try that on, it sees "." as an existing directory. That makes it fall into the pattern "ln -s source_file target_dir", which creates the file "./leafname", where "leafname" is the final pathname component of source_file. See the 'ln' man page for details.


    If there is some directory that doesn't have an entry named ".", then that directory is damaged. Also, the "." entry should always refer to the enclosing directory itself. The fact that this happened at all suggests you may have some latent file-system damage. Consider running "Verify Disk" in Disk Utility.app, and see if any errors are listed.
     
  7. Undecided thread starter macrumors 6502a

    Joined:
    Mar 4, 2005
    Location:
    California
    #7
    Mmmm, going through the terminal history, I guess it was actually a comma! Hard to see from 12 feet away.

    It went like this:

    ls
    ln -s Documents/ ,

    ls -la
    Maybe "rm ," would have worked after all...still, I learned about inodes.
     
  8. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #8
    That makes more sense. Thanks for taking the time to clarify it.

    Yes, "rm ," would have worked. You can test it with these commands:
    Code:
    touch ,
    rm ,
    
    The first command makes an empty file. The second removes it.
    You can do this in any directory where you have write privileges.
     

Share This Page