What could cause touch to fail with this error message?
touch: cannot touch `foo': No such file or directory
Note that an error due to incorrect permissions looks different:
touch: cannot touch `foo': Permission denied
What could cause touch to fail with this error message?
touch: cannot touch `foo': No such file or directory
Note that an error due to incorrect permissions looks different:
touch: cannot touch `foo': Permission denied
Following sequence causes this error message:
$ mkdir foo
$ cd foo
In another terminal:
$ rm -r foo
In the previous terminal:
$ touch x
touch: cannot touch `x': No such file or directory
Of course, other events that also result in invalidating the current working directory (CWD) of a process that tries to create a file there also yield this error message.
For me it was trying to write to a symlink that was pointing to a file that was no longer there:
$ ln -s file symlink
$ rm file
$ touch symlink
$ touch: cannot touch `symlink': No such file or directory
Another (simpler) way to trigger the message:
$ mkdir foo
$ touch foo/bar/baz.txt
touch: cannot touch 'foo/bar/baz.txt': No such file or directory
Basically trying to create a file in a non-existent folder.
Maybe this will help someone in the future:
I got this same issue when I removed the only file which exists in my folder with git rm. Thus git removed the folder in which I was, and any attempt to create a file triggers this error because the folder is no longer there. So I had to recreate the folder manually, go into it and run the touch command successfully.