How to add an alias to a command in terminal?

By typing a manually specified command in terminal I want to execute some other command.

How could add an alias to a command? Can i do that with the help of the terminal or should I edit some kind of file?


Solution 1:

alias new_name='old command'

To create a permanent alias you have to edit the .bashrc file in your home directory.

More info here

More .bashrc files here

Solution 2:

On the bash command line it is simply a case of typing:

alias my_command="Command to run"

For example to create a short command run a long listing you could do:

alias ll="ls -l"

The quotes are not required if you are not adding switches to the aliased command.

Solution 3:

To make permanent changes you can put your aliases separetely in ~/.bash_aliases

Solution 4:

You can either use the alias built-in command in the shell you're using, or you can write a script which does what you want. Assuming you are using bash as the shell (which is the default), you can type man bash and skip down to the ALIASES section, for documentation on aliases in bash.