8

Is there a way that I can pipe the output of this command (assuming there is only one file found) to vi. I want to find this command, and then call it up in vi.

Thanks.

find . -name 'id.properties'
0

3 Answers 3

9

To edit the files printed by find:

find . -name 'id.properties' -exec vi {} +

In plain English, this finds paths in the current directory (.) and all subdirectories with a base name of id.properties. With these files it runs a vi file1 file2 [...] command (-exec vi {} +). If there are very many files (typically thousands), it might even run more than one vi command, each with a bunch of files, to be able to fit the commands into the maximum command length of your system. To force it to run the command for each file you could use \; instead of +.

To edit the text printed by find:

find . -name 'id.properties' | vi -

This writes the paths (relative to the current directory) of any files found (because by default find has a hidden -print at the end) to its standard output, which is connected (|) to vi's standard input. vi, in turn, reads from standard input (-) and shows that as a file to be edited.

1
  • Can you explain the commands a bit more? Why the + in the first one and the empty braces and why the - in the second one?
    – don.joey
    Jun 19, 2013 at 13:35
0

You can push the output in a textfile and open it with vi.

find . -name 'id.properties' >> /home/<user>/find.txt
vi /home/<user>/find.txt
-2

This answer seems most straight forward. For your case it would be:

vim $(find . -name 'id.properties')
1
  • -1: This could easily blow up with spaces in paths. The exec version is far better.
    – muru
    Apr 17, 2015 at 22:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .