0

This question already has an answer here:

My format is whereis directory | cd but I get no output (not even a warning).

Where as you have other posts that require variables, my question asks how to do it without them.

marked as duplicate by mdpc, Stephen Rauch, Scott, muru, countermode Aug 4 '17 at 7:00

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • What exactly are you trying to accomplish? The way I'm reading this is you would like to lookup the location of a directory and then change to it? As far as I know the whereis command is for finding file sources and man pages and I don't believe it has the ability to search for directories. – Jesse_b Aug 3 '17 at 21:06
  • whereis can be used to find a directory, what I am trying to do is output the location into cd. @Jesse_b – Death_by_Ch0colate Aug 3 '17 at 21:08
  • How do you use it to find a dir? – Jesse_b Aug 3 '17 at 21:10
  • for example, 'whereis bin' outputs '/usr/local/bin' – Death_by_Ch0colate Aug 3 '17 at 21:11
  • That doesn't work for me on BSD. – Jesse_b Aug 3 '17 at 21:11
1

So on CentOS the whereis command prefixes the output with your search.

[root@JBCLAMP001 ~]# whereis bin
bin: /usr/local/bin

So I came up with the following that seems to work in my testing so far:

cd $(whereis bin | awk '{print $2}')

Some directories will have multiple locations which may or may not be an issue. For example on my machine the rpm directory has 4 locations. The above cd command still works but it will cd you to the first listed location and not inform you that there are more.

Not the answer you're looking for? Browse other questions tagged or ask your own question.