• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

Understanding How Umask Controls the Initial File / Directory Permissions in Linux

by admin

Controlling Initial File / Directory Permissions

When new files and directories are created in Linux, default permissions are initially set. These permissions are calculated by taking the default permissions of the files/directories created and subtracting the umask value from it. The umask is a four-digit octal number that represents the value of permissions that will be masked out. In other words, permissions specified in the umask represent the permissions that will be automatically withheld when you create a new file.

Files and directories have different default permissions when they are created. The default permissions applied to files is 666. For directories, the default permissions are 777. The following example illustrates the process of how initial file permissions are calculated:

 666   Default File permission.
-002   Umask value
----
 664   Initial file permission (rw-rw-r--)

Viewing and Setting the umask Value

The umask command is the utility that is provided to view or change the current umask. The umask comes preset in configuration files and to view the current umask issue the command without any options:

$ umask 
0002

The umask may be changed at any time simply by typing umask followed by the new desired value:

$ umask 0022 
$ umask
0022

The root users’ account has a default umask of 0022 subsequently, all files created by root have default permissions of 644 (rw-rw-r–) allowing only read access to anyone other than root.

Filed Under: Linux

Some more articles you might also be interested in …

  1. eqn: Equation preprocessor for the groff (GNU Troff) document formatting system
  2. lpinfo Command Examples
  3. How to transfer files securely using sftp (examples included)
  4. fnm: Fast Node.js version manager
  5. What are /dev/zero and /dev/null files in Linux
  6. lastlog Command Examples in Linux
  7. lcov: command not found
  8. halt Command Examples in Linux
  9. pvck Command Examples in Linux
  10. csplit: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright