Why are execute permissions along with write permissions needed for creating a file in C (Linux)?

2

2

I am trying to create a file from my C source code on linux. I am using the dd command for reading from a file and writing it to a file by creating it. If I don't have execute permissions (I have write permissions) for the target directory (where the file is going to be created), it is unable to create the file. If I have both write and execute permissions, it is able to create file.

What is the reason for this?

Chinna

Posted 2013-12-05T06:41:32.207

Reputation: 1 579

Answers

8

When set, the r, w, and x mode attributes have the following effect on files and directories:

  • r Attribute (read permission):

Files: Allows a file to be opened and read.

Directories: Allows a directory's contents to be listed if the execute attribute is also set.

  • w Attribute (write permission):

Files: Allows a file to be written to or truncated, however this attribute does not allow files to be renamed or deleted. The ability to delete or rename files is determined by directory attributes.

Directories: Allows files within a directory to be created, deleted, and renamed if the execute attribute is also set.

  • x Attribute (execute permission):

Files: Allows a file to be treated as a program and executed. Program files written in scripting languages must also be set as readable to be executed.

Directories: Allows a directory to be entered, e.g., cd directory.

Reference: The Linux® Command Line William E. Shotts, Jr.

I would recommend to read this book or pdf version which you can download it from this link: http://sourceforge.net/projects/linuxcommand/files/TLCL/13.07/TLCL-13.07.pdf/download

Sepahrad Salour

Posted 2013-12-05T06:41:32.207

Reputation: 928

0

The execution bit on a directory grants you the possibility to enter/trasverse it. Therefore it's a prerequisite to create a file (otherwise you can enter it) aswell in your case.

fede.evol

Posted 2013-12-05T06:41:32.207

Reputation: 1 718