14

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?

wjandrea
  • 14,236
  • 4
  • 48
  • 98
dongjiawei
  • 141
  • 1
  • 1
  • 3

4 Answers4

10

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.

Eric Leschinski
  • 2,221
  • 1
  • 20
  • 24
  • instead of running cd .. "often enough" you could also just cd ~ directly to your homefolder – derHugo Jun 14 '18 at 13:33
  • @Eric Leschinski I get this error sometimes on ubuntu 18.04 even when the folder is my home folder and has not been deleted, eg ls . works fine, etc. How do "directory signatures" work and what causes Ubuntu to get confused about the directory signature of a folder that has not been deleted? – localhost May 19 '22 at 00:37
5

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 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.

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.

Pablo Bianchi
  • 15,657
Alexx Roche
  • 281
  • 5
  • 8
  • So that I can past this into a bash script and not end up with output that I don't want. I try to add as complete an answer as I can because when I find commandline-fu I find it easy to cut it down to my needs and I expect anyone that is using this to be a bit like me. – Alexx Roche Sep 06 '13 at 06:20
  • ok, I've added an edit explaining, (though some might feel that I'm teaching them to suck eggs - those that know do not need the edit and those that do not know can cut-n-paste, or look up that function that is not directly related to the original question.) – Alexx Roche Sep 07 '13 at 08:17
  • Sadly is like that :( – Braiam Sep 07 '13 at 10:52
1

Run the command in your home directory.
Move to the home directory:

cd ~

Then run the command again. That should help

-1

Even i was having the same problem with python virtualenv. It got corrected by a simple restart

sudo shutdown -r now
yunus
  • 105
  • 1