UbuntuThis forum is for the discussion of Ubuntu Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello,
I'm not sure if I am posting on the right subsection because I am new to this community and also Linux in general. I am learning the find and grep command I have a question regarding placement of wildcards. When using a wildcard in find, I am to place the wildcard directly before and after (ex: find *txt). But when I am using grep, why do I place the wildcard after a space? (ex: grep .txt *)
Hi, and welcome here, at LQ
the command line arguments (what you add/append to the command) depends on the command you use, because the command itself will process that.
So you need to check man find to understand what find *txt means and man grep to know how grep uses those arguments.
For example the usual case: grep pattern file, so .txt is a pattern here.
Arguments are separated by a space (or more), so *txt and .txt * are two different things.
Additionally * can be evaluated by the shell (see globs), so *txt and * can be replaced before execution.
Arguments are separated by a space (or more), so *txt and .txt * are two different things.
Additionally * can be evaluated by the shell (see globs), so *txt and * can be replaced before execution.
1) To expand on that, no pun intended, "wildcards" in that context will either take effect in the shell and thus be globbing (see "man 7 glob") or take place in find as various flavors of regular expression aka "regex". So any special characters, like the asterisk *, which might get interpreted by the shell need to be enclosed in quotes to have the shell pass them intact to find.
find /home/cybernewbie/ -type f -name '*.txt' -print
find /home/cybernewbie/ -type f -name *.txt -print
In the latter, the shell interface gets hold of the asterisk first and tries to interpret it before passing it to find.
The same applies to grep, though the focus at any given time with it is on one of three flavors of regular expression: POSIX, Extended, or Perl-Compatible.
2) as for the different types of regular expression:
Thank you everyone who replied. I think I should really get myself more acquainted with the man page. It's intimidating but I think it will be really beneficial if I learn how to read and process the man pages.
Thank you!!
It's intimidating but I think it will be really beneficial if I learn how to read and process the man pages.
Definitely - being able to comprehend man pages isn't always as straight-forward as it should be, but is a useful skill to develop.
Also useful is skipping to the the "See Also" section to check if there's additional documentation: for example, grep has online + downloadable manuals which are both more thorough and easier to follow than the man page.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.