Reputation: 73
I tried mkdir -p /a/b/c
on AIX. When a
and b
didn't exist, this command created a
, b
and c
. But when a
and b
both exists, it gives an error
Cannot create /a/b. /a/b: File exists
and returns an error code 2.
Any help on this?
Upvotes: 1
Views: 11937
Reputation: 443
I had this happen using Parallels filesystem. The virtual machine complained about a directory existing, even though "ls" could not see it. When I cd'ed into the directory, it allowed it, but then ls would fail. So it seemed to be a filesystem caching bug. I solved it by going to the host machine and creating the directory with a file, then going back to the virtual machine and deleting the directory. After that, the virtual machine filesystem was synced properly and I could create the directory with mkdir as normal.
On VM:
> mkdir -p build/a/b/c <-- failed with "file exists"
> cd build <-- allowed
> ls <-- failed
On host machine:
> mkdir build
> touch build/foo
On VM:
> rm -rf build
> mkdir -p build/a/b/c <-- Success
Upvotes: 0
Reputation: 2035
I just came across a similar symptom - except that it was a broken remote mountpoint (in this case using sshfs) and had nothing to do with a file being "in the way":
$ 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/
A umount* sorted it out. I've also added an exception into the script that triggered the error to also try 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
*In case someone is wondering about the -l I used on umount: It is probably unnecessary - but on remote mounts I've found it to be a cleaner/easier way to just "get on with it". From the umount man page:
-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.)
Upvotes: 2
Reputation: 95
I think you are talking about this scenario:
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#
Upvotes: -1