Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


share|improve this question
The changes are extensive. I suppose I can open a new terminal, hen-pick the changes and copy paste them. Or just copy-paste the whole thing. But I was wondering if there was a "geeky" way of doing it. – theTuxRacer Nov 30 '10 at 5:19
up vote 12 down vote accepted

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.

alt text 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.

share|improve this answer
You need to 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. – Martin Thornton Jul 11 '15 at 14:34

Try ctrl+o and choose to save the file to your home folder.

Then do sudo mv /home/username/file /etc/

share|improve this answer
yeah, i guess I could do that. thanks. but ill still hold on accepting it, to see if there is really a way. – theTuxRacer Nov 30 '10 at 5:35

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.

share|improve this answer
Coupled with Ctrl + z and fg this is hands down the fastest way to do it. – Jervelund Dec 13 '14 at 11:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.