Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make all new directories have 777 permissions

I have a script that, when run, creates a directory inside /home/test/ and then writes some files in it. When I run this script, it works fine. However, when I call it from a perl script with

$ret = `/home/..../testscript.py`

it doesn't have permissions so it can't create the folder, or can't write inside it after it is created. It looks like when Python does open("/home/test/abcde/file1.txt", "w"), that file has permissions -rw-r--r--

What can I do to get around this? Is there a way to set /home/test to recursively make all subdirectories have global write-access? Or a better solution maybe?

like image 897
Andrew Latham Avatar asked Jul 19 '13 22:07

Andrew Latham


People also ask

How do I give a folder permission to 777?

Easiest way to set permissions to 777 is to connect to Your server through FTP Application like FileZilla, right click on folder, module_installation, and click Change Permissions - then write 777 or check all permissions. Save this answer.

How do I set permissions to all files in a directory?

To change directory permissions for everyone, use “u” for users, “g” for group, “o” for others, and “ugo” or “a” (for all). chmod ugo+rwx foldername to give read, write, and execute to everyone. chmod a=r foldername to give only read permission for everyone.

How do I give permission to all subfolders in Linux?

Use the chmod command to change the permissions for all files, directories, and subdirectories. Note – The permission 755 is good to set for directories but not on files. This set the execute bit on files which is not recommended for any production environments excluded some specific cases.


1 Answers

Put:

os.umask(0000)

in the Python script before it creates the directory. If you can't change the Python script, put:

umask(0000)

in the Perl script before it calls the Python script.

When a new file or directory is created, the permissions are determined by taking the permissions specified in the call to creat() or mkdir(), and then masking off the bits that are specified in the umask.

Typically, applications specify 0666 or 0777 permissions when they call the function (depending on whether they're creating something that should be executable or not). A common value for umask is 022, which turns off group and world write permissions. If you don't want them turned off, use the above umask value to keep the permissions specified in the call.

like image 154
Barmar Avatar answered Oct 10 '22 06:10

Barmar