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

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

Original file mode
- rw- rw- rw-
- --- -1- -1-
- 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?

Acupressure Mat & Pillow

Aching back from coding all day? Try Back Problems

Relieve your stress, back, neck and sciatic pain through 1,782 acupuncture points for immediate neck pain relief. Made for lower, upper and mid chronic back pain treatment, and improves circulation, sleep, digestion and quality of life.

$$ Check price
144.87144.87Amazon 4.5 logo(1,890+ reviews)

More Back Problems resources

Take your Linux skills to the next level!

The Linux Command Line

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

The Linux Command Line takes you from your very first terminal keystrokes to writing full programs in Bash, the most popular Linux shell. Along the way you'll learn the timeless skills handed down by generations of gray-bearded, mouse-shunning gurus: file navigation, environment configuration, command chaining, pattern matching with regular expressions, and more.

$ Check price
39.9539.95Amazon 4.5 logo(274+ reviews)

More Linux & UNIX resources