Save an edited file in nano, but no permissions












17















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.










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
















17















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.










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














17












17








17


5






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.










share|improve this question














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.







sudo text-editor nano






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 30 '10 at 5:07









theTuxRacertheTuxRacer

7,497156187




7,497156187













  • 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



















  • 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

















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





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










3 Answers
3






active

oldest

votes


















19














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





















  • 3





    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





















3














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



















  • 1





    Coupled with Ctrl + z and fg this is hands down the fastest way to do it.

    – Jervelund
    Dec 13 '14 at 11:11













  • I find this way easier and faster than the accepted answer (Y)

    – Sudip Bhandari
    Nov 2 '16 at 14:17



















2














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














Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f15447%2fsave-an-edited-file-in-nano-but-no-permissions%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









19














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





















  • 3





    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


















19














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





















  • 3





    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
















19












19








19







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















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














share|improve this answer



share|improve this answer








edited Feb 2 at 19:47









wjandrea

9,46042664




9,46042664










answered Nov 30 '10 at 5:23









karthick87karthick87

49.9k54167218




49.9k54167218








  • 3





    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
















  • 3





    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










3




3





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







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















3














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



















  • 1





    Coupled with Ctrl + z and fg this is hands down the fastest way to do it.

    – Jervelund
    Dec 13 '14 at 11:11













  • I find this way easier and faster than the accepted answer (Y)

    – Sudip Bhandari
    Nov 2 '16 at 14:17
















3














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



















  • 1





    Coupled with Ctrl + z and fg this is hands down the fastest way to do it.

    – Jervelund
    Dec 13 '14 at 11:11













  • I find this way easier and faster than the accepted answer (Y)

    – Sudip Bhandari
    Nov 2 '16 at 14:17














3












3








3







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













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












share|improve this answer



share|improve this answer










answered Dec 1 '10 at 3:10









charlie-tcacharlie-tca

1,119915




1,119915








  • 1





    Coupled with Ctrl + z and fg this is hands down the fastest way to do it.

    – Jervelund
    Dec 13 '14 at 11:11













  • I find this way easier and faster than the accepted answer (Y)

    – Sudip Bhandari
    Nov 2 '16 at 14:17














  • 1





    Coupled with Ctrl + z and fg this is hands down the fastest way to do it.

    – Jervelund
    Dec 13 '14 at 11:11













  • I find this way easier and faster than the accepted answer (Y)

    – Sudip Bhandari
    Nov 2 '16 at 14:17








1




1





Coupled with Ctrl + z and fg this is hands down the fastest way to do it.

– Jervelund
Dec 13 '14 at 11:11







Coupled with Ctrl + z and fg this is hands down the fastest way to do it.

– Jervelund
Dec 13 '14 at 11:11















I find this way easier and faster than the accepted answer (Y)

– Sudip Bhandari
Nov 2 '16 at 14:17





I find this way easier and faster than the accepted answer (Y)

– Sudip Bhandari
Nov 2 '16 at 14:17











2














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


















2














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
















2












2








2







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













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












share|improve this answer



share|improve this answer










answered Nov 30 '10 at 5:25









RolandiXorRolandiXor

44.8k26140231




44.8k26140231













  • 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





















  • 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



















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







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




















draft saved

draft discarded




















































Thanks for contributing an answer to Ask Ubuntu!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f15447%2fsave-an-edited-file-in-nano-but-no-permissions%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents