Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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 have a very simple question but I cannot get much use put of the --help or man files!(too damm-many brackets [[]] 2 confusing to noob)..
1- Is find command case sensitive? Like if I am looking for a file Foo can I type find -name foo or do I have to say Foo?
2-Can I use wild-card or * in my find?
for instance I want to find foo but I say:
find -name fo*
can it read the * as a "dont care" statement?
Linux (and all Unix-like systems) are typically case-sensitive.
In man pages, those brackets are there for a reason---once you get used to it, you'll find it helpful.
In Bash, the "*" is normally a wildcard. In certain commands which use regular expressions, it has a different meaning. The man page (sorry) will tell you all the details.
In find, it's a wildcard, but I've discovered I often need to to this: (Suppose I am looking in /usr/lib for a filename containing "foo")
find /usr/lib -name "*foo*"
I'm not totally clear on why the quotes are needed, but it works.
I recommend reading the Bash Guide for Beginners (free at http://tldp.org)
I'm not totally clear on why the quotes are needed, but it works.
Well I can quote you the reason I gave you in an earlier thread. I'm pretty sure this is correct, was it not entirely clear?
Quote:
Originally Posted by openSauce
Without quotes, the shell expands *foo* to either:
all files in the current directory with "foo" in the name
or the literal string *foo* if no such files exist.
It then passes the result to find. The latter is what you want, and you can force the shell not to expand the *'s by using quotes.
Matey: use -iname rather than -name for a case insensitive search.
e.g.
Code:
find /home/user -iname "*foo*"
will find all files in your home dir with "foo" (case-insensitive) somewhere in the name.
I seem to remember there's a good article or two on linux-mag.com on using find, but the site seems to be down at the mo so I can't find it and link to it.
Well I can quote you the reason I gave you in an earlier thread. I'm pretty sure this is correct, was it not entirely clear?
Without quotes, the shell expands *foo* to either:
* all files in the current directory with "foo" in the name
* or the literal string *foo* if no such files exist.
It then passes the result to find. The latter is what you want, and you can force the shell not to expand the *'s by using quotes.
Not remembering this from you---but no matter.
I think you've just cleared a mystery for me.....Much of the time, find works just fine without quotes. If I read you correctly......it works like this:
If the string after -name is not in the current directory, then the command works OK.
If there is anything in the current directory containing the search string, then it is passed to the find command.
Suppose there are 2 files containing the search string---they'll get passed in a list with a newline, n'est-ce pas? THEN what does find do??
All this aside, THANK YOU for pointing out what is happening.
iirc, you use single quotes ( '*foo*' ) so that they are interpreted by the find cmd itself, not the current shell, otherwise you could get 'too many args ...' error.
I think you've just cleared a mystery for me.....Much of the time, find works just fine without quotes. If I read you correctly......it works like this:
If the string after -name is not in the current directory, then the command works OK.
If there is anything in the current directory containing the search string, then it is passed to the find command.
Suppose there are 2 files containing the search string---they'll get passed in a list with a newline, n'est-ce pas? THEN what does find do??
All this aside, THANK YOU for pointing out what is happening.
If there is more than one match for an entry like -name cmd*
That will expand the command to `-name cmd001 cmd002, ...' . This will cause an error. It's not the same as `-name cmd001 -name cmd002' which would be OK.
If there is only one match, then the cmd* will be expanded to a literal which would not cause a problem.
You could have
find */ -name "aname*"
Which would expand to something like:
find dir1/ dir2/ dir3/ -name "aname*"
This would be OK. You can explicitly have move then one directory in your find command. For example:
$ find /bin /usr/bin /usr/local/bin -name "ffplay*"
/usr/local/bin/ffplay
This can be a lot easier than trying to prune directories from a search.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.