How to find a linux command having a specific substring

I am an Ubuntu user and it occurs to me several times that I need to execute a command in shell.This is what I do.

  1. Alt+F2
  2. Type gnome-terminal followed by enter.

The terminal popped open.I start typing the command and suddenly I realise that I do not remember what the exact command is.I just have a slight idea about the command.I am just sure of a particular word/substring in the command.It happened to me yesterday too when I was trying to modify some configuration of Gnome-Desktop.The actual command for the configuration editor is gconf-editor.But I remembered only a part of it(editor :( ),thats when I tried to write a simple script(findscript) for finding a command when you have a slight idea of a substring or word in it.

THE SHELL SCRIPT

findcommand

#!/bin/bash
paths=${PATH//:/ };
find `echo $paths` -name $1;

Make this script executable by the following command

chmod +x findcommand;

Now move this file to /usr/local/bin or any other directory in your PATH environment variable.

mv findcommand /usr/local/bin

Code to check the PATH variable.

echo $PATH;

So this is the full command I ran after making this script for finding the configuration editor command.

findcommand *editor

OUTPUT:

/usr/bin/gconf-editor
/usr/bin/nm-connection-editor
/usr/bin/sensible-editor
/usr/bin/gnome-text-editor
/usr/bin/select-editor
/usr/bin/gmenu-simple-editor
/usr/bin/editor

This script will accept a regex as argument.Other possible arguments for the job can be
1. edit
2. ed
3. gconf

The script basically uses the linux file finding utility find to find all the executables in your path having a specific word.Feel free to experiment with it :)

Though it can also be done using apropos command or 'man -k editor' (editor is the search term), but its always fun doing in a different way ;)

... Loading comments