You are currently browsing the monthly archive for March 2007.

It’s the simple things in life… Sometimes you simply want to know the canonical path for your current working directory.

Here is a symbolic link to a directory.

$ ls -go /home/crashingdaily/symlink
lrwxrwxrwx 1 14 Mar 29 10:54 /home/crashingdaily/symlink -> im/a/real/path

I change to the directory using the symbolic link.

$ cd /home/crashingdaily/symlink

The ‘pwd’ bash builtin does not resolve symbolic links so reports that I’m in the ‘symlink’ directory.

$ pwd
/home/crashingdaily/symlink

‘/bin/pwd’ reports the canonical path.

$ /bin/pwd
/home/crashingdaily/im/a/real/path

I can leverage this to quickly change my path from symlinked to real.

$ pwd
/home/crashingdaily/symlink

$ cd `/bin/pwd`

$ pwd
/home/crashingdaily/im/a/real/path

Also see

readlink -f .

readlink is advantageous if you need to resolve paths outside your current working directory.

Update: Sometimes the simpler things are right under your nose.

pwd -P

and

cd -P .

were sitting there all along. No need for /bin/pwd (for bash at least). RTFM, indeed.

Advertisements

Categories

March 2007
M T W T F S S
« Feb   Apr »
 1234
567891011
12131415161718
19202122232425
262728293031  

Latest del.icio.us