Ok, humor me ... ;)
after logging on, do sudo -s
provide the password for the account you used to login.
That sets your session to root user.
Then cd /path/moodlecode/admin/tool/httpsreplace/cli/
php url_replace.php -l
We are not working with files in code nor anywhere else in moodle. Therefore, no file/folder will be tagged as belonging to root sever. All cli scripts read/take the DB variables from config.php. It's just php and the datbase then.
Do you find yourself at a mysql> prompt?
If so, issue: show databases;
Do you see the DB for the moodle?
Then: use [moodledb]; (you provide moodledb name).
Can you query any of the tables?
Could be the DB user you have in config.php file doesn't have the rights to do what needs to be done.
'spirit of sharing;, Ken