1

I have a folder, I am setting its permissions by using chmod.

chmod 777 /home/Desktop/Project

is success.

I am using a tool(.exe) that will download the project from the repository. But after the download completes all the subfolders and files under /home/Desktop/Project is having permissions as drw-r--r-- and -r--r--r-- respectively.

Is their any way I can set executable permissions for any files/folder under Project directory prior I start to download in Project Folder ?

Note: The entire processing is done using python script which uses the tool to download the project as said above. Testing on Ubuntu 14.04 LTS.

5
  • 1
    ... create a script that does what this tool does and add a "chmod" on the next line. And "chmod 777" ... 755 is the most you should need for permissions. If you use 644 for files and 755 for dirs you will prevent yourself from using 777 on a file or dir that should not have these permissions
    – Rinzwind
    Sep 28, 2015 at 12:48
  • The same tool used for downloading also builds the project immediately after download completes, so I cannot set the permissions after download starts. I need a ways as just before the download starts, I should be able to add files with "Allow executing file as program" as default for Project Directory. Sep 28, 2015 at 12:52
  • The build tool should set the executable bit on the files that need it. Otherwise I'll say it's a bug.
    – Rmano
    Sep 28, 2015 at 13:27
  • You're using a .exe? From Windows? If the thing is a Windows-based download manager or such, it won't 'work' with Linux filesystem permissions like you want it to. Have you tried looking for a Linux-equivalent 'download and build' program?
    – Thomas Ward
    Sep 28, 2015 at 13:29
  • The tool is build for linux too, I am using the linux version of the tool. Sep 29, 2015 at 4:32

2 Answers 2

1

See man umask. It says, in part:

trusty (1) umask.1posix.gz
Provided by: manpages-posix_2.16-1_all bug

NAME

       umask - get or set the file mode creation mask

SYNOPSIS

       umask [-S][mask]

DESCRIPTION

       The  umask utility shall set the file mode creation mask of the current
       shell execution environment (see Shell Execution Environment )  to  the
       value specified by the mask operand. This mask shall affect the initial
       value of the file permission bits of  subsequently  created  files.

What this means, is that when a file is created, it starts off assuming its permission wil be 777, rwxwrxwrx, Read, Write and Execute access for Owner, Group and World. But then, the "mode bits" (another name for "permission bits", but shorter) are ANDed with the COMPLIMENT of the umask value. If one sets umask 022 (in ~/.bashrc, or in the current shell, to affect that shell) then the operation is:

 777    Original mode bits  0B111111111
 755    Compliment of 022   0B111101101
-----   AND     
 755    The result, rwxr-xr-x (Read, Write, Execute for Owner, Read, Execute for Group and World  

Another common umask value is 027 (NO access for World).

This is a tricky idea, and deserves understanding. I remember being confused for weeks about this back in the 1970s when I first ran into Unix.

1
  • I believe this is the only reason, While I created the directory I set its permissions (777) using os.system("chmod 777 <path>") I am using python script, I used subprocess to start a new process (invokes the dowlnload/build tool). I need to set umask for this subprocess right ? Cause it will be considered as a new environment. Sep 29, 2015 at 4:46
0

What you could do is to add that command to your .bashrc as function or alias, and execute that function or alias with && operator.

In other words ./pythonscript.py && aliasToChMod

You must log in to answer this question.

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