summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--findutils/Config.in7
-rw-r--r--findutils/find.c26
-rw-r--r--include/usage.h9
3 files changed, 36 insertions, 6 deletions
diff --git a/findutils/Config.in b/findutils/Config.in
index f274ad1c6..8582d6446 100644
--- a/findutils/Config.in
+++ b/findutils/Config.in
@@ -171,6 +171,13 @@ config FEATURE_FIND_CONTEXT
help
Support the 'find -context' option for matching security context.
+config FEATURE_FIND_LINKS
+ bool "Enable -links: link count matching"
+ default n
+ depends on FIND
+ help
+ Support the 'find -links' option for matching number of links.
+
config GREP
bool "grep"
default n
diff --git a/findutils/find.c b/findutils/find.c
index 1b2466816..f0c259833 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -96,6 +96,7 @@ IF_FEATURE_FIND_PRUNE( ACTS(prune))
IF_FEATURE_FIND_DELETE( ACTS(delete))
IF_FEATURE_FIND_EXEC( ACTS(exec, char **exec_argv; unsigned *subst_count; int exec_argc;))
IF_FEATURE_FIND_GROUP( ACTS(group, gid_t gid;))
+IF_FEATURE_FIND_LINKS( ACTS(links, char links_char; int links_count;))
struct globals {
IF_FEATURE_FIND_XDEV(dev_t *xdev_dev;)
@@ -175,7 +176,7 @@ static int exec_actions(action ***appp, const char *fileName, const struct stat
* On return, bit is restored. */
cur_group = -1;
- while ((app = appp[++cur_group])) {
+ while ((app = appp[++cur_group]) != NULL) {
rc &= ~TRUE; /* 'success' so far, clear TRUE bit */
cur_action = -1;
while (1) {
@@ -390,7 +391,16 @@ ACTF(context)
return rc == 0;
}
#endif
-
+#if ENABLE_FEATURE_FIND_LINKS
+ACTF(links)
+{
+ switch(ap->links_char) {
+ case '-' : return (statbuf->st_nlink < ap->links_count);
+ case '+' : return (statbuf->st_nlink > ap->links_count);
+ default: return (statbuf->st_nlink == ap->links_count);
+ }
+}
+#endif
static int FAST_FUNC fileAction(const char *fileName,
struct stat *statbuf,
@@ -463,7 +473,7 @@ static int find_type(const char *type)
#if ENABLE_FEATURE_FIND_PERM \
|| ENABLE_FEATURE_FIND_MTIME || ENABLE_FEATURE_FIND_MMIN \
- || ENABLE_FEATURE_FIND_SIZE
+ || ENABLE_FEATURE_FIND_SIZE || ENABLE_FEATURE_FIND_LINKS
static const char* plus_minus_num(const char* str)
{
if (*str == '-' || *str == '+')
@@ -505,6 +515,7 @@ static action*** parse_params(char **argv)
IF_FEATURE_FIND_GROUP( PARM_group ,)
IF_FEATURE_FIND_SIZE( PARM_size ,)
IF_FEATURE_FIND_CONTEXT(PARM_context ,)
+ IF_FEATURE_FIND_LINKS( PARM_links ,)
};
static const char params[] ALIGN1 =
@@ -538,6 +549,7 @@ static action*** parse_params(char **argv)
IF_FEATURE_FIND_GROUP( "-group\0" )
IF_FEATURE_FIND_SIZE( "-size\0" )
IF_FEATURE_FIND_CONTEXT("-context\0")
+ IF_FEATURE_FIND_LINKS( "-links\0" )
;
action*** appp;
@@ -823,6 +835,14 @@ static action*** parse_params(char **argv)
bb_simple_perror_msg(arg1);
}
#endif
+#if ENABLE_FEATURE_FIND_LINKS
+ else if (parm == PARM_links) {
+ action_links *ap;
+ ap = ALLOC_ACTION(links);
+ ap->links_char = arg1[0];
+ ap->links_count = xatoul(plus_minus_num(arg1));
+ }
+#endif
else {
bb_error_msg("unrecognized: %s", arg);
bb_show_usage();
diff --git a/include/usage.h b/include/usage.h
index eab57d8ae..4254e153c 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -1232,13 +1232,13 @@
"\n -type X File type is X (X is one of: f,d,l,b,c,...)") \
IF_FEATURE_FIND_PERM( \
"\n -perm NNN Permissions match any of (+NNN), all of (-NNN)," \
- "\n or exactly (NNN)") \
+ "\n or exactly NNN") \
IF_FEATURE_FIND_MTIME( \
"\n -mtime DAYS Modified time is greater than (+N), less than (-N)," \
- "\n or exactly (N) days") \
+ "\n or exactly N days") \
IF_FEATURE_FIND_MMIN( \
"\n -mmin MINS Modified time is greater than (+N), less than (-N)," \
- "\n or exactly (N) minutes") \
+ "\n or exactly N minutes") \
IF_FEATURE_FIND_NEWER( \
"\n -newer FILE Modified time is more recent than FILE's") \
IF_FEATURE_FIND_INUM( \
@@ -1252,6 +1252,9 @@
IF_FEATURE_FIND_SIZE( \
"\n -size N[bck] File size is N (c:bytes,k:kbytes,b:512 bytes(def.))." \
"\n +/-N: file size is bigger/smaller than N") \
+ IF_FEATURE_FIND_LINKS( \
+ "\n -links N Number of links is greater than (+N), less than (-N)," \
+ "\n or exactly N") \
"\n -print Print (default and assumed)" \
IF_FEATURE_FIND_PRINT0( \
"\n -print0 Delimit output with null characters rather than" \