I am wondering if there is a Linux command that allows for the use of wildcards when using the whereis command.

For example,

whereis vi

produces only where vi resides

whereis vi*

would also show vim if this was a possible command

asked 24 May '10, 19:08

Andy's gravatar image

Andy
2972920
accept rate: 14%




The following command should do what you're requesting.

echo `echo $PATH | tr : ' '` | while read DIR ; do ls $DIR/vi* ; done
link

answered 26 May '10, 13:13

Kevin%20M's gravatar image

Kevin M
11215
accept rate: 25%

edited 28 May '10, 13:08

Thanks for the tip.

(27 May '10, 17:53) Andy

This is what ended up working for me:

find echo $PATH | tr : ' ' -name vi*

(27 May '10, 17:54) Andy

This script can be done without any need for pipes to other commands: while read -d: DIR ; do ls -l "$DIR"/vi* ; done <<<"$PATH:"

(01 Jun '10, 04:50) SiegeX

Normally, you can pipe the output of one command through grep.

# whereis vi |grep vi

But because whereis will only return one value, it's really poinless, so you can also try the locate command like so:

# locate vi

and maybe filter it so you are only lokking in user/bin or usr/local/bin???

Or better still, maybe use the find command above and look only for strings that are in user/bin or usr/local/bin.

link

answered 24 May '10, 20:33

Anthony%20Stanton's gravatar image

Anthony Stanton
593
accept rate: 0%

The locate command will do this for you. The command works with a database that is updated regulary.

If you execute

locate vi

it will show you lots of documentation files, config files and executables of vi and vim. So locate uses wildcards.

If the output is too large, grep it or whatever you want.

Here's a link to the man page of locate and a German explanation for locate.

Good luck.

link

answered 26 May '10, 08:12

guerda's gravatar image

guerda
5533515
accept rate: 38%

Hello,

You could also try "apropos". It does a grep on the manpage database. In your case that would return any page including the text "vi" which would include "vim".

Good Luck

link

answered 26 May '10, 17:17

DBA's gravatar image

DBA
2264
accept rate: 23%

Thank you for introducing me to apropos!

(27 May '10, 17:49) Andy

user@shell:$ find -name vi*

This may suite your needs, but realize it won't JUST find vi and vim, but ANYTHING that has vi* in it's name. Of course doing this below, will have different results:

user@shell:$ find -name *vi

or

user@shell:$ find -name vi*

link

answered 24 May '10, 19:39

Ron's gravatar image

Ron ♦
9361618
accept rate: 13%

john@john-laptop ~ $ whereis vi

vi: /usr/bin/vi /usr/share/man/man1/vi.1.gz

john@john-laptop ~ $ whereis vi*

virtualbox-3.1_3.1.8-61349~Ubuntu~karmic_i386 (1):

virtualbox-3.1_3.1.8-61349~Ubuntu~karmic_i386:

john@john-laptop ~ $

Whereis works exactly the way you want it. Wildcards are always available in BASH

link

answered 27 May '10, 03:29

FewClues's gravatar image

FewClues
24929
accept rate: 5%

I am using bash but this is my output:

root@aws-c3:~# whereis vi vi: root@aws-c3:~# whereis vi vi: /usr/bin/vi /usr/share/man/man1/vi.1.gz root@aws-c3:~#

(27 May '10, 17:47) Andy

Why doesn't the original vi show up on whereis vi* ?

(03 Aug '10, 17:53) Andy
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×90

Asked: 24 May '10, 19:08

Seen: 2,831 times

Last updated: 28 May '10, 13:08

powered by OSQA