5

Can I set permissions when I create a file/directory using a single command or do I have to create the file/directory first and then use chmod to set its permissions?

For instance to do something like this

// for directories
mkdir 755 test 

// for files
touch 644 test/my_file.php
ltdev
  • 4,037
  • 20
  • 69
  • 129

3 Answers3

7

For files, try using install command:

$ install -m 644 /test/path/ myfile.php

For folders, mkdir with -m param:

$ mkdir -m 755 test

You might have to execute that as sudo.

henriale
  • 1,012
  • 9
  • 21
3

Man pages are your friend. This is possible with GNU mkdir but not with GNU touch.

mkdir -m 755 test
jangler
  • 949
  • 6
  • 7
0

you can use following command to create directory and give permissions at the same time

mkdir -m755 test
Omer Gafar
  • 129
  • 1
  • 6