0

I have searched one file "portmap" inside root directory as follows:

find -name "portmap"

It gives location of file

.init/...somepath./portmap

Now I want to change my current directory to the location of portmap file and print the present working directory.

So I am thinking of pipeline the above location to cd. But how can I do it with one command?

Please help

techfun
  • 457

2 Answers2

1

Presuming that find finds one and only one match for the search pattern, you can use

cd "$( dirname "$( find -name "portmap" )" )"

If at any time you want to do to the directory enumerated in the output of the previous command, you can use

cd "$( dirname "$(!!)" )"
slhck
  • 235,242
DopeGhoti
  • 603
-1

The xargs command is perfect for this, but the cd command in the shell doesn't play well with it. So I'd use back ticks:

cd `find . -type d -name "portmap"`
joe
  • 24