Unlink (remove) directory symlink

5,297

./base_DATA/ is a normal directory that existed before. Your ln command created a symlink inside it. The symlink is ./base_DATA/DATA. You can unlink it:

unlink ./base_DATA/DATA
Share:
5,297

Related videos on Youtube

alex
Author by

alex

Updated on September 18, 2022

Comments

  • alex
    alex over 1 year

    I did:

    ln -s /DATA/ ./base_DATA/
    

    and I'd like to unlink. Simply:

    unlink ./base_DATA
    

    but... unlink: cannot unlink './base_DATA': Is a directory

    According to this answer (and many other online) the problem is usually the trailing space in the unlink command. But I get this error regardless.

    Any ideas how to tackle this?

    • ctrl-alt-delor
      ctrl-alt-delor almost 6 years
      unlink is not the opposite of ls -s. It is basically same as rm (in this case. rm has more powers.).
    • ctrl-alt-delor
      ctrl-alt-delor almost 6 years
      If using gnu ln then consider using the -t and -T option. They are designed to make the arguments to cp, mv, and ln unambiguous.
    • alex
      alex almost 6 years
      @ctrl-alt-delor doesn't rm -r delete the contents of linked diretory?
    • ctrl-alt-delor
      ctrl-alt-delor almost 6 years
      rm -r will remove a directory and everything in it. It will also remove a single file (including a symlink). rm can also take a list of filenames. unlink excepts one filename, and only removes single files. Note: nether delete, they remove/unlink directory entries. If a file has zero references (no entry in any directory, no open files), then it is deleted.
  • alex
    alex almost 6 years
    I see, this makes sense. And works obviously. Thanks