alias cdc='cd `pwd -P`'

cd canonical (resolve any symlinks)


-2
By: adavies42
2009-02-05 10:15:11

These Might Interest You

  • The symlinks command can show status of all symbolic links, including which links are dangling, which symlinks point to files on other file systems, which symlinks use ../ more than necessary, which symlinks are messy (e.g. having too many slashes or dots), etc. Other useful things it can do include removing all dangling links (-d) and converting absolute links to relative links (-c). The path given must be an absolute path (which is why I used $(pwd) in the example command).


    6
    symlinks -r $(pwd)
    kFiddle · 2009-05-01 23:33:10 1
  • With the "--resolve" switch, you can avoid doing DNS lookups or edit the /etc/hosts file, by providing the IP address for a domain directly. Useful if you have many servers with different IP addresses behind a load balancer. Of course, you would loop it: for IP in 10.11.0.{1..10}; do curl --resolve subdomain.example.com:80:$IP subdomain.example.com -I -s; done


    2
    curl --resolve subdomain.example.com:80:10.100.0.1 subdomain.example.com -I -s
    atoponce · 2013-01-24 19:50:26 0
  • shows you the symlinks in the current directory, recursively, but without following them Show Sample Output


    0
    find ./ -type l -print0 | xargs -0 ls -plah
    jmorganwalker · 2014-03-20 20:36:39 0
  • since the most url shorteners respond with a header containing the Location: ... this works with most common shorteners Show Sample Output


    2
    resolve(){ curl -Is $1 | egrep "Location" | sed "s/Location: \(.*\)/\1/g"; }
    hoodie · 2011-12-06 12:37:46 2
  • recursively deletes all broken symlinks using zsh globbing syntax.


    2
    rm **/*(-@)
    xro · 2012-09-18 20:18:57 1
  • If you use symlinks a lot, especially nested symlinks, this puts you back on the absolute path to command-line-fu-nirvana. (Note the backticks around pwd). Show Sample Output


    16
    cd `pwd -P`
    Davvolun · 2009-02-17 17:21:24 2

What Others Think

In bash you can use cd -P symlink or to enable it all the time, do set -P
mulad · 482 weeks and 5 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: