Sh: 0: getcwd() failed: No such file or directory on Linux

I am working on codebase and suddenly I get this when I need to install something using apt on the test server:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
sh: 0: getcwd() failed: No such file or directory
sh: 0: getcwd() failed: No such file or directory
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
sh: 0: getcwd() failed: No such file or directory
sh: 0: getcwd() failed: No such file or directory

What causes sh: 0: getcwd() failed: No such file or directory on Linux error and how can I fix it?

This error means the directory no longer exists. Hence, you are getting this problem. Go back to your home directory and run apt command again:

cd
sudo apt update
sudo apt install foobar 

How to produce “sh: 0: getcwd() failed: No such file or directory” error

Run the following commands:

mkdir /tmp/foo
cd /tmp/foo

Now open another terminal and run:

rm -rfv /tmo/foo/

Then go back to original terminal and run:

sudo apt update
sudo apt upgrade

You should see an error:

1 Like

Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki