Bash and the Secret of the Lost Folders

This bit me majorly yesterday. Nobody tells Bash when the current folder is renamed.

Consider this in a first shell:

mkdir foo
cd foo

Now fire up a second shell and do this:

mv foo foo.old
mkdir foo
cd foo
touch hellothere.txt

Try this in your first shell:


So what do you see? Missing something? Perhaps the hellothere.txt file? Well sorry nobody told Bash the folder was renamed. You actually aren’t in the new folder but still in the old one which now is called foo.old.

If you really want to make sure you actually are in the folder pwd says you are, do this:

cd `pwd`