How to find the Magento 2 frontend base URL using the command line?

Magento 2 stores the root URLs in the database the same way as Magento 1.x.

You can get it from the command line using the following command:

mysql --host=<host> --user=<user> --password=<password> --database=<database> -e "SELECT value FROM core_config_data WHERE path IN ('web/secure/base_url', 'web/unsecure/base_url');"

<host>, <user>, <password> and <database> are the Magento 2 database credentials, you can find them in the app/etc/env.php file

See also:

Since Magento 2.2, you can use a new console command bin/magento config:show for it:

bin/magento config:show web/secure/base_url
bin/magento config:show web/unsecure/base_url]