Junior — Middle
How are permissions for a file or folder changed in Linux?
sobes.tech AI
Answer from AI
In Linux, changing permissions for a file or folder is done using the chmod command or the chmod() system call.
Permissions are represented by three groups: owner, group, and others, each of which can have read (r), write (w), and execute (x) rights.
Example in Node.js using the fs module:
const fs = require('fs');
// Set file permissions to rw-r--r-- (644)
fs.chmod('example.txt', 0o644, (err) => {
if (err) throw err;
console.log('Permissions changed');
});
Here, 0o644 is an octal representation of the permissions, where:
- 6 (110) — read and write for the owner
- 4 (100) — read for the group
- 4 (100) — read for others
Thus, changing permissions involves setting access bits that determine who can perform what operations on a file or folder.