Save an edited file in nano, but no permissions
Solution 1
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.
Solution 2
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.
Solution 3
Try ctrl+o and choose to save the file to your home folder.
Then do sudo mv /home/username/file /etc/
Related videos on Youtube
theTuxRacer
I am an inquisitive developer. Regular joe by day, TV freak by night. I love all things Android. Weaned off Ubuntu onto a Mac.. Back to linuxland with Fedora 28. I enjoy getting lost on my motorcycle. Also learning photography. Dabbling in both on a weekend is my idea of a day well spent. Student of Life, Laidback, Abrasive, Possesive, Obsessive.
Updated on September 17, 2022Comments
-
theTuxRacer over 1 year
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.
-
Admin over 13 yearsThe 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 over 13 yearsyeah, i guess I could do that. thanks. but ill still hold on accepting it, to see if there is really a way.
-
Jervelund over 9 yearsCoupled with Ctrl + z and
fg
this is hands down the fastest way to do it. -
Martin Thornton almost 9 yearsYou need to
sudo cp </full/temp/name> </full/original/name>
andrm </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. -
Sudip Bhandari over 7 yearsI find this way easier and faster than the accepted answer (Y)
-
Josh almost 5 yearssudo chmod 777 yourfile