The effect of
cd . is to update the shell with information about what the current working directory is. This could be useful in circumstances when the (pathname of the) current directory changes by other means than through
$ mkdir dir
$ cd dir
So, we're currently some place under
/tmp, in a directory called
dir. Let's rename the directory we're currently in.
$ mv ../dir ../new-dir
So, where are we now?
Really? Why, that's odd. Let's make sure the shell knows were we are.
$ cd .
In a script,
cd . could possibly be used to test whether the user still as access to the current directory:
if ! cd . 2>/dev/null; then
echo lost access to cwd >&2
Or, the other way around, to verify that the current directory is no longer accessible after some sort of operation to revoke access for the current user.
Reasons for loosing access to the current directory includes having the directory removed, or someone removing one's execute permissions on it.
Another example is using
cd ., but with the
-P option, i.e.
cd -P .. This would put you in the "physical" directory if the current directory was otherwise accessed through a symbolic link:
$ mkdir dir
$ ln -s dir link-dir
$ ls -l
drwxr-xr-x 3 kk wheel 512 May 8 00:48 dir
lrwxr-xr-x 1 kk wheel 3 May 8 00:46 link-dir -> dir
So now we have a directory,
dir, and a symbolic link to that directory. Let's enter the directory through the symbolic link:
$ cd link-dir
$ cd -P .