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

Allow for exact find #157

Closed
niladam opened this issue Oct 31, 2017 · 10 comments
Closed

Allow for exact find #157

niladam opened this issue Oct 31, 2017 · 10 comments

Comments

@niladam
Copy link

niladam commented Oct 31, 2017

First of all thank you for this. It's really fast and i'm already loving it!:)

I think fd should allow for exact find probably using some flag. A use case i can use to explain is when searching for error_log files.

Using fd error_log returns:

/some/folder/open_basedir_error_log.phpt
/another/folder/open_basedir_error_log_variation.phpt
/new/folder/name/random_string_before_error_log.old
/new/folder/name/random_string_before_error_log.temp
/new/folder/name/jibberish_error_log_readme_first.txt

You can see how for example you can't use xargs to delete as you might delete files that are actually in use by something else.

Thanks.

@sharkdp
Copy link
Owner

sharkdp commented Nov 1, 2017

First of all thank you for this. It's really fast and i'm already loving it!:)

Thank you for the feedback!

I think fd should allow for exact find probably using some flag. A use case i can use to explain is when searching for error_log files.

Note that the search pattern in fd is always a regular expression, so in a situation like this, I just use:

> fd '^error_log$'

What do you think?

@matematikaadit
Copy link
Contributor

matematikaadit commented Nov 9, 2017

for comparison, ripgrep has -F or --fixed-strings flag to treat the pattern as a literal string instead of regular expression. When this flag is used, the special regular expression meta characters such as (){}*+. do not need to be escaped.

There's also -g, --glob <GLOB>... to include/exclude files for searching in ripgrep. It's using glob pattern instead of regular expression. You can do exact file name matching using this.

@sharkdp
Copy link
Owner

sharkdp commented Nov 10, 2017

Agreed, -F/--fixed-strings sounds like a useful addition.

Concerning --glob: @iology implemented a version of this in his fork here: https://github.com/jakwings/ff-find

@niladam
Copy link
Author

niladam commented Nov 10, 2017

Note that the search pattern in fd is always a regular expression, so in a situation like this, I just use:

fd '^error_log$'

I think your option is clever enough. However, while i had to open an issue for this (after reading the help and other issues) i wonder if this won't happen in the future. While providing a new flag to use this might seem a little more work -- i think in the long run it'll just be more easier to use and discover this..

@jakwings
Copy link
Contributor

About the pros and cons of a glob pattern compared to a fixed string: The special chars * ? { } \ in glob patterns are seldom used in pathnames (except [ ]). Other than this glob patterns are more powerful than fixed strings while still safer to use than regex patterns.

One biggest problem of fd and my ff is that it does not warn users about the magic of regex. (I'll suggest people to use --glob and make it the default.)

For better interactive experience I would suggest fzf. 😉

@ChengCat
Copy link

I don't think searching for a fixed string is worth adding an extra option here. It is easier to memorize that fd always search by regex, and that ^xxx$ means an exact string in regex, than to memorize an extra option.

@matematikaadit
Copy link
Contributor

Just to clarify, fixed string in this context isn't equal to exact find. Fixed string just means a regular searching without treating regex meta character as special.

@ChengCat
Copy link

ChengCat commented Nov 28, 2017

Thanks for the clarification.

for comparison, ripgrep has -F or --fixed-strings flag to treat the pattern as a literal string instead of regular expression. When this flag is used, the special regular expression meta characters such as (){}*+. do not need to be escaped.

However, do we actually use (){}* in file names? The only useful characters seem to be .[]. I am not sure whether this is worth introducing an extra kind of pattern.

This flag is much more useful for ripgrep, since it searches file contents, rather than file names.

@ghuls
Copy link

ghuls commented Nov 28, 2017

At least () is used quite often. For example if you download and save a file with the same filename in Firefox, you get:

file.txt
file(1).txt
file(2).txt

@sharkdp
Copy link
Owner

sharkdp commented Feb 10, 2018

Fix released in v6.3.0

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

6 participants