1

mkdir -p /a/b/c我在 AIX 上试过。当ab不存在时,此命令创建a,bc. 但是当a两者b都存在时,它会给出一个错误

无法创建 /a/b。/a/b: 文件存在

并返回错误代码 2。

对此有什么帮助吗?

4

3 回答 3

2

我刚刚遇到了类似的症状 - 除了它是一个损坏的远程挂载点(在这种情况下使用 sshfs)并且与“挡道”的文件无关:

$ mkdir -p /mnt/sshfs-remote
mkdir: cannot create directory `/mnt/sshfs-remote': File exists
$ ls -lscrath /mnt/sshfs-remote
/bin/ls: cannot access /mnt/sshfs-remote: No such file or directory
$ ls -lscrath /mnt
/bin/ls: cannot access /mnt/sshfs-remote: No such file or directory
total 4.0K
    ? d?????????  ? ?    ?        ?            ? sshfs-remote/

一个 umount* 把它整理出来。我还在脚本中添加了一个异常,该异常触发了错误以尝试卸载。

$ umount -l /mnt/sshfs-remote ; mount /mnt/sshfs-remote
$ ls -lsahd /mnt/sshfs-remote
4.0K drwxr-xr-x 1 root root 6 Mar 11 09:20 /mnt/sshfs-remote/
$ mkdir -p /mnt/sshfs-remote
$ echo $?
0

*如果有人想知道我在 umount 上使用的 -l:这可能是不必要的 - 但在远程安装上,我发现它是一种更清洁/更简单的方式来“继续使用它”。从 umount 手册页:

   -l, --lazy
          Lazy unmount.  Detach the filesystem from the file hierarchy now, and clean up all references to this filesystem as soon
          as it is not busy anymore.  (Requires kernel 2.4.11 or later.)
于 2015-03-11T07:57:28.493 回答
0

我使用 Parallels 文件系统发生了这种情况。虚拟机抱怨存在一个目录,即使“ls”看不到它。当我进入目录时,它允许它,但随后 ls 会失败。所以这似乎是一个文件系统缓存错误。我通过转到主机并使用文件创建目录,然后返回虚拟机并删除目录来解决它。之后,虚拟机文件系统已正确同步,我可以正常使用 mkdir 创建目录。

在虚拟机上:

> mkdir -p build/a/b/c  <-- failed with "file exists"
> cd build              <-- allowed
> ls                    <-- failed

在主机上:

> mkdir build
> touch build/foo

在虚拟机上:

> rm -rf build
> mkdir -p build/a/b/c    <-- Success
于 2017-04-23T23:10:53.620 回答
-1

我认为您正在谈论这种情况:

bash-2.02# mkdir -p /a/c/d
bash-2.02# rm -rf /a/c/d
bash-2.02# mkdir -p /a/c/d
mkdir: cannot create /a/c
/a/c: File exists
bash-2.02# echo $?
2
bash-2.02#
于 2013-06-27T11:48:42.620 回答