diff --git a/Base/usr/share/man/man1/find.md b/Base/usr/share/man/man1/find.md index 4f29f0ee36e..acb65e084c0 100644 --- a/Base/usr/share/man/man1/find.md +++ b/Base/usr/share/man/man1/find.md @@ -76,6 +76,8 @@ by the current user. the specified reference file. If `file` is a symbolic link and the `-L` option is in use, then the creation time of the file pointed to by the symbolic link is used. +* `-gid [-|+]number`: Checks if the file is owned by a group with an ID less + than, greater than or exactly `number`. * `-print`: Outputs the file path, followed by a newline. Always evaluates to true. * `-print0`: Outputs the file path, followed by a zero byte. Always evaluates to diff --git a/Userland/Utilities/find.cpp b/Userland/Utilities/find.cpp index a94050cf717..8746c1ea922 100644 --- a/Userland/Utilities/find.cpp +++ b/Userland/Utilities/find.cpp @@ -494,6 +494,26 @@ private: TimestampType m_timestamp_type { TimestampType::LastModification }; }; +class GidCommand final : public StatCommand { +public: + GidCommand(char const* arg) + { + auto gid_or_error = NumericRange::parse({ arg, strlen(arg) }); + if (gid_or_error.is_error()) + fatal_error("find: Invalid argument '{}' to '-gid'", arg); + + m_gid_range = gid_or_error.release_value(); + } + +private: + virtual bool evaluate(struct stat const& stat) const override + { + return m_gid_range.contains(stat.st_gid); + } + + NumericRange m_gid_range; +}; + class PrintCommand final : public Command { public: PrintCommand(char terminator = '\n') @@ -713,6 +733,10 @@ static OwnPtr parse_simple_command(Vector& args) if (args.is_empty()) fatal_error("-cnewer: requires additional arguments"); return make(args.take_first(), NewerCommand::TimestampType::Creation); + } else if (arg == "-gid") { + if (args.is_empty()) + fatal_error("-gid: requires additional arguments"); + return make(args.take_first()); } else if (arg == "-print") { g_have_seen_action_command = true; return make();