Everything is a file. And if it's not a file, it's a process. Things are easy in classical unix. And thus, directories are files, too. Which is completely fine until you end up in a shell which is currently working in a directory which gets relocated. Note this article to be less of a bug description than result of an "ooh -- interesting" reaction when expeiencing the sketched phenomenon.

Changing the working directory without changing the working directory

We take a shell and we create some directories and a test file:

[ad001@koffer /usr/home/ad001]$ mkdir -p a/b/c
[ad001@koffer /usr/home/ad001]$ cd a/b/c/
[ad001@koffer /usr/home/ad001/a/b/c]$ touch test1
[ad001@koffer /usr/home/ad001/a/b/c]$ ls
test1
Now we stay in this directory and use a shell running in a second xterm (or whatever floats your ... key strokes) and fiddle with the directory in middle while keeping track about the files in there:
[ad001@koffer /usr/home/ad001/a]$ find .
.
./b
./b/c
./b/c/test1
[ad001@koffer /usr/home/ad001/a]$ mv b X
[ad001@koffer /usr/home/ad001/a]$ find .
.
./X
./X/c
./X/c/test1
[ad001@koffer /usr/home/ad001/a]$
Switch back to the first shell... which still is located at ~/a/b/c and which we now again use:
[ad001@koffer /usr/home/ad001/a/b/c]$ pwd
/usr/home/ad001/a/b/c
[ad001@koffer /usr/home/ad001/a/b/c]$ touch test2
[ad001@koffer /usr/home/ad001/a/b/c]$ ls
test1   test2
[ad001@koffer /usr/home/ad001/a/b/c]$
... aaand back to the second shell, what do we see there?
[ad001@koffer /usr/home/ad001/a]$ find .
.
./X
./X/c
./X/c/test1
./X/c/test2
[ad001@koffer /usr/home/ad001/a]$
Okay, so the first shell seemingly doesn't need any named info and just keeps the directory handle -- which shouldn't change during a simple rename operation. However, the most interesting moment came when cd'ing out of the subdir in the first shell as it then notices the changed name:
[ad001@koffer /usr/home/ad001/a/b/c]$ cd ..
[ad001@koffer /usr/home/ad001/a/X]$
Nice, eh?

Again, this is not a bug, it's completely predictable and fine. Yet, you may want to keep it in mind for your next debugging session as it's a nice trap not to notice identity of directories in spite of differing names.

For the sake of completeness, this phenomenon is experienced with

GNU bash, version 4.2.28(0)-release (i386-portbld-freebsd8.0)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
on a
FreeBSD koffer 8.0-RELEASE-p2 FreeBSD 8.0-RELEASE-p2 #1: Thu Mar 18 12:49:45 UTC 2010     root@koffer:/usr/obj/usr/src/sys/GENERIC  i386
... and yes, I know, that's all a bit older. Oh well, 't has been sleepin' in my drawer and waiting for spring to come. It woke up too early.

Stichworte:


Impressum