在 OS X 中删除文件名中包含奇怪字符的文件

Sig*_*gyF 5 rm filenames macos

在我的程序出现内存错误后,我被一个文件名奇怪的文件卡住了。事实证明,它对删除具有奇怪名称的文件的所有常规方法具有很强的抵抗力。

文件名是:

%8BUȅ҉%95d%F8%FF%FF\x0f%8E%8F%FD%FF%FF%8B%B5T%F8%FF%FF%8B%85\%F8%FF%FF\x03%85x%F8% FF%FF%8B%95D%F8%FF%FF%8B%BD%9C%F8%FF%FF%8D\x04%86%8B%B5@%F8%FF%FF%89%85%90%F8 %FF%FF%8B%85X%F8%FF%FF\x03%85%9C%F8%FF%FF%C1%E7\x02%8B%8Dx

我尝试了以下方法:

  • rm *
      ? No such file or directory
  • rm -- filename
      ? No such file or directory
  • rm "filename"
      ? No such file or directory
  • ls -i 获取inode编号
      ? No such file or directory
  • stat filename
      ? No such file or directory
  • 压缩文件所在的目录
      ? error occurred while adding "" to the archive
  • 在finder中删除目录
      ? error -43
  • 在 Python 中: os.unlink(os.listdir(u'.')[0])
      ? OSError——No such file or directory
  • find . -type f -exec rm {} \;
      ? No such file or directory
  • 检查文件上的锁 lsof
      ? no locks

所有这些尝试都会导致未找到文件(此处为长文件名)错误或错误 -43。即使是ls -i.

我找不到更多选项,所以在重新格式化或修复我的文件系统之前(fsck可能会有所帮助),我想也许我错过了一些东西。

我编写了这个小 C 程序来获取 inode 编号:

#include <stdio.h>
#include <stddef.h>
#include <sys/types.h>

int main(void) 
{
  DIR *dp;
  struct dirent *ep;

  dp = opendir ("./");
  if (dp != NULL)
    {
      while (ep = readdir (dp)) {
        printf("d_ino=%ld, ", (unsigned long) ep->d_ino);
        printf("d_name=%s.\n", ep->d_name);
      }
      (void) closedir (dp);
    }
  else
    perror ("Couldn't open the directory");

  return 0;
}
Run Code Online (Sandbox Code Playgroud)

那个有效。我现在有了 inode 号,但正常的不起作用。我想我必须使用现在。find -inum inode_num -exec rm '{}' \;clri

bry*_*yan 1

尝试

find . -type f -exec rm {} \;
Run Code Online (Sandbox Code Playgroud)

您是否尝试过删除父目录?