1

The terms "file permission" and "file mode" are often used interchangeably. However, some tools exclusively use one term or the other. Interestingly, the venerable chmod tool specifically refers to "file mode".

Is there a technical or historical difference between them?

muru
  • 72,889
lonix
  • 1,723
  • 1
    I don't know if "permission" has a technical definition, but I'd think that setuid/setgid/sticky bits are not actually part of a file's permissions, even though they are a part of the mode. – muru Jun 09 '23 at 03:51
  • I don't think it warrants an answer but mode is the value that's stored, traditionally in the i-node, permissions are how that mode is interpreted to grant/deny access, so they represent two distinct aspects of the operation. – chexum Jun 19 '23 at 15:42

2 Answers2

2

Technically it depends on how you define file permissions. A files mode is one of the data points found in the stat structure. The mode lower 12 bits are the user, group, and other RWX permission triplets along with a setuid, setgid, and sticky bit. Mask away those lower bits and the value remaining is the file's type of which block, character, directory, FIFO, socket, symlink, and regular file are the only standard defined types. So the file's mode could be described as the Unix discretionary access control file permissions, the setguid and sticky bits, and the file type.

However file permissions have been extended since the original Unix file permissions to include ACL's, Extended Attribute file permissions, and mandatory access control schemes like SELinux and AppArmor.

ilkkachu
  • 138,973
2

“Mode” is defined as

A collection of attributes that specifies a file's type and its access permissions.

They aren’t interchangeable, a file’s mode is more than its permissions.

A file’s mode can be retrieved using stat, and the various values extracted using macros defined in sys/stat.h.

See Understanding UNIX permissions and file types for more details on file types and permissions.

Stephen Kitt
  • 434,908
  • 1
    but of course chmod can only change the permissions part of the mode (incl. setuid/setgid/sticky), so maybe it'be better called chperm instead... – ilkkachu Jun 09 '23 at 08:56
  • @ilkkachu I wouldn't be surprised if in very early stages, chmod was actually used to change files into directories. For one, I remember reading that mkdir(1) was responsible for creating the . and .. entries in the new directory, and not the kernel. – chexum Jun 19 '23 at 15:58