Bash: create alias

If you find yourself repeatedly running a wordy command, having to look up how to run a command, or forgetting a username and password combination, I suggest looking into creating a bash alias.

To create a bash alias, do the following:

1. Start up terminal

2. Type cd ~  to go to your home folder

3. Type touch .bash_profile to create the new file

4. Type vim .bash_profile or open this file in your favorite editor.

5. Add your alias by adding a line to this file in the format alias <alias name>='<command>’ . For example alias gw=’./gradlew’.  This will create an alias named gw , which when typed will run the command ./gradlew  from wherever gw  is typed.

6. Type . .bash_profile  to reload your bash profile which loads any newly added aliases.

At this point you can type your alias instead of the wordy command you had been previously typing.

Leave a Reply

Your email address will not be published. Required fields are marked *