So I'm trying to setup a python project and for whatever reason i can't create a file called __init__.py...

I've tried doing all the following:

vim __init__.py               // opens file but can't save
sudo vim __init__.py          // same as command above
echo "" > __init__.py         // outputs: bash: __init__.py: Permission denied
sudo echo "" > __init__.py    // same output as above

The directory I'm trying to make these calls in is empty so there are no other conflicting files...

Does anyone know what the issue here may be?


ls -ld returns drwxr-xr-x 2 root root 4096 Nov 27 09:47 .

id returns uid=1000(quinn) gid=1000(quinn) groups=1000(quinn),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),119(lpadmin),130(lxd),131(sambashare)

  • Can you update your question with the output of ls -ld . (while you're in the directory in which you're trying to create files). Also add the output of id. – Andy Dalton Nov 27 '19 at 16:10
  • @AndyDalton updated – Quinn Nov 27 '19 at 16:14
  • Please note the 4th try doesn't do what you think it does: you run echo "" with elevated privilege (don't do this just to get around permission problems!!!) but the redirection is evaluated outside that, as for any cmd > file sequence. This takes a while to get used to if you're not used to Linux shells. – Mats Wichmann Nov 27 '19 at 16:17

The reason that you're unable to create the file in the current directory is that your user (quinn, which the id utility reports) has no write permission in the directory (which is owned by root, which is evident in the ls output).

It's not clear whether the directory should be owned by the root user, or why it is owned by the root user, but this is the reason you can't create the file as the user quinn.

  • ah, thats probably what it is... i had to do a bunch of commands as root earlier so i did a sudo -i and likely made the directory then... Will see if i can fix it – Quinn Nov 27 '19 at 16:40
  • Yup, that was it, managed to fix it - thanks! – Quinn Nov 27 '19 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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