Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Aptitude
  • Engineering Mathematics
  • Discrete Mathematics
  • Operating System
  • DBMS
  • Computer Networks
  • Digital Logic and Design
  • C Programming
  • Data Structures
  • Algorithms
  • Theory of Computation
  • Compiler Design
  • Computer Org and Architecture
Open In App
Next Article:
users command in Linux with Examples
Next article icon

Umask command in Linux with examples

Last Updated : 19 Mar, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The umask command in Linux is used to set default permissions for files or directories the user creates.

How does the umask command work?

  • The umask command specifies the permissions that the user does not want to be given out to the newly created file or directory.
  • umask works by doing a Bitwise AND with the bitwise complement(where the bits are inverted, i.e. 1 becomes 0 and 0 becomes 1) of the umask.
  • The bits which are set in the umask value, refer to the permissions, which are not assigned by default, as these values are subtracted from the maximum permission for files/directories.

How to calculate umask value?

Syntax:

$umask

[The above command will give the following output]

umask command in Linux without parameters (output)
pratyay@pratyay-ROG-Strix-G531GT:~/Study/Linux/CommandTrials/umask$ umask
0002
  • Here, the first digit, 0 is called the sticky bit, it is a special security feature.
  • The next three digits represent the octal values of the umask for a file or directory.

For a better understanding of umask working, we need to understand octal mode security settings. The three rwx permissions (Read-Write-Execute) values are converted into three-bit binary values and represented by a single octal value as shown in the following table:

PermissionsOctal ValueBinary ValueDescription
---0000No permission
--x1001only permission to execute 
-w-2010only permission to write
-wx3011permission to write and execute
r--4100only permission to read
r-x5101permission to read and execute
rw-6110permission to read and write
rwx7111permission to do all three, i.e. read, write and execute

Simplification:

Let's understand the above table with an example: Let's explain the previous output we got using umask, 0002

  • For a better understanding of the above table, it might seem confusing at first, but it's pretty simple, all you have to remember is the three modes, rwx (read-write-execute).
  • the bit for the respective mode, i.e. in 3-bit number, the first bit(leftmost) is for read, then write and execute respectively. In the above example, 0002 is outputted by the umask command, we will be not worrying about the first 0 as of now. the next three digits are 0 0 2.
  • Each digit here is for different classes of users, there are a total of 3 classes of users in Linux,
    • The owner
    • group members
    • everyone else
  • The above output (0002) means that the umask is restricting write permissions for 'others'. Since umask subtracts from the default permissions:
    • For a file (default: 666), the umask 0002 results in 664 (rw-rw-r--), meaning others can only read the file.
    • For a directory (default: 777), the umask 0002 results in 775 (rwxrwxr-x), meaning others can only read & execute, but not write."
  • The umask 0002 ensures that while owner and group can read & write, others can only read (for files) or read & execute (for directories)

How to set and update the default umask value?

We can set and update the default umask value using the command umask followed by a parameter, which should be an integer ranging from 000-777. The syntax for updating the umask value is the same as setting the umask value.

Setting the umask value:

We can use the umask command to set the default permissions with which the files/directories will be created.

Syntax

$umask 543
umask command in Linux terminal (Setting default umask value)

How to calculate umask values for files and directories?

Here, when we execute the command, the values are not directly allocated as 5 for the owner, 4 for the group members and 3 for the others, but the value we pass as an argument is subtracted from the max/full permission set. There are two full permission sets:

  • File -> The full permission set for a file is 666 (read/write permission for all)
  • Directory -> The full permission set for a directory is 777 (read/write/execute)

Note: The files cannot be given execution permissions by default as it can cause a security concern, and Linux systems are pretty much known for their amazing security, so that wouldn't be good.

So, once we have set the umask value to 543, let's see what happens when we make a directory(7-7-7) and a file(6-6-6)

Making a directory:

  • When we make a new directory, the permissions will be calculated as (full permissions for directory) - (umask value) i.e. 777 - 543 = 234
  • 234, can be clarified more as:
    • 2 for the owner, that is 010 in binary, so write permissions for the owner.
    • 3 for the group members, that is 011 in binary, so write and execute permissions for the group members.
    • 4 for everyone else, that is 100 in binary, so only read permission for everyone else.
Making a directory with custom set umask
  • The output shows the following: d-w--wxr--, which is a bit confusing, but when we simplify it, it can be seen as d   -w-   -wx   r--, d here stands for directory and the latter 3 are the permissions for the respective users as we discussed in the previous point.

Making a file:

  • When we make a new directory, the permission will be given out similarly but with a slight change as follows: (full permissions for file) - (umask value) i.e. 666-543 = 123
  • Linux does not provide execute permissions by default, even if it is specified in the umask. 
  • 123 can be clarified more as:
    • 1 for the owner, that is 001 in binary, so execute permission should be given to the owner, but Linux doesn't give execute permissionMaking a directory:s by default, so, the value is promoted by one and we get 010, and write permission will be granted to the owner.
    • 2 for the group members, that is 010 in binary, so write permissions for the group members.
    • 3 for everyone else, that is 011 in binary, so write and execute permission for everyone else, but again execute permission cannot be provided, so the value will be promoted one more time, and we will get 100, so read permission will be granted to everyone else.
Making a file using custom set umask
  • The output shows, --w--w-r--  which can be simplified as -   -w-  -w-  r--, that is write for the owner, write for the group, and read for everyone else.
  • Now when we will try to open this file as the owner, we will get access denied, as the owner of the file only has access to write to it.
Trying to open the file without access
  • So in order to open the file, we would either have to be the admin or be other than owner and group members.
  • Opening file as Admin:
Opening file as admin
  • You can also use symbolic notations with umask. Below in "umask u-w" command 'u' stands for user and '-' is used for remove permission and 'w' stands for write permission.
 
  • Create File named newDir and check permissions.
 
  • In given figure it shows that permission for newDir is "dr-x-wx---" and user's write permission has been removed.
 
  • If you use '+' symbol instead of '-' then it will give corrosponding permission to the user. you can also use 'r' which is used for read permission. ie. umask u+rw
 
  • Now, Give write permission to user and check it's permission by creating an directory.
 

So, in this way, it is possible to use umask command in order to set default permissions for files and directories. It should be noted that the default permissions for files and directories are different as files do not provide the option to execute by default.

What is the difference between chmod and umask?

  • The umask command can be only used on new files i.e. while creating new files, any files created prior to using the umask command will have no effect.
  • The chmod command must be used on files that are already present, it is used to change the access permissions of files that have been created earlier.

Thus, we need umask command in order to set the default access permissions for files and directories which will be created in the future, and we need the chmod command in order to change the access permissions for files that have been already created and are present in the system.


Next Article
users command in Linux with Examples

D

dhondpratyay
Improve
Article Tags :
  • Operating Systems
  • Linux-Unix
  • linux-command
  • Linux-file-commands

Similar Reads

  • pmap command in Linux with Examples
    The pmap command in Linux is a powerful utility used to display the memory map of a process. A memory map provides insight into how memory is allocated and distributed within a running process. This can be incredibly useful for developers and system administrators when debugging memory issues, optim
    4 min read
  • uname command in Linux with Examples
    Linux, renowned for its open-source flexibility and powerful performance, offers a range of commands that reveal the inner workings of your system. Among these, the 'uname' command stands out as a versatile tool that provides key details about your Linux machine. Here, we will learn the basics of th
    4 min read
  • users command in Linux with Examples
    users command in Linux system is used to show the user names of users currently logged in to the current host. It will display who is currently logged in according to FILE. If the FILE is not specified, use "/var/run/utmp". "/var/log/wtmp" as FILE is common.  Syntaxusers [OPTION]... [FILE]where, OPT
    2 min read
  • lsusb command in Linux with Examples
    The 'lsusb' command in Linux is a useful utility for displaying information about USB buses and the devices connected to them. It provides a detailed view of the USB hardware connected to your system, including details such as speed, bus number, device class, and type. This command is particularly v
    2 min read
  • Linux make Command with Examples
    The make command for Linux is a very useful utility in the automation of software development and performing tasks in a Linux environment. It simply reads a special file, which is called a Makefile and this file describes how one's program is compiled and linked with another file or another program
    6 min read
  • seq command in Linux with Examples
    The 'seq' command in Linux is a powerful utility used to generate a sequence of numbers. It is particularly useful in scenarios where you need to create a list of numbers within loops, such as while, for, or until loops. With 'seq', you can quickly generate numbers from a starting value (FIRST) to a
    4 min read
  • tac command in Linux with Examples
    tac command in Linux is used to concatenate and print files in reverse. This command will write each FILE to standard output, the last line first. When no file is specified then this command will read the standard input. Here, we will look deeper into the tac command, exploring its syntax, various o
    3 min read
  • whatis Command in Linux with Examples
    whatis command in Linux is used to get a one-line manual page description. In Linux, each manual page has some sort of description within it. So, this command search for the manual pages names and show the manual page description of the specified filename or argument. Syntax of the `whatis` command
    5 min read
  • sync command in Linux with Examples
    sync command in Linux is used to synchronize cached writes to persistent storage. If one or more files are specified, sync only them, or their containing file systems. Syntax: sync [OPTION] [FILE]... Note: Nothing is being shown in the screenshots just because sync command makes the cache in the bac
    1 min read
  • sudo Command in Linux with Examples
    sudo (Super User DO) command in Linux is generally used as a prefix for some commands that only superusers are allowed to run. If you prefix any command with "sudo", it will run that command with elevated privileges or in other words allow a user with proper permissions to execute a command as anoth
    8 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences