Fd: support size filter option

Created on 2 Apr 2018  路  11Comments  路  Source: sharkdp/fd

find supports the -size filter, could fd do that too?

feature-request help wanted

Most helpful comment

Closed via #286. Thank you very much, @stevepentland.

All 11 comments

Thank you for your feedback!

Filtering by file size is something that I would consider not to be part of the "80% of the use cases" (see README). If we decide to include this (and related tickets #165 and #273), I guess we have to re-consider that statement at some point :smile:.

Before we move forward with this, I would like to discuss a clear strategy on how to implement this. In particular, I would like to know which kind of syntax we would use for file-size filtering.

For the syntax I'd suggest something as:
-S >9M (larger than 9 GiB) or -S <5G (smaller than 5 MiB)

And for ranges:
-S 100k-2M (larger than 100 KiB, but smaller than 2 MiB)

It should accept both capital and non-capital k for kilobytes (1k / 1K), even if the capital variant is actually not accurate (captial letters only start from Mega). The only problem this might cause is that the > character might interfere with the bash syntax.

Thank you for the feedback!

The only problem this might cause is that the > character might interfere with the bash syntax.

Exactly. fd -S >9M would be parsed as "pipe the output of fd -S into the file named 9M. This would mean that users would have to remember to quote the arguments (fd -S '>9M'), which makes this less appealing.

Maybe we could introduce two arguments (--larger-than, --smaller-than or --size-larger, --size-smaller)? They could act in a AND-fashion, such that ranges could be specified via --larger-than 100k --smaller-than 2M.

Maybe we could introduce two arguments (--larger-than, --smaller-than or --size-larger, --size-smaller)? They could act in a AND-fashion, such that ranges could be specified via --larger-than 100k --smaller-than 2M.

That seems pretty reasonable. I was going to suggest following the same syntax as find has, where you use a + or - prefix to indicate larger or smaller, but I like that this reads better and is composable. My question here is that does this include the equal-to case? I'd expect that there is little need for both a --larger-than and a --larger-or-equal-to argument,

Actually, I'd be interested in some real world use cases for the usage of the size option. I don't think I have ever used find -size for anything other than searching for large files.

I actually just did it recently to delete all small files from a backup directory I had. There were a ton of small hidden files created by various programs and so I looked for all files under 100KiB. I went to use fd first but it didn't support this feature so I had to use find instead.

Maybe we could introduce two arguments (--larger-than, --smaller-than or --size-larger, --size-smaller)? They could act in a AND-fashion, such that ranges could be specified via --larger-than 100k --smaller-than 2M.

With find we'd do like this to search files between 10 MB and 15 MB:

find -type f -size +10M -size -15M

I think that looks better.

@sharkdp I'd like to take this one if it is to be included. It seems the most straightforward idea may be to use an adapted version of the same notation as find with --size +N and --size -N. With number_of_values and allow_hyphen_values from clap, we should be able to accommodate the minus sign without any real extra effort. And we just need to document that + indicates > and - indicates < to obtain a fairly easy-to-understand filtering capability.

@stevepentland Okay - sounds good. Thanks!

Closed via #286. Thank you very much, @stevepentland.

Released in v7.1.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ariecattan picture ariecattan  路  3Comments

runiq picture runiq  路  3Comments

codyro picture codyro  路  4Comments

blueray453 picture blueray453  路  3Comments

Dietr1ch picture Dietr1ch  路  3Comments