I unintentionally renamed the
/etc directory on a Mac running macOS Monterey, with disastrous consequences: the password for
sudo in Terminal is no longer recognised (because the
/etc/sudoers file can no longer be found), which means I can no longer run any commands that require a password. Worse, I can no longer even log into the Mac.
To resolve the problem I began with the accepted answer described by David Rouse in response to a similar question - Renamed /etc folder. I can't login anymore - asked in 2019.
The first part of that solution (booting the Mac using Single User Mode with the existing password and running
mount -uw) works perfectly.
However, even from Single User Mode I am unable to rename the
/etc directory. For instance, attempting to run
mv in relation to
/etc results in a
No such file or directory message, and the symlink
/private folder appears to be empty - see image below.
So how can I change the folder name back to
/etc so that the Mac becomes operational again?