title: How can I derefence symbolic links in bash?
body: <p>How can I take any given path in <code>bash</code> and convert it to it's canonical form, dereferencing any symbolic links that may be contained within the path?</p>
  
  <p>For example:</p>
  
  <pre><code>~$ mkdir /tmp/symtest
  ~$ cd /tmp/symtest/
  /tmp/symtest$ mkdir -p foo/bar cat/dog
  /tmp/symtest$ cd foo/bar/
  /tmp/symtest/foo/bar$ ln -s ../../cat cat
  /tmp/symtest/foo/bat$ cd ../../
  /tmp/symtest$ tree
  .
  |-- cat
  |   `-- dog
  `-- foo
      `-- bar
         `-- cat -&gt; ../../cat
  
  6 directories, 0 files
  </code></pre>
  
  <p>How can I get the full canonical path of <code>/tmp/symtest/foo/bar/cat</code> (i.e: <code>/tmp/symtest/cat</code>)?</p>