Reputation: 11716
How do I change directory to location of executable from a Linux terminal?
I tried, e.g., cd $(which ruby)/..
but that doesn't work.
Upvotes: 1
Views: 76
Reputation: 5209
which
command tells you not only directory name but also filename, so you have to get rid of the filename using some utility. I used simple sed
for this to remove everything after last slash including.
This works in bash:
cd `which ls | sed -r 's#/[^/]+$##'`
Upvotes: 0