Install and run when a command is not found

function command_not_found_handle(){ apt-get install $( apt-file search "$1" | grep bin | grep -w "$1" | head -n1 | cut -d ':' -f 1 ) && $* ; }
Work only with bash and apt-file installed. When it found an unknow command, it will search for a file named "scribus" (in my example), in a folder named bin and then install the corresponding package. After installation, it will run the command. Usefull juste after reinstalling linux and missing lot of package.
Sample Output
juluan@juluan-desktop ~ 21:56:04 [130] $ scribus
Lecture des listes de paquets... Fait
Construction de l'arbre des d?pendances       
Lecture des informations d'?tat... Fait
Les paquets suppl?mentaires suivants seront install?s?: 
  blt python-tk
Paquets sugg?r?s?:
  blt-demo tix python-tk-dbg scribus-template scribus-doc
Les NOUVEAUX paquets suivants seront install?s?:
  blt python-tk scribus
0 mis ? jour, 3 nouvellement install?s, 0 ? enlever et 3 non mis ? jour.
Il est n?cessaire de prendre 11,5Mo dans les archives.
Apr?s cette op?ration, 32,2Mo d'espace disque suppl?mentaires seront utilis?s.
Souhaitez-vous continuer [O/n]??

By: Juluan
2011-04-06 19:58:32

What Others Think

Automatic installing sounds extremely dangerous to me.
houghi · 533 weeks and 1 day ago
it still ask for the agrement but search and asking for installing or not
Juluan · 533 weeks and 1 day ago
dont work for non-root users
kuhkatz · 533 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: