• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 863
  • Last Modified:

umask?

When would you use umask?  Cant you just use chmod instead?  I know umask is used to set default permissions, but I do not understand when/how it would be used. Can anyone shed some light?
Thanks
0
dissolved
Asked:
dissolved
  • 4
  • 4
2 Solutions
 
kusuma_hsCommented:
umask sets the file mode creation mask of the invoking process to the given mode. You can specify the mode in any of the formats recognized by chmod; see chmod for more information.

The file mode creation mask (often called the umask) determines the default permissions for any file created by the process. For example, a file created by the create command has the permissions specified by the umask unless the create command specifies explicit permissions.

Calling umask without a mode argument displays the current umask.

if u set umask in /etc/profile or any startup file, whenever u create a new file/directory, the default permissions will be

777 subtract umask value - for a directory and
666 subtract umask value for a file.

where as chmod is used to change the permissions of a file/dir which already exist.

Ex.

if umask is set to 022 and

if u create a new directory called test. now test will have 777-022 = 755 (rwxr-xr-x) permission by default.
if u create a new file called testfile, now testfile will have 666-022 = 644 (rw-r--r--) permission by default.

This umask can be set in /etc/profile or $HOME/.profile or $HOME/.login etc

Regards,
0
 
dissolvedAuthor Commented:
ah, I see. Umask is defined globally in your unix box?  It is a value, that you subtract from the default file's permissions. ie: 777-444=333 (write ane execute permissions)
0
 
manav_mathurCommented:
>It is a value, that you subtract from the default file's permissions
octal subtraction, yes.
The value of umask is valid in the current shell
for eg
umask 022
(umask 044)
##create file1 here

the permission bits of file1 will still be operated upon by umask 022, and not 044.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
dissolvedAuthor Commented:
I just checked my box, my umask is set to 022. So this means when I create new files, they will have a default permission of what?
thanks!
0
 
manav_mathurCommented:
depends on what permissions you give when you create the file. From the permission bits that you supply, the umask is deducted.
0
 
manav_mathurCommented:
for eg, if you touch a file (which gives, I believe 666 file prmissions), the actual permissions that the file gets is 644. ie -rw-r--r--
0
 
dissolvedAuthor Commented:
what are default permissions?

Say I do a cat > test.txt
garbage here
CTRL Z

ls -l is showing  rw - r  -r  , which means default permissions were probably 666 (since my umask is 022). Am I correct?
Thanks for all the help
0
 
manav_mathurCommented:
Yes. cat, touch etc all give a default file permission of 666.
0
 
dissolvedAuthor Commented:
thanks a lot!
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now