Results 1 to 7 of 7

Thread: Cannot unlink symlink to directory

  1. #1
    Join Date
    Oct 2006
    Beans
    27

    Cannot unlink symlink to directory

    I want to remove a symlink to a directory, after that I will create another symlink.

    I get errors:

    Code:
    mythuser@PVR1:/usr/share/zoneminder$ ls -li
    total 48
    2876739 drwxr-xr-x 2 root root 4096 Dec 30 15:06 ajax
    2876993 lrwxrwxrwx 1 root root   17 Feb 12  2012 cgi-bin -> ../../lib/cgi-bin
    2876747 drwxr-xr-x 2 root root 4096 Dec 30 15:06 css
    2876697 drwxr-xr-x 2 root root 4096 Dec 30 15:06 db
    2876990 lrwxrwxrwx 1 root root   28 Jan 20 10:00 events -> /mnt/raid2/zoneminder/events
    2876751 drwxr-xr-x 2 root root 4096 Dec 30 15:06 graphics
    2876991 lrwxrwxrwx 1 root root   28 Jan 20 10:01 images -> /mnt/raid2/zoneminder/images
    2876755 drwxr-xr-x 2 root root 4096 Dec 30 15:06 includes
    2876988 -rw-r--r-- 1 root root 3795 Feb 12  2012 index.php
    2876763 drwxr-xr-x 2 root root 4096 Dec 30 15:06 js
    2876766 drwxr-xr-x 2 root root 4096 Dec 30 15:06 lang
    2876787 drwxr-xr-x 5 root root 4096 Dec 30 15:06 skins
    2876989 drwxr-xr-x 2 root root 4096 Feb 12  2012 sounds
    2876992 lrwxrwxrwx 1 root root   26 Feb 12  2012 temp -> /var/cache/zoneminder/temp
    2876984 drwxr-xr-x 2 root root 4096 Feb 12  2012 tools
    2876985 drwxr-xr-x 2 root root 4096 Dec 30 15:06 views
    Code:
    mythuser@PVR1:/usr/share/zoneminder/events$ unlink /mnt/raid2/zoneminder/events
    unlink: cannot unlink `/mnt/raid2/zoneminder/events': Is a directory
    or
    Code:
    mythuser@PVR1:/usr/share/zoneminder/events$ rm /mnt/raid2/zoneminder/events
    rm: cannot remove `/mnt/raid2/zoneminder/events': Is a directory
    or
    Code:
    mythuser@PVR1:/usr/share/zoneminder/events$ rmdir  /mnt/raid2/zoneminder/events
    rmdir: failed to remove `/mnt/raid2/zoneminder/events': Directory not empty

  2. #2
    Join Date
    Jan 2009
    Location
    Santander, Spain
    Beans
    1,977
    Distro
    Ubuntu Gnome 16.04 Xenial Xerus

    Re: Cannot unlink symlink to directory

    As I understand from the error obtained you are trying to unlink a directory but you have to unlink a FILE: http://manpages.ubuntu.com/manpages/.../unlink.1.html

    Also, this link can be useful: http://manpages.ubuntu.com/manpages/.../unlink.2.html

  3. #3
    Join Date
    Apr 2012
    Beans
    7,110

    Re: Cannot unlink symlink to directory

    It looks like you are specifying the wrong 'end' of the link - if you have

    Code:
    /path/to/symlink -> /path/to/real/dir
    then you shouldn't be trying to unlink or rm /path/to/real/dir, you should be doing

    Code:
    unlink /path/to/symlink
    or

    Code:
    rm /path/to/symlink
    In your case (since you are already in the parent dir), it should be enough to do

    Code:
    unlink events
    or
    Code:
    rm events

  4. #4
    Join Date
    Oct 2006
    Beans
    27

    Re: Cannot unlink symlink to directory

    Thanks Steeldriver, you were correct. However, it deleted the directory, not just the symlink:

    Code:
    mythuser@PVR1:/usr/share/zoneminder$ ls -li
    total 48
    2876739 drwxr-xr-x 2 root root 4096 Dec 30 15:06 ajax
    2876993 lrwxrwxrwx 1 root root   17 Feb 12  2012 cgi-bin -> ../../lib/cgi-bin
    2876747 drwxr-xr-x 2 root root 4096 Dec 30 15:06 css
    2876697 drwxr-xr-x 2 root root 4096 Dec 30 15:06 db
    2876990 lrwxrwxrwx 1 root root   28 Jan 20 10:00 events -> /mnt/raid2/zoneminder/events
    2876751 drwxr-xr-x 2 root root 4096 Dec 30 15:06 graphics
    2876991 lrwxrwxrwx 1 root root   28 Jan 20 10:01 images -> /mnt/raid2/zoneminder/images
    2876755 drwxr-xr-x 2 root root 4096 Dec 30 15:06 includes
    2876988 -rw-r--r-- 1 root root 3795 Feb 12  2012 index.php
    2876763 drwxr-xr-x 2 root root 4096 Dec 30 15:06 js
    2876766 drwxr-xr-x 2 root root 4096 Dec 30 15:06 lang
    2876787 drwxr-xr-x 5 root root 4096 Dec 30 15:06 skins
    2876989 drwxr-xr-x 2 root root 4096 Feb 12  2012 sounds
    2876992 lrwxrwxrwx 1 root root   26 Feb 12  2012 temp -> /var/cache/zoneminder/temp
    2876984 drwxr-xr-x 2 root root 4096 Feb 12  2012 tools
    2876985 drwxr-xr-x 2 root root 4096 Dec 30 15:06 views
    then I did

    mythuser@PVR1:/usr/share/zoneminder$ unlink /usr/share/zoneminder/events
    unlink: cannot unlink `/usr/share/zoneminder/events': Permission denied
    mythuser@PVR1:/usr/share/zoneminder$ sudo unlink /usr/share/zoneminder/events
    [sudo] password for mythuser:
    but it deleted the source directory, in addition to the symlink. Not a big deal, there was nothing of importance in the directory, I just recreated it.

    Code:
    mythuser@PVR1:/usr/share/zoneminder$ ls -li
    total 48
    2876739 drwxr-xr-x 2 root root 4096 Dec 30 15:06 ajax
    2876993 lrwxrwxrwx 1 root root   17 Feb 12  2012 cgi-bin -> ../../lib/cgi-bin
    2876747 drwxr-xr-x 2 root root 4096 Dec 30 15:06 css
    2876697 drwxr-xr-x 2 root root 4096 Dec 30 15:06 db
    2876751 drwxr-xr-x 2 root root 4096 Dec 30 15:06 graphics
    2876991 lrwxrwxrwx 1 root root   28 Jan 20 10:01 images -> /mnt/raid2/zoneminder/images
    2876755 drwxr-xr-x 2 root root 4096 Dec 30 15:06 includes
    2876988 -rw-r--r-- 1 root root 3795 Feb 12  2012 index.php
    2876763 drwxr-xr-x 2 root root 4096 Dec 30 15:06 js
    2876766 drwxr-xr-x 2 root root 4096 Dec 30 15:06 lang
    2876787 drwxr-xr-x 5 root root 4096 Dec 30 15:06 skins
    2876989 drwxr-xr-x 2 root root 4096 Feb 12  2012 sounds
    2876992 lrwxrwxrwx 1 root root   26 Feb 12  2012 temp -> /var/cache/zoneminder/temp
    2876984 drwxr-xr-x 2 root root 4096 Feb 12  2012 tools
    2876985 drwxr-xr-x 2 root root 4096 Dec 30 15:06 views
    Is there a command to just delete the symlink?

  5. #5
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Cannot unlink symlink to directory

    Code:
    rm -i /path/to/symlink


    Use sudo if needed.
    Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide

    Tomorrow's an illusion and yesterday's a dream, today is a solution...

  6. #6
    Join Date
    Apr 2012
    Beans
    7,110

    Re: Cannot unlink symlink to directory

    What do you mean exactly by "it deleted the directory"? Is /mnt/raid2/zoneminder/events still there? That's "the directory", and that should NOT have been deleted by either an unlink OR rm of the symlink

    Or were you expecting /usr/share/zoneminder/ to still contain an 'events' dir?

  7. #7
    Join Date
    Oct 2006
    Beans
    27

    Re: Cannot unlink symlink to directory

    Yes, I expected /usr/share/zoneminder/events as a directory to remain, but no longer be symlinked to /mnt/raid2/zoneminder/events.

    It certainly is no longer symlinked but as you can see in the directory listing above, it was there before and not after the unlink command.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •