Execute CLI commands in Magento

Magento contains a bin/magento command line script which supplies you with tons of actionable commands that let you carry out functionality on your store instance.

M Bytes Newsletter
Get the developer newsletter

    Fresh bytes every Thursday. No spam, ever. Unsubscribe anytime.

    Join 9,000+ developers and get three free video lessons every week.

    Magento's bin/magento script supplies you with tons of actionable commands that let you carry out functionality on your store instance.

    To see all available commands, just run it with no arguments:

    bin/magento

    Take a moment to look through the output - it shows all available commands, along with their descriptions. While there are many commands available, you'll likely use these two most frequently:

    bin/magento cache:flush
    bin/magento setup:upgrade

    Typing these can be a bit repetitive, but luckily Magento’s CLI script is pretty smart.

    As long as what you type isn't ambiguous or can reference other commands, you can use shortened versions for any command.

    For example, these shortened commands work exactly the same as their longer counterparts:

    bin/magento c:f  # Same as cache:flush
    bin/magento :up  # Same as setup:upgrade

    Note: If for some reason multiple commands match your shortened version, Magento will not be able to proceed and will let you know.

    You can make your commands even more succinct by creating a bash alias.

    Add this line to your ~/.bashrc or ~/.zshrc file:

    alias m="bin/magento"

    Then after reloading your terminal, your commands can become super terse!

    m c:f  # cache:flush
    m :up  # setup:upgrade

    These shortcuts can save you a ton of typing during development. Just remember to always use full commands in documentation, to keep things super clear and easy to understand, as well as in deployment scripts, where short commands can cause your builds to unexpectedly fail.