Whenever we update something in Magento 2 we need to run different commands which are quite lengthy and while writing them we may have some typo errors as well. To short/customize Magento 2 commands you can alias all your required commands. But the drawback is, it saves these aliases in the current terminal session only. To overcome this drawback we have a solution for it.
In your home directory, you’ll have ~/.bashrc and .bash_aliases hidden files. To make permanent changes you can write your aliases separately in ~/.bash_aliases file and it will be read automatically whenever a new session starts. For this, your ~/.bashrc file should have the following-
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
~/.bashrc file will already have the above-mentioned code. It means if you have a file ~/.bash_aliases file then it will be sourced and all the aliases written in it will be applied in the current terminal session. If you don’t have ~/.bash_aliases file you can create it manually.
Here, you can find the list of some Magento commands which I have aliased and run the customized command to get the desired output.
Example- I have used alias cf=”php bin/magento cache:flush” so whenever I’ll run cf in the Magento root directory complete cache flush command will run.
If you have any doubt then please leave us a comment here.
Thanks! 🙂
Be the first to comment.