DaveEP
DaveEP

Reputation: 1496

Unlink (Symlink) Directory to Mounted Hard Disk

I'm trying to remove a symlink that was created using:

ln -s /media/hdd2 /home/DocumentsLibrary/

These are the suggestions I've found & tried:

rm /home/DocumentsLibrary (tried with and without the trailing slash) but every time I get:

rm cannot remove '/home/DocumentsLibrary': Is a Directory

unlink /home/DocumentsLibrary (tried with and without the trailing slash) but every time I get:

unlink cannot remove '/home/DocumentsLibrary': Is a Directory

I am logged in as a user with sudo -i and I can do everything else as expected.

I've tried with the owner as root:root, and user:root (where user is my user name) and tried changing the permissions to 777 but nothing seems to work.

Having Googled this and visited many sites

including:

The wisdom seems to be that either/both the rm / unlink statements above should work, but they don't in this case.

using ls -ls gives this:

4 drwxrwxrwx 2 root root 4096 Aug 6 11:35 DocumentsLibrary

What am I missing?

Upvotes: 1

Views: 2635

Answers (2)

myaut
myaut

Reputation: 11504

using ls -ls gives this:

4 drwxrwxrwx 2 root root 4096 Aug 6 11:35 DocumentsLibrary

It seems that DocumentsLibrary already existed as directory when you tried to create symlink with this name. ln -s deals with trailing slash on destination in such cases differently:

ln -s /media/hdd2 /home/DocumentsLibrary/ (1)
ln -s /media/hdd2 /home/DocumentsLibrary  (2)

Case (1) will try to create symlink in /home/DocumentsLibrary/ named after basename of original file, so /home/DocumentsLibrary/hdd2 is created

Case (2) will try to create symlink in /home/ with name DocumentsLibrary and should fail due to name conflict.

Hence, try to do the following:

ls -l /home/DocumentsLibrary/hdd2    # check that it is symlink
rm /home/DocumentsLibrary/hdd2
rmdir /home/DocumentsLibrary
ln -s /media/hdd2 /home/DocumentsLibrary

Upvotes: 1

DaveEP
DaveEP

Reputation: 1496

Thanks to several replies above I figured out what happened, since I wasn't the one that created the symlink so didn't know if the /DocumentsLibrary existed as a directory at the time the link was created (it appears it must have been).

As suggested above, using touch to see if a file created in /DocumentsLibrary appeared in /media/hdd2 (it didn't) confirmed the symlinks were actually created inside the DocumentsLibrary directory to each of the directories on hdd2 rather than from /home/DocumentsLibrary to /media/hdd2. Not sure why I didn't sport that earlier.

Deleting each of the directories (within DoscumentsLibrary) using rm * then allowed the DocumentsLibrary itself to be deleted.

Thank you all.

Upvotes: 0

Related Questions