How to define a global alias in BASH?

Asked

Viewed 805 times

4

I’m using the Terminal in the Linux and I’m tired of repeating the same commands all the time.

For example, I use a command practically all day, then I create an alias to make things easier.

Example:

  alias tt="php artisan tinker --env=local"

  alias artisan="php artisan --env=local"

However, every time the Terminal is closed, these shortcuts "go to the bag". Then I have to set everything up again when I open the Terminal or I restart my Ubuntu;

How can I leave these Aliases global? Is there any way to do this?

  • You can say it’s not "within the scope," but I use it every day to program, use!

2 answers

4


You can add these lines to the file /etc/profile, Once the user logs in, the information is loaded.

$ sudo vim /etc/profile
ou
$ sudo nano /etc/profile

profile:

#...
alias tt="php artisan tinker --env=local"
alias artisan="php artisan --env=local"

To apply the changes, you must logout.

  • Just reminding @Brumazzi DB that just do $source /etc/profile or #source /etc/profile which already updates and makes it unnecessary to logout.

  • @Armandomarquesnephew, yes but that only applies in the terminal that was made the source, if you open another terminal the setting is not applied, so the logout suggestion.

  • no problems, it was just to implement! but as far as I know if open another terminal it already comes loaded, at least in mine with Scientific Linux, but I will test on a machine that I have here of the children watch movies and that uses the Ubuntu.

  • opa, you are right @Brumazzi DB I tested there in Ubuntu, you really need to logout but in mine with RHEL I never needed

  • @Armandomarquessobrinho, Some distributions comes with the .bashrc or the .profile pre-configured, probably your already imports the settings directly from /etc/profile because of these settings.

  • Would that be global for all users? Is that really what he wants?

Show 1 more comment

2

Put your aliases inside the archive /home/$USER/.bashrc .

This file runs every time you open a graphical terminal.

Preferably add your aliases at the end of the file.

For example, you can use the nano to edit this file:

 sudo  nano /home/$USER/.bashrc

Then you can add any alias:

artisan="php artisan --env=local"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.