04. Setting Default Permissions umask

When we create a file or directory, accession modes are applied by default. We can see and change these defaults with umask.

Default settings

To look at your current masking simply use the umask command.

$ umask
0022

Since our umask is set to 0022, and the default file mode is usually 666, we have:

Original file mode
- rw- rw- rw-
Masking
- --- -1- -1-
Result
- rw- r-- r--

Thus we see the canonical 644 file permission that we get when we create new files.

$ touch sampleFile.txt
$ ls -l sampleFile.txt
-rw-r--r-- 1 JohnDoe staff 0 Mar 30 18:34 sampleFile.txt

Changing umask

To change umask, simply pass the octal value as an argument (include a 0 for the file mode).

$ umask 0777
$ touch sampleFile2.txt
$ ls -l sampleFile2.txt
---------- 1 JohnDoe staff 0 Apr 01 18:34 sampleFile2.txt

Here, we would cannot do anything with our sampleFile2.txt because umask suppressed all its accession modes.

Aching back from coding all day?

Self-Massage Tool

Aching back from coding all day? Try Back Problems

Relieve spasms, tight muscles, trigger points and pressure points with the Body Back Buddy! This trigger point massage is designed to help you self-message any area of your body - especially those that are hard to reach. Keeping your muscles relaxes and out of contraction is importan in helping to reduce pain and prevent muscle injury.

$ Check price
29.9529.95Amazon 4.5 logo(3,443+ reviews)

More Back Problems resources

Take your Linux skills to the next level!

Linux for Beginners

Take your Linux skills to the next level! Try Linux & UNIX

Linux for Beginners doesn't make any assumptions about your background or knowledge of Linux. You need no prior knowledge to benefit from this book. You will be guided step by step using a logical and systematic approach. As new concepts, commands, or jargon are encountered they are explained in plain language, making it easy for anyone to understand.

$ Check price
24.9924.99Amazon 4.5 logo(101+ reviews)

More Linux & UNIX resources

Ad