295

I am trying to compile ARM code on Ubuntu 12.04 (Precise Pangolin).

Everything is working fine when I put the code in the local directory.

But when I put the code in the cited mount directory, an error shows up:

making testXmlFiles
sh: 0: getcwd() failed: No such file or directory
ARM Compiling xxxxx.c
sh: 0: getcwd() failed: No such file or directory

Here is my setting in fstab:

//10.0.0.1/data /mnt/data   cifs    auto,noserverino,credentials=/root/.smbcredentials,file_mode=0777,dir_mode=0777,uid=user,gid=users,noperm 0 0

What is going on here? What could cause this error?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
CrazyKitty Rotoshi
  • 2,959
  • 2
  • 13
  • 4
  • 71
    This error message might be triggered when trying to execute a command from a path that doesn't exist (e.g. if process B deletes a folder that process A is currently located in. A real-life example: in terminal A: `mkdir ~/myfunnydir && cd ~/myfunnydir` in terminal B: `rm -rf ~/myfunnydir` and finally back in terminal A again: `java --version`) – dbm Oct 22 '12 at 17:41
  • Your directory is auto mounted but the credentials is stored in `/root`. A regular user will not be able to mount it because the credential will not be readable to them. Try making it as non-auto mount and let root mount it. – alvits Jan 06 '14 at 07:03

8 Answers8

789

This error is usually caused by running a command from a directory that no longer exists.

Try changing your directory and rerun the command.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Human
  • 8,380
  • 2
  • 19
  • 15
  • 7
    `getcwd` gets the current working directory and if the directory is deleted or moved it will be unhappy! See [Linux Manual for getcwd](http://linux.die.net/man/3/getcwd) – Human Jan 08 '15 at 21:51
  • 4
    You may even have to do this if you've deleted the directory you were in and recreated one in the same place with the same name. – Jackson Nov 20 '15 at 18:45
  • 2
    all I did was hit cd, and re-run command, and it worked, thanks! – FreeSoftwareServers Oct 06 '16 at 18:45
  • 1
    Noticed this myself when running apt-get upgrade from a nonexistent directory. The message spams about 20 times then the update continues as though nothing happened. I was hoping to find more information on why apt-get even cares what folder I'm in, especially so insistently with so little consequence. – Darren Ringer Jan 02 '17 at 21:59
  • I still get an error: **dpkg: error processing package debconf (--configure): package is in a very bad inconsistent state; you should reinstall it before attempting configuration Errors were encountered while processing: debconf E: Sub-process /usr/bin/dpkg returned an error code (1)** – IgorGanapolsky Jan 30 '17 at 21:37
  • I read this as I was in the main directory of the project on the production server, When I read your answer literally tears came into my eyes because its 4:20 and I am clocking off in 10 mins and I thought I accidentally deleted the project somehow. Luckily, it was just a bug caused by old version of fish. – Dimitar Mar 15 '22 at 15:19
36

That also happened to me on a recreated directory. The directory is the same, but to make it work again, just run:

cd .
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
19

Try the following command. It worked for me.

cd; cd -
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tim Siwula
  • 966
  • 11
  • 15
  • 1
    what is this ?waht is it mean ? – dılo sürücü Mar 20 '20 at 11:25
  • 5
    `cd;` will usually take you to the home directory and `cd -` takes you back to the directory you were in just before the current directory. So basically you go to home directory and come back. However, if the original directory that you were in is deleted, this won't work. – Human Jun 12 '20 at 01:57
10

This can happen with symbolic links sometimes. If you experience this issue and you know you are in an existing directory, but your symbolic link may have changed, you can use this command:

cd $(pwd)
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
smcjones
  • 5,490
  • 1
  • 23
  • 39
5

In Ubuntu 16.04.3 LTS (Xenial Xerus), the following command works for me:

exit

Then I've login again.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Is Ma
  • 913
  • 11
  • 14
  • 2
    actually it would be enough to switch to an existing directory as Hooman already said in his [answer](https://stackoverflow.com/a/21593371/7111561) – derHugo Jun 14 '18 at 13:27
3

Please check whether the directory path exists or not. This error comes up if the folder doesn't exist from where you are running the command.

Probably you have executed a remove command from the same path on the command line.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Aritrik
  • 99
  • 1
  • 1
  • 7
2

If some directory/folder does not exist, but somehow you navigated to that directory, in that case you can see this error.

For example:

  • currently, you are in the "mno" directory (path = abc/def/ghi/jkl/mno
  • run "sudo su" and delete mno
  • go to the "ghi" directory and delete the "jkl" directory
  • now you are in the "ghi" directory (path abc/def/ghi)
  • run "exit"
  • after running the "exit", you will get that error
  • now you will be in "mno"(path = abc/def/ghi/jkl/mno) folder. That does not exist.

So, generally this error will show when the directory doesn't exist.

To fix this, simply run "cd;" or you can move to any other directory which exists.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
0

In my case, none of the previous answers has worked.

After banging my head against the wall for a while I've found out, that I've destroyed the /etc/passwd entries by running a custom-made-linux-server-setup-bash-script which worked well previously, but this time the regex within the "sed" command erased all the existing entries :D

After copy pasting the default entries from another working Linux server, I could finally restart sshd.

So don't forget to back up the original /etc/passwd file before applying any regular expression replacements on it :)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
FullStack Alex
  • 1,783
  • 19
  • 31