Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I get to use the locate command extremely often.

So if I run the following command.

locate updatedb | head -1

Then it gives me the O/p


I wonder if there is any such command that can let me open that file directly?

I am hoping for something like this.

locate updatedb | head -1 | vim
share|improve this question
up vote 14 down vote accepted

You're nearly done:

$ locate updatedb | head -1 | xargs vim

sometimes (under certain terminals) you need reset the terminal after editing.

$ reset
share|improve this answer
Thanx man i was looking for this. – Krishna Jun 16 '14 at 12:21
Most probably your version of locate have -l / --limit / -n option so you do not need head -1: locate -n 1 updatedb | xargs vim – Dmitry Alexandrov Jun 16 '14 at 17:19
yup! Thats right. can also do it this way thanks @DmitryAlexandrov – Krishna Jun 16 '14 at 17:47
Why does this terminal corruption happen? Is there any way to avoid it? – Jacobo de Vera Nov 28 '14 at 12:43

As an interactive editor, Vim needs both stdin and stdout, so using it within a pipe is problematic and makes Vim warn about this. For just a single file, process substitution solves this easily:

vim "$(locate updatedb | head -1)"

You can also use backticks, and that even works inside Vim itself:

:edit `locate updatedb | head -1`
share|improve this answer

I know this is bad solution but I used this for creating alias in .bashrc:

locate updatedb  > /tmp/vimForTempDontTouch && vim /tmp/vimForTempDontTouch

Downsides: ugly

Advantage: No side effects with terminal

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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