Create a permanent alias for a command
Create an alias
To create an alias run:
$ alias youralias='thecommandyouwanttocreateanaliasfor'
$ todo='vi /home/username/Documents/todo.txt'
will create an alias named
todo that will open the file
todo.txt in Vim. In other words, once you have created the alias, when you want to open
todo.txt with Vim, run:
But: you will notice that when you quit the shell (a.k.a. the terminal), and open it again, the alias no longer exists.
Make an alias permanent
For an alias to be permanent, add it to file:
~ is a substitute for
If setting the alias is the last command you’ve executed, running:
$ echo !!:q >> /home/username/.bash_aliases
will add the alias to the
If this file does not exist, create it:
$ touch ~/.bash_aliases.
Then check if the following lines are present in the file
# Alias definitions. # You may want to put all your additions into a separate file like # ~/.bash_aliases, instead of adding them here directly. # See /usr/share/doc/bash-doc/examples in the bash-doc package. if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi
If not, add them.
The first four lines are mnemonics. The pound key
# comments them out for the script to ignore them. The three following lines tell the Bash configuration file (a.k.a. “a dot file”) to check if a
~/.bash_aliases exists; if so, to run it.
Let me know if you have questions.
Feedback welcome at yctct dot domain name.
- Start using the command-line interface (cli)
- A guide to simple and stupid usage of computers for writers (anyone who writes really)
- A roadmap to reclaiming my attention and time