Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
share|improve this question
up vote 13 down vote accepted

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.

share|improve this answer
In my case, it was occurring because of a misconfigured GlusterFS mount point, but I was curious about the general case that would cause this to happen. Would this type of question really be a homework problem in a class? – Lorin Hochstein Oct 26 '10 at 17:54
The general case is the current directory not existing. Apart from its having been deleted as in maxschlepzig's example, this can only happen in weird circumstances like a misbehaving filesystem (your case), or perhaps a security mechanism like SELinux having made the directory invisible (I don't know if SELinux can actually produce this effect). – Gilles Oct 26 '10 at 19:51
@lorin: Well, at a Unix introduction course in university we asked such kind of questions as part of homework assignments (because e.g. NFS problems may manifest in similar error messages). Just have asked out of curiosity ... – maxschlepzig Oct 26 '10 at 20:35
@Gilles: If you add your comment as an answer, I'll accept it. – Lorin Hochstein Oct 26 '10 at 20:50
In the original answer, no need for another terminal: rmdir ../foo in the same terminal should work. Another possibility without misbehaving filesystems: ln -s directory-that-doesnt-exist/foo foo; touch foo. – ephemient Oct 27 '10 at 3:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.