sh: 0: getcwd() failed: No such file or directory

I am trying to compile ARM code in Ubuntu 12.04.

Everything is working fine when I put my code in local directory. But when I put the code in cited mount directory this error happens:

sh: 0: getcwd() failed: No such file or directory
sh: 0: getcwd() failed: No such file or directory

Here is my mount command:

sudo mount -t cifs -o username=wx,passwd=wx,auto,nounix,noserverino,file_mode=0777,dir_mode=0777,uid=user,gid=users,noperm,rw,uid=1002,gid=1002 //192.165.54.18/prj_9330  /home/dongjw/work_dir/work_9330

I am using Ubuntu 12.04 64bit

What would cause this error?


Solution 1:

I got this error using jshint through a python subprocess on Ubuntu 12.10 64 bit.

node.js:464
var cwd = process.cwd();
                  ^
Error: ENOENT, no such file or directory
    at Function.resolveArgv0 (node.js:464:23)
    at startup (node.js:51:13)
    at node.js:555:3

It is caused because you deleted or moved a directory out from underneath it and the current directory can't be determined.

How to tell if you are having this problem:

Run the command cd . (If you get this error then you have this problem).

el@apollo:~/foo$ cd .
cd: error retrieving current directory: getcwd: cannot access parent 
directories: No such file or director

You tried to change directory into your current dir, and could not.

How to reproduce the error:

jshint is affected by this error. Make a directory foo, cd into it, make a file called myjavascript.js

cd /home/el
mkdir foo
cd foo
touch myjavascript.js
jshint myjavascript.js

jshint runs correctly, it says there are no errors which is correct.

Open a 2nd terminal, and rm -rf the directory /home/el/foo out from underneath.

rm -rf /home/el/foo

Run the jshint myjavascript.js again from your first terminal and you get an error:

el@apollo:~/foo$ jshint myjavascript.js 

    node.js:464
        var cwd = process.cwd();
                      ^
    Error: ENOENT, no such file or directory
        at Function.resolveArgv0 (node.js:464:23)
        at startup (node.js:51:13)
        at node.js:555:3

The directory is gone! And even if you were to replace it with the same contents, it has a different signature and the terminal can't recover, the method getcwd can't know what the current directory is.

Three Solutions:

The terminal is confused about what the current directory is because its gone or it's signature has changed. Do one of these to fix it:

  1. Run the command cd .. until you stop getting errors. This re synchronizes the terminal with the filesystem. Then cd back into your directory. Try again. The error goes away.

  2. Use su youruser in the terminal, enter the password. It refreshes and brings you back to the same directory.

  3. Close and reopen the terminal which flushes away the stale directory signatures. Or send a nastymail to whatever program (jshint) or the thousands of other programs which can't tolerate or recover from stale directory signatures.

Solution 2:

I get the same error, but I was trying to run a script in my home directory. I solved it with:

pushd ~ 1>/dev/null; pwd ; popd 1>/dev/null

This moves my to my home directory, then runs pwd (but you can run anything that you like) and then the popd moves me back to where I was. If you don't need to move back then

cd; pwd

Would be enough to solve my problem, (I hope that it helps with yours.)

edit The 1>/dev/null parts are optional; I add them so that I can use the above line within a shell script without additional output that isn't needed in this case.