1 |
On Friday 11 May 2007 14:34, Martin S wrote: |
2 |
|
3 |
> Just recently tried using |
4 |
> |
5 |
> locate foo.conf | cd |
6 |
> |
7 |
> to automagically move to the directory in which I've saved foo.conf |
8 |
> Of course it didn't work as you can't cd to /bar/foo.conf |
9 |
|
10 |
It would not have worked anyway, since cd does not read its input from |
11 |
stdin. Try: |
12 |
|
13 |
[/]$ echo "etc" | cd |
14 |
-bash: echo: write error: Broken pipe |
15 |
[/]$ |
16 |
|
17 |
> I didn't find a way to dropping the actual file name from the result |
18 |
> of locate. |
19 |
> I did a brief google on locate, but didn't find a switch to drop the |
20 |
> actual file name from the result. |
21 |
|
22 |
It's not a locate problem. Use the "dirname" command. |
23 |
|
24 |
$ dirname /bar/foo.conf |
25 |
/bar |
26 |
$ |
27 |
|
28 |
and do something like |
29 |
|
30 |
cd $(dirname "$(locate foo.conf)") |
31 |
|
32 |
of course, make sure that the locate command returns just a single entry. |
33 |
-- |
34 |
gentoo-user@g.o mailing list |