0

The man pages state that:

-perm -mode means that all of the permission bits in mode are set for the file.

-perm /mode means that any of the permission bits in mode are set for the file.

When I created two directories in /tmp with permissions 1777 and 1755, and used these commands, both directories were found with both 1777 and 1755 permissions.

find / -perm -1000 -type d

find / -perm /1000 -type d

This is why I'm confused. I'm using CentOS 7 as my distribution.

Z0OM
  • 1
  • 4
  • 24
  • 56
achhainsan
  • 323
  • 10

1 Answers1

3

octal 8#1000 is binary 2#1_000_000_000, it only has one bit set, the sticky bit, so all or any make no difference.

/tmp has all of that one bit set, and has any of that one bit set.

You'd see a difference for values that have at least 2 bits set such as in -perm -5000 vs -perm /5000 (8#5000 being 2#101_000_000_000 with 2 bits set) where the former returns files that have both the setuid and sticky bit set and the latter has either of them (or both) set.

You use typically / for things like -perm /111 (is executable by someone) -perm /444 (is readable by someone) or -perm /6000 (either setuid or setgid, i.e. dangerous) and - for things like -perm -111 (is executable by everyone), -perm -600 (is both readable and writable by its owner) often negated (! -perm -... -exec chmod ...+... {} +).

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
  • What does 8#1000 means? Your answer wasn't very clear to me, can you clarify? – achhainsan Jun 27 '23 at 08:20
  • What's the correct command to find files 1) With sticky bit set, regardless of other permissions? eg find both 1777 and 1755 files. 2) With sticky bit set as well as other permissions be exact? eg find only 1777 file. – achhainsan Jun 27 '23 at 08:25
  • `base#digits` is one way to represent numbers in arbitrary bases. That's used for instance in the arithmetic expressions of Korn-like shells including bash. You might have come across some other notations such as `01000` or `0o1000` for octal (base 8, `8#1000`) or `0b1010` for binary (base 2, 2#1010) or 0xdead for hexadecimal (base 16, 16#dead). – Stéphane Chazelas Jun 27 '23 at 08:31
  • @achhainsan does the answer not make it clear how to find files whose permissions have at least the sticky bit set? To find only 1777, use `-perm 1777`. Try `man find` or `info -- find -perm` for details. – Stéphane Chazelas Jun 27 '23 at 08:35
  • sorry if I come across as rude, but it isn't clear to me. – achhainsan Jun 27 '23 at 08:38