Create short forms of Magento 2 commands in Linux

Create short forms of Magento 2 commands in Linux

During development with Magento 2, we need to run the command repeatedly. And each time we need to type bin/magento command.

In this article, I will show you how you can create short forms of Magento 2 commands in Linux. For example, you can clean the cache by only typing c:c without php bin/magento cache:clean at the root of Magento.

You don’t need to do anything. Just open .bashrc file from your home folder

File Path: /home/username/.bashrc

Now just add the following line at the bottom of the file

alias c:c='php bin/magento c:c'

Now restart the terminal.

That’s all! you can now clean the cache by only typing c:c at the root of the Magento.

You can add any number of short-form of commands in this file.

Here is my short forms of Magento 2 commands

My .bashrc File

This is a little bit hard to set dynamic commands like if you need to make an alias of php bin/magento deploy:mode:set developer and production you need to make two aliases here like d:m:s:d and d:m:s:p.

So it’s also a good idea to add an alias of php bin/magento as m so now you can run commands like m command:name. For example to clean the cache type m c:c

Please comment below if you have any questions. Thank you for reading.

Keep sharing and liking. Happy Coding 🙂