5

I have a symbolic link formerly pointing to a Dropbox directory. I don't know what I did wrong, but apparently now it points to itself.

hyper@mypi:/home/hyper/test$ ls -l
total 1024
lrwxrwxrwx 1 hyper hyper 7 Feb 15  2013 Dropbox -> Dropbox

When I try to remove the link I get:

hyper@mypi:/home/hyper/test$ rm Dropbox
rm: cannot remove ‘Dropbox’: Not a directory

What else can I try to get rid of this link?

Part of the Output of strace rm Dropbox:

close(3)                                = 0
ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
newfstatat(AT_FDCWD, "Dropbox", {st_mode=S_IFLNK|0777, st_size=7, ...}, AT_SYMLINK_NOFOLLOW) = 0
geteuid()                               = 1000
newfstatat(AT_FDCWD, "Dropbox", {st_mode=S_IFLNK|0777, st_size=7, ...}, AT_SYMLINK_NOFOLLOW) = 0
unlinkat(AT_FDCWD, "Dropbox", 0)        = -1 ENOTDIR (Not a directory)
open("/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=2570, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f7ce00fc000
read(3, "# Locale name alias data base.\n#"..., 4096) = 2570
read(3, "", 4096)                       = 0
close(3)                                = 0
munmap(0x7f7ce00fc000, 4096)            = 0
open("/usr/share/locale/en_US/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en_US/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en/LC_MESSAGES/coreutils.mo", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=619, ...}) = 0
mmap(NULL, 619, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f7ce00fc000
close(3)                                = 0
open("/usr/lib/charset.alias", O_RDONLY|O_NOFOLLOW) = -1 ENOENT (No such file or directory)
write(2, "rm: ", 4rm: )                     = 4
write(2, "cannot remove \342\200\230Dropbox\342\200\231", 27cannot remove ‘Dropbox’) = 27
open("/usr/share/locale/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
write(2, ": Not a directory", 17: Not a directory)       = 17
write(2, "\n", 1
)                       = 1
lseek(0, 0, SEEK_CUR)                   = -1 ESPIPE (Illegal seek)
close(0)                                = 0
close(1)                                = 0
close(2)                                = 0
exit_group(1)                           = ?
+++ exited with 1 +++
  • 1
    Have you tried fscking the filesystem? If /home is on your root filesystem, you'll have to reboot to do this. – Warren Young Feb 17 '14 at 10:46
  • 1
    Do you have an alias for rm? What does strace rm Dropbox tell you? – Stéphane Chazelas Feb 17 '14 at 10:55
  • Try ln -sfing to a different location? – mniip Feb 17 '14 at 11:38
  • Can you give us the relevant output (at the end) of strace rm Dropbox? You could try to create a new folder, move the link there and delete the folder afterwards: mkdir tmp; mv Dropbox tmp/; rm -rf tmp/ – Hauke Laging Feb 17 '14 at 11:42
  • I added the output to my first post above. – HyperCube Feb 17 '14 at 12:30
2

The error message does not refer to the symlink but to the current directory!

man 2 unlinkat:

int unlinkat(int dirfd, const char *pathname, int flags);

ERRORS

ENOTDIR

pathname is relative and dirfd is a file descriptor referring to a file other than a directory.

Thus you should cd at least one level above and have a look at the directory. Has it been deleted or something like that (usually not possible when it is the CWD of a process).

  • 1
    Good call, this must be the problem. rm has no problem deleting a circular symlink: ln -s foo foo; ls -l foo; rm foo. OP has probably deleted (or perhaps moved or read-protected) the directory cortaining the symlink. Kill that shell or do a cd to your home directory, come back and try again. – alexis Feb 17 '14 at 12:44

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.