Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support size filter option #276

Closed
yifeikong opened this issue Apr 1, 2018 · 13 comments
Closed

support size filter option #276

yifeikong opened this issue Apr 1, 2018 · 13 comments

Comments

@yifeikong
Copy link

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

@sharkdp
Copy link
Owner

sharkdp commented Apr 3, 2018

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 😄.

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.

@lnjX
Copy link

lnjX commented Apr 14, 2018

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.

@sharkdp
Copy link
Owner

sharkdp commented Apr 14, 2018

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.

@Susurrus
Copy link

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,

@sharkdp
Copy link
Owner

sharkdp commented Apr 14, 2018

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.

@Susurrus
Copy link

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.

@guihkx
Copy link

guihkx commented Apr 17, 2018

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.

@stevepentland
Copy link
Contributor

@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.

@sharkdp
Copy link
Owner

sharkdp commented Apr 22, 2018

@stevepentland Okay - sounds good. Thanks!

@sharkdp
Copy link
Owner

sharkdp commented Apr 25, 2018

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

@sharkdp sharkdp closed this as completed Apr 25, 2018
@sharkdp sharkdp added this to the v7.1.0 milestone Aug 19, 2018
@sharkdp
Copy link
Owner

sharkdp commented Aug 19, 2018

Released in v7.1.0

@gMan1990
Copy link

gMan1990 commented Feb 2, 2021

@sharkdp how to find only equal size, not greater and less?

@sharkdp
Copy link
Owner

sharkdp commented Feb 13, 2021

See #696

This is supported in fd v8.2.1:

▶ fd --size=1079b
LICENSE-MIT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants