How to create all files generated in a directory with 644 permissions?

Hi,

We are using AIX machines. How to create all files generated in a directory with 644 permissions automatically.

Regards,
Suresh

mkdir -m 644 dirname

---------- Post updated at 07:30 PM ---------- Previous update was at 07:26 PM ----------

root@nio:/tmp# mkdir -m 644 testdir

root@nio:/tmp# touch testdir/file1

root@nio:/tmp# stat -c "%a %n" testdir/
644 testdir/

root@nio:/tmp# stat -c "%a %n" testdir/file1 
644 testdir/file1

I think I'd like to correct this. As far as I'm aware, permissions when creating files is set by the inverse of the umask value. The command above will create a directory with tw-r--r-- permissions (meaning you cannot cd into it) but that's all.

To create files with permissions 644, do the following:-

umask=022
touch /tmp/my_file
ls -l /tmp/myfile

For me, umask=066, so default permissions are rw-------

Robin

2 Likes

Yes Robin..

I am unable to do cd directory. I have already a directory with below permissions. Now, whatever the files generating in this directory, should generate with 644 permissions. How to get this?

drwxrwxr-x dump

Regards,
Suresh

rbatte1: thanks for sharing knowledge :b:. I wish I would have created and tested as a normal user :slight_smile:

You use umask command and its per user or set as default for all in AIX I suppose in /etc/environment ...
What you want is

 umask 022 

See Robin's explanation above

Depending on the shell and the user you run it under, changing the umask to 022 might be sufficient.

Directories do not work that way.

Set a umask of 022 for your user or application. umask 022 in their ~/.profile may be sufficient for a user, depending on what shell they use. For an application, that depends on the application. More details, please.

As vbe and corono688 mentioned umask value goes with user.

In AIX you can set umask for each user or set default value for all users

To change the umask value
chuser umask=022 <username>

The file which hold this information is 
"etc/security/user"

You have to run the above command as root.

Now the question is, how are you getting the file? ftp, sftp , cp, scp etc.., or are you generating the file from within application/DB?

I have application user abc who creates the files in dump - directory. One more user xyz has to read the file in the directory. With 644 permission we are able to do this. I may not have root access every time. How to set umask configurations? Please help.

Ok,
Check for the umask value on local service ID (for application).

lsuser -a umask <username>
lsuser -a umask abc  (abc is user)
abc umask=XXX

If the value is NOT 022 or 22 (both mean same, then change it to 022

chuser umask=022 <username>
chuser umask=022 abc

Again list umask

lsuser -a umask abc

Note: You have to restart the application for changes to be effective.

I hope this helps.

Try setting the umask for the user abc.