mkdir -p返回错误“文件存在”

时间:2013-06-27 11:16:38

标签: shell aix

我在AIX上试过mkdir -p /a/b/c。如果ab不存在,则此命令会创建abc。但是当ab都存在时,会出现错误

  

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

并返回错误代码2.

对此有何帮助?

3 个答案:

答案 0 :(得分:2)

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

$ 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:这可能是不必要的 - 但是在远程坐骑上我发现它是一种更清洁/更容易的方式来继续使用它&#34 ;.从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.)

答案 1 :(得分:0)

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

在VM上:

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

在主机上:

> mkdir build
> touch build/foo

在VM上:

> rm -rf build
> mkdir -p build/a/b/c    <-- Success

答案 2 :(得分:-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#