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.

Take your Linux skills to the next level!

System Admin Handbook

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

This book approaches system administration in a practical way and is an invaluable reference for both new administrators and experienced professionals. It details best practices for every facet of system administration, including storage management, network design and administration, email, web hosting, scripting, and much more.

$ Check price
74.9974.99Amazon 4.5 logo(142+ reviews)

More Linux & UNIX resources

Aching back from coding all day?

Foam Seat Cushion

Aching back from coding all day? Try Back Problems

This foam seat cushion relieves lowerback pain, numbness and pressure sores by promoting healthy weight distribution, posture and spine alignment. Furthermore, it reduces pressure on the tailbone and hip bones while sitting. Perfect for sitting on the computer desk for long periods of time.

$ Check price
99.9599.95Amazon 4.5 logo(9,445+ reviews)

More Back Problems resources

Ad