Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

class method

File.sticky?

(::path | ::IO file_name) -> bool
File.sticky?(object) → true or false

Returns whether the sticky bit is set in the special bits for the given object, which may be a path or an IO object:

Example
filepath = '/tmp/t.tmp'
File.write(filepath, 'foo')
mode = File.stat(filepath).mode.to_s(8) # => "100664"
File.sticky?(filepath)                  # => false
File.chmod(01644, filepath)             # Set sticky bit.
mode = File.stat(filepath).mode.to_s(8) # => "101644"
File.sticky?(filepath)                  # => true
File.delete(filepath)                   # Clean up.
File.sticky?($stdin)                    # => false
File.sticky?('nosuch')                  # => false

Returns false on Windows.

See also .stat .symlink .split .symlink? also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0