I am answering the original question about a custom command (not only a custom script).
Simple command - alias
A simple command for one single user (the current user) can be created as an alias (you mentioned alias in your question), for example
alias rm='rm -i'
to make the remove command interactive. This works 'now' and only in the current terminal window. You can save it in
~/.bashrc near the standard aliases, and it will be activated in all terminal windows in the future and also the text screens.
Please notice that your current user's aliases do not work with sudo (unless you create an alias for the the user root too and store it in
It is a good idea to backup the
.bashrc file(s) before editing, just in case, for example
cp -p .bashrc .bashrc.0
See also this link, Combine 2 commands into 1 Custom command?
Advanced command - function or shellscript
If you want to call a more advanced command, that consists of several command lines and/or uses parameters in a complicated way, you can use
a function, which is defined like the following examples
Such a function is activated like an alias, and can be stored in the same way in
a shellscript, which is a text file with the bash commands.
If you want only the current user to use the shellscript, you can store it in
mkdir ~/bin # create `~/bin`, if it is not already created.
Otherwise, if you want all users to use the shellscript, you can store it in one of the general directories for executable programs and scripts, for example
/usr/local/sbin if the script is to be run with
Please check very carefully that the shellscript has a unique name, so that you do not 'compete' with (or even worse, overwrite) an already existing executable program.