touch: cannot touch `foo': No such file or directory

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

Tags:

Linux

Shell

Touch