0

I'd like to get the nth (3rd) result of locate, and then open it to vi.

$ locate 
/private/etc/my.cnf
/private/etc/my.cnf.bak_
/usr/local/mysql-5.6.22-osx10.8-x86_64/my.cnf 
....
2

You need a pattern for locate; say "my.cnf":

vi $( locate my.cnf | head -n3 | tail -n1 )

Caveat: No newlines in the filenames, please. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.