Save an edited file in nano, but no permissions

52,429

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.

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.

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/

Share:
52,429

Related videos on Youtube

theTuxRacer
Author by

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, 2022

Comments

  • theTuxRacer
    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
      Admin over 13 years
      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
    theTuxRacer over 13 years
    yeah, i guess I could do that. thanks. but ill still hold on accepting it, to see if there is really a way.
  • Jervelund
    Jervelund over 9 years
    Coupled with Ctrl + z and fg this is hands down the fastest way to do it.
  • Martin Thornton
    Martin Thornton almost 9 years
    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.
  • Sudip Bhandari
    Sudip Bhandari over 7 years
    I find this way easier and faster than the accepted answer (Y)
  • Josh
    Josh almost 5 years
    sudo chmod 777 yourfile