Super User is a question and answer site for computer enthusiasts and power users. 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 have come up with an issue when I tried to save a file. I managed to write the intended file but then when I try to save it with the command Ctrl + x, Ctrl + s the message comes up Directory / write-protected How can I save the file?

share|improve this question

migrated from Mar 10 '13 at 4:28

This question came from our site for professional and enthusiast programmers.

Wait, you're trying to save a file into the root directory? Are you sure you actually want to do that?

If you're sure, save it as /sudo::/filename instead. I don't know much about OSX, but as it's your own machine I'm assuming you have sudo permissions, in which case Emacs will prompt you for your password, and should then write the file.

share|improve this answer
That's the weird thing! I'm not! It's possible I was before, but I changed the save location to a folder that is definitely fine to write in and emacs is still giving me strife. – user1765835 Mar 11 '13 at 12:42
How about C-x C-w ~/filename RET to save into your home directory. Does that work? – phils Mar 11 '13 at 19:16
This is so useful for jumping into /etc/ without reverting to launching another session as sudo. Thanks! – Droogans Oct 19 '14 at 2:23

You can use C-xdEnter to view (dired) the directory. Go to the parent directory (pressing Enter on ..) and change the permissions for the directory by pressing S-mu+wEnter. Then, you should be able to save the file.

share|improve this answer
When I try to do that I get the message "Operation not permitted, /../.file" – user1765835 Mar 9 '13 at 18:33
If you do not have the permission to create a file in a directory and you cannot change it, Emacs cannot do anything about it. Ask your system administrator. – choroba Mar 9 '13 at 18:36
Also, how can I get the directory of a file I haven't saved yet? – user1765835 Mar 9 '13 at 18:38
I am the system administrator. I'm just working on my laptop. How do I let emacs know that? – user1765835 Mar 9 '13 at 18:39
@user1765835: As a system admin, you should be permitted to change permissions on directories. What OS are you running? Do you use ACL's? – choroba Mar 9 '13 at 18:45

Start from emacs -Q, i.e., no init file (no ~/.emacs). It does not sound like you did that. My guess is that something in your init file is messing things up.

If you have no such problem when you start from emacs -Q, then bisect your init file recursively until you find the problematic code. Quick to do, no matter how big your init file is.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .