I edited a file in /etc/ that I want to save, but forgot to open it using sudo. I remember there was a command to save such a file in vi, and want to know if there is any such way to do it in nano?
Thanks.
I edited a file in /etc/ that I want to save, but forgot to open it using sudo. I remember there was a command to save such a file in vi, and want to know if there is any such way to do it in nano?
Thanks.
Yes you could save it temporarily to your home directory. Press Ctrl+O to change the path to your home directory or in /tmp and then press Enter to save it. Then you can sudo mv
it.
Press CTRL+O will show you the path. Change that to your home directory or /tmp. For example File Name to Write: /tmp/filename and press Enter.
sudo cp </full/temp/name> </full/original/name>
and rm </full/temp/name>
to maintain permissions on the original file. sudo mv
will destroy them, which is not what you want, especially if it had executable permissions.
Jul 11, 2015 at 14:34
Just open a new tab in terminal, use chmod to change permissions of the file to 777, save the file in nano, then change the permissions back to what they were, probably 644. An alternative is to change owner using chown to yourself, save the file, and change ownership back to root.
fg
this is hands down the fastest way to do it.
Dec 13, 2014 at 11:11
Try ctrl+o and choose to save the file to your home folder.
Then do sudo mv /home/username/file /etc/