Adding command shortcuts to /bin

An easy way for a shortcut is to define an alias

alias dcls='docker container ls'

This will execute docker container ls when you enter dcls and the command alias lists your defined aliases. To remove this alias use unalias dcls.

If you use bash, you can save the alias in your ~/.bashrc or ~/.bash_aliases.

If your ~/.bash_aliases is not read on startup, you can add this line to your ~/.bashrc:

[ -f ~/.bash_aliases ] && . ~/.bash_aliases

Actually, what you describe would work, with a few notes:

  1. You could simply put docker container ls into a file called /bin/dcls.  But the behavior of that can be a little complicated.  It’s a little more reliable to begin the file with a line called a “shebang”, so the file would look like
    #!/bin/sh
    docker container ls
    which specifies that the file is a shell script.
  2. Before you can run the command, you must make the file executable with a command like
    chmod +x /bin/dcls
    You probably need to be root to do this (i.e., run it with sudo).
  3. Follow the above two steps and you will be able to type dcls and it will do docker container ls. But, if you type dcls -l foo, it will still do docker container ls.  If you want it to do docker container ls -l foo, you should change the script to say

    #!/bin/sh
    docker container ls "$@"
    which specifies that any arguments that you type on the dcls command line should be passed along to the docker container ls command.

    Naturally, there are more complicated things you can do with command-line arguments.

For a mapping of one simple command → one simple command, that doesn’t need to be shared with other users, it’s simpler to define an alias (as Freddy suggested), or a shell function.  More complicated functions are often written as scripts; i.e., text files that contain commands.  But, if you don’t need to share it with other users, it’s more common to use a private bin directory.

$ cd                                    # (to your home directory)
$ mkdir bin
Then copy dcls to $HOME/bin, and add
export PATH="$HOME/bin:$PATH"
to your ~/.bashrc.

Also, it’s common to put personal scripts into /usr/local/bin, and leave /bin for the programs that came with the system.