For most of us, working in Linux or in a shell is not necessarily a daily activity, and that’s totally OK.
I’m not daily working with it either, but occasionally I use one of those funny commands to set the access rights to certain files and/or directories.
This command, chmod, is not super complicated to work with, and is commonly used when working in a shell or terminal on both the MacOS X and Linux platforms. But we need a “magic number” to set these rights. The “magic number” for chmod is also commonly used with FTP programs.
Whenever I use this command, I need to refresh my mind on how to calculate the “magic number”, and I find myself looking for a chmod calculator.
Since I’m lazy at times, I figured: why not have one on my own website?
So I started playing with JavaScript and created this chmod calculator.
The calculator
Since you’re here for the calculator, let’s get right to it:
Ad Blocking Detected Please consider disabling your ad blocker for our website.
We rely on these ads to be able to run our website.
You can of course support us in other ways (see Support Us on the left).
Some background on chmod
“chmod” stands for “Change Mode” which doesn’t tell us much.
It’s commonly used in Unix like systems (which includes Linux and MacOS X) to set the access rights to files and directories, and determine:
– READ, WRITE and EXECUTE rights
– for the OWNER of the file, the GROUP of users of which the owner is part, and for the OTHER users.
Obviously, setting the proper access rights is important to prevent users from getting access to files or directories they should not have access to, or have limited access to. For example: your private files, or have read only access to the company phonebook, or have the ability to run a program without the ability to delete or damage the program.
To calculate this “magic” number we simply need to add numbers.
Each “right” has a value. READ = 4, WRITE = 2 and EXECUTE = 1.
So if we want to allow reading and executing, then we get: READ (4) + EXECUTE (1) = 5.
Now this doesn’t help much, since we need to specify which user will get this right.
For this we need to understand how the magic number is setup.
The first digit is for the owner, the second number for the group and the last number for other users.
Some chmod examples
As an example, let’s assume the owner can do anything with the file: READ (4) + WRITE (2) + EXECUTE (1) = 7.
Users in the same group are allowed to read and execute the file: READ (4) + EXECUTE (1) = 5.
All the other users should be blocked: 0 (they have NO rights).
This results in: 750 which would look like this in the shell/terminal: chmod 750 <yourfile>
Another example; say we’d like everybody to have full access, so the can read, write and execute: READ (4) + WRITE (2) + EXECUTE (1) = 7.
The result: 777 which would look like this in the shell/terminal: chmod 777 <yourfile>
Another example, which is one of the mote common ones on webservers, is that the owner has full access, but everybody else can only read and execute: READ (4) + EXECUTE (1) = 5. And for the owner it’s 7 again.
The result: 755 which would look like this in the shell/terminal: chmod 755 <yourfile>
You see, it’s not complicated to calculate the magic number for chmod.
Note when you’d like to change access right for a directory, including all the files and directories it holds, you’d need to add the “-R” option, for example: chmod -R 750 <yourdirectory>
Sometimes however, when looking at a directory listing from “ls -l”, my mind draws a blank when it comes to finding the matching number. This is another way I use my new calculator. I just keep clicking until the “ls” output looks like what the calculator says and I know what chmod value I’m looking at.
Ad Blocking Detected Please consider disabling your ad blocker for our website.
We rely on these ads to be able to run our website.
You can of course support us in other ways (see Support Us on the left).
chmod without the calculator
Now, experienced Linux users will probably tell me that there is an alternative way to use chmod. And there is. If you remember that.
For example, to add READ rights for the other users, to a given file: chmod o+r <yourfile>
You can find more in the man page of chmod (man chmod
) or on the Wiki page.
Other sources
There are numerous variants out there, so if you’re interested in the different JavaScript version,… check out the code by:
p.s. mine is not based on these codes, but I learned a lot from looking at their work.
Comments
There is only one comment, you can read it below.
You can post your own comments by using the form below, or reply to existing comments by using the "Reply" button.
For MacOS users;
if you want to read this value from a file (versus setting it), try this:
For example:
hans