How to run a php file that uses wordpress functions from command line?

WordPress has a command line library called WP-CLI. You can extend it to create your own commands. I would recommend this for any work on the command line.