Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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'm searching for a Linux command line tool that allows me to store my favorite / most used / most difficult to remember bash commands and quickly run them when needed.

I prefer not using aliases because I want to avoid names conflict. alias is a handy thing, but it's not what I'm searching, that is some command line snippets library.

An example of what I want is:

$ favorite --add hello 'echo Hello World!'
$ favorite hello
Hello World!
$ favorite --delete hello
$ favorite hello
favorite: shortcut 'hello' not defined
$ _

I think I'm able to code this tool by myself (maybe using python-cliapp or php5-cli), but if something already exists I prefer not reinventing the wheel.

share|improve this question
The commands I reuse usually need some modification before re-execution. What I do is to have a large history file (5000+ lines) and regex search with <C-r> for partials. – Thor Jun 26 '12 at 17:45
Learn the CLI backwards and forwards. After that the only think you need is your memory, and the ability to type fast. I find it much easier trying to remember the standard selection of commands, then trying to the name of alias, scripts, other memory crutches. Plus I can be useful on a machine without any aliases or so on. – Zoredache Jun 26 '12 at 17:54
@Thor I owe you a beer for making me discover reverse intelligent history search. – lorenzo-s Jun 26 '12 at 18:11
@lorenzo-s If you're really ok with typing "favorite" before every snippet, why don't you just alias with a prefix: alias fav-hello='echo Hello World!' ? – Soheil Hassas Yeganeh Dec 5 '13 at 22:50
up vote 3 down vote accepted

If you don't mind lack of error messages for syntax errors etc., you can use this simple bash script:


case $1 in
    if [ -a ~/.favorites/$2 ]; then
      echo favorite: Shortcut \'$2\' already exists.
      echo $3 >> ~/.favorites/$2
    if [ -a ~/.favorites/$2 ]; then
      rm ~/.favorites/$2
      echo favorite: Shortcut \'$2\' does not exist.
    if [ -a ~/.favorites/$1 ]; then
      $(cat ~/.favorites/$1)
      echo favorite: Shortcut \'$1\' does not exist.
share|improve this answer
I think your use of $3 is problematic. I think you want to shift off the first two positional parameters and use $* instead. – Fran Jun 26 '12 at 18:05
Since the OP quotes the command (favorite --add hello 'echo Hello World!'), $3 becomes echo Hello World!. – Dennis Jun 26 '12 at 18:06
True, but without quotes typed by the user, it malfunctions. But since the author is the user, that's probably ok. – Fran Jun 26 '12 at 18:07
I like it for the simplicity :) +1 – lorenzo-s Jun 26 '12 at 18:11

It seems that writing scripts and putting them in ~/bin (which would then be in your PATH) is an acceptable alternative. That would work unless you want to be able to see and edit the command before pressing ENTER to execute it, but your example above does not demonstrate that requirement.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .