Take the 2-minute tour ×
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.

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

1 Answer 1

up vote 10 down vote accepted

Hm, homework question? Anyway, 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
share|improve this answer
2  
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
3  
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
3  
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

 
discard

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.