We have --max-depth option, but there is no --min-depth counterpart. It could be used exactly like it's been used with find.
Thank you for the feedback.
Please see my comment in #390.
Thank you for fast reply.
My usecase is pretty simple, I use fd to generate input for shell functions, which help to apply some action (edit, cd, select) to the target. I found it handy to have two modes of such functions, the first one applies only to files (directories) in the current directory, and the second one applies to all the files (directories) under the current PWD. I have easily implemented the first mode, supplying --max-depth 1 to fd. But with the second mode there is an inconvenience, because I'd like to exclude the files (directories) of PWD from the result output.
That's where --min-depth 1 would do exactly what I need, list all the items under the PWD, but excluding the immediate children.
As you can see, for me it would suffice to have something like --min-depth-1 only, but I think a more generic option would be better.
find -mindepth 1 only excludes entries with depth 0, i.e. the current directory (.). fd does this by default. I guess what you really want is -mindepth 2.
-mindepth 2 can be simulated in fd by supplying all directories in the current directory as search paths:
fd … */
Similarly, -mindepth 3 can be simulated via:
fd … */*/
Agreed, it's not as pretty as -mindepth, but that should work (if the argument list is not exceedingly large).
*/
I didn't think about that. It will take some additional checks and handlers, but I'll figure it out, I guess.
Thank you.
Hey! I have a case where I want to do --min-depth 6 --max-depth 6, i.e. only list directories at a certain depth. If I do /base/path/*/*/*/*, I get this error:
$ fd-v7.5.0-x86_64-unknown-linux-gnu/fd . /base/path/*/*/*/* --type d --max-depth 6 --change-older-than 1h
-bash: fd-v7.5.0-x86_64-unknown-linux-gnu/fd: Argument list too long
To try to get around bash glob expansion, I used single quotes, but get another error:
$ fd-v7.5.0-x86_64-unknown-linux-gnu/fd . '/base/path/*/*/*/*' --type d --max-depth 6 --change-older-than 1h
[fd error]: '/base/path/*/*/*/*' is not a directory.
Unless I'm missing something, this might be a good motivation for including the --min-depth flag in fd. Sometimes the argument list is too long!
I was about to write that you could use fds new -g/--glob option in combination with -p/--full-path (match the pattern on the full path, not just the basename):
fd -pg '/base/path/*/*/*/*'
but that doesn't actually work, because * currently matches directory separators as well. So you would --max-depth 6 in addition.
I think behavior is actually surprising and we should probably change this. We still have ** to match to arbitrary depths. This fix would be easy (https://docs.rs/globset/0.4.5/globset/struct.GlobBuilder.html#method.literal_separator).
That said, I kind of agree that --min-depth would be a natural addition. The glob-workaround is neither pretty nor will users likely come up with this. So let's add --min-depth <depth> and --exact-depth <depth>. They could be hidden from the short -h help text.
@sharkdp Thank you for thinking about my use case and considering incorporating it into your project. I agree the glob workaround isn't very intuitive, so the --min-depth helps there as well. Your addition of --exact-depth as an alias for --min-depth <depth> --max-depth <depth> further makes my use case more readable and intuitive! I'm excited to give this a spin.
Thank you for the feedback!
Closed via #568 and #569.
This has now been released in fd v8.0.
Most helpful comment
This has now been released in fd v8.0.