Use Results of Find Command to Call vi
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'
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.