This all depends on the shell, of course.
For bash, you can use an alias:
alias foo="ls --color=always -l -Z --my-favourite-option"
Now when you enter foo
on the command line, bash will replace it with that long ls
command line. This is valid until you exit your shell; if you wish for it to be permanent, you can add that command to ~/.bashrc
, which will be executed by every started bash shell.
You can also create shortcuts by way of a .inputrc
file. E.g., if you enter the following in a file ~/.inputrc
:
"\C-\M-e": "echo this is a test"
and then restart the shell, then whenever you hit control-alt-e, readline will enter that command.
Note, however, that since the inputrc file is parsed by libreadline (rather than by bash), it is used by every program that uses libreadline; so things like gdb
and lftp
will use it too, where running shell commands may not work.
bind
: https://stackoverflow.com/questions/4200800/in-bash-how-do-i-bind-a-function-key-to-a-command – Arkadiusz Drabczyk Sep 04 '19 at 10:44