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
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
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.
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.