我不小心反转了我的 ln 的参数并调用:
ln -s my_link my_dir
其中 my_dir 已经存在,而 my_link 不存在。我删除了 my_dir,但无法删除 my_link。
如果我 ls -l my_link 的父目录,我会得到两个不同的响应之一:
l????????? ? ? ? ? ? my_link
或者:
lrwxrwxrwx 1 username username 8 Mar 20 16:34 my_link
如果我打电话,rm my_link
我会得到:
rm: cannot remove `my_link': Not a directory
而且,我不确定它是否相关,但 my_link 位于网络安装驱动器上。
有人知道我在这里做了什么,以及如何删除断开的链接吗?
编辑: 我查看了我的 bash_history 并找到了我运行的命令。看来我并没有真正删除 my_dir,它只是消失了。而且我运行了几个错误的 ln 命令版本。
以下是在出现删除错误之前我运行的未编辑的命令列表:
ln -s test_dir ~/netdrive/test_dir/
ln -s test_dir ~/netdrive/test_dir
ln -s test_dir/ ~/netdrive/test_dir/
您会注意到,我已删除 my_link 和 my_dir。实际名称均为 test_dir,这可能造成了一些混淆(我希望以后再也不会犯这样的错误)。
因此现在不再有目录 ~/test_dir,有一个目录 ~/netdrive/test_dir/,并且有断开的链接 ~/netdrive/test_dir/test_dir
我要删除的是最后一个。我希望这能澄清事实,而不是让事情变得更加混乱。
编辑2:
我的操作系统是 CentOS,并且我很确定网络驱动器是 Samba。
以下是输出的最后几行strace -f -v unlink test_dir
:
unlink("test_dir") = -1 ENOTDIR (Not a directory)
open("/usr/share/locale/locale.alias", O_RDONLY) = 3
fstat(3, {st_dev=makedev(8, 3), st_ino=1573552, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=8, st_size=2512, st_atime=2012/03/21-02:19:02, st_mtime=2012/03/15-13:42:39, st_ctime=2012/03/16-05:31:49}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc843b2f000
read(3, "# Locale name alias data base.\n#"..., 4096) = 2512
read(3, "", 4096) = 0
close(3) = 0
munmap(0x7fc843b2f000, 4096) = 0
open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US.utf8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.UTF-8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.utf8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en/LC_MESSAGES/coreutils.mo", O_RDONLY) = 3
fstat(3, {st_dev=makedev(8, 3), st_ino=1575882, st_mode=S_IFREG|0644, st_nlink=2, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=8, st_size=435, st_atime=2012/03/20-11:53:41, st_mtime=2011/12/07-16:51:00, st_ctime=2011/12/21-05:34:01}) = 0
mmap(NULL, 435, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc843b2f000
close(3) = 0
write(2, "unlink: ", 8unlink: ) = 8
write(2, "cannot unlink `test_dir'", 24cannot unlink `test_dir') = 24
open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.utf8/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)
write(2, ": Not a directory", 17: Not a directory) = 17
write(2, "\n", 1
) = 1
close(1) = 0
close(2) = 0
exit_group(1) = ?
最后几行来自strace -f -v rm test_dir
:
newfstatat(AT_FDCWD, "test_dir", 0x7fff71464640, AT_SYMLINK_NOFOLLOW) = -1 ENOTDIR (Not a directory)
open("/usr/share/locale/locale.alias", O_RDONLY) = 3
fstat(3, {st_dev=makedev(8, 3), st_ino=1573552, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=8, st_size=2512, st_atime=2012/03/21-02:19:02, st_mtime=2012/03/15-13:42:39, st_ctime=2012/03/16-05:31:49}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f039e56b000
read(3, "# Locale name alias data base.\n#"..., 4096) = 2512
read(3, "", 4096) = 0
close(3) = 0
munmap(0x7f039e56b000, 4096) = 0
open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US.utf8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.UTF-8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.utf8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en/LC_MESSAGES/coreutils.mo", O_RDONLY) = 3
fstat(3, {st_dev=makedev(8, 3), st_ino=1575882, st_mode=S_IFREG|0644, st_nlink=2, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=8, st_size=435, st_atime=2012/03/20-11:53:41, st_mtime=2011/12/07-16:51:00, st_ctime=2011/12/21-05:34:01}) = 0
mmap(NULL, 435, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f039e56b000
close(3) = 0
write(2, "rm: ", 4rm: ) = 4
write(2, "cannot remove `test_dir'", 24cannot remove `test_dir') = 24
open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.utf8/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)
write(2, ": Not a directory", 17: Not a directory) = 17
write(2, "\n", 1
) = 1
close(0) = 0
close(1) = 0
close(2) = 0
exit_group(1) = ?
答案1
确保没有包含尾随的 /
即rm my_link
不rm my_link/
尾随的 / 表示您想要删除符号链接之外的内容
答案2
试着做:
rm -rf my_link
我在本地文件系统和网络文件系统(NFS)上对其进行了测试并且它运行正常。
答案3
你有没有尝试过rm -rf my_link
?
答案4
我设法解决了这个问题,尽管我不完全明白到底出了什么问题或是怎么回事。
看着神秘文件,“不是目录”,我发现有人遇到了类似的问题。他们能够通过 ssh 进入共享的机器并从那里删除“神秘文件”。
我没有该机器的 ssh 权限,但我可以使用 FTP。而且,令人惊讶的是,我能够删除该链接。
我猜问题出在 Samba 和错误的 ln 调用上。感谢您提供的帮助来解决这个问题。