Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redirecting output of 'find' command to 'vim'

Tags:

redirect

find

vim

I am doing a find $PWD -name 'filename' | vim -

expecting the file filename to be opened in vim editor. but it is not working. In this case, I am sure that there exists just one file with name 'filename'.

Also the result of find gives the complete path on stdout.

like image 761
Sachin Shetye Avatar asked Feb 01 '11 20:02

Sachin Shetye


3 Answers

vim "$(find "$PWD" -name 'filename')"

or

find "$PWD" -name 'filename' -exec vim {} \;

(You can drop "$PWD", by the way. find starts the search from current directory by default.)

like image 192
Roman Cheplyaka Avatar answered Nov 04 '22 03:11

Roman Cheplyaka


find . -name 'filename' -print0 | xargs -0 vim

should also work. You might want to read up on xargs, which is a handy thing to know about.

like image 24
frabjous Avatar answered Nov 04 '22 04:11

frabjous


Mentioned in @idbrii's comment, but my favorite is:

find . -name 'filename' -type f -exec vim {} \+

This opens up each file found in its own buffer ready to be navigated with :next and :prev. Tested on OSX, but I'm fairly certain it will work on Linux too.

like image 4
Ben Avatar answered Nov 04 '22 04:11

Ben