LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Find question ? How to use wild cards with arguments ? (https://www.linuxquestions.org/questions/linux-newbie-8/find-question-how-to-use-wild-cards-with-arguments-4175443098/)

.product 12-27-2012 06:18 AM

Find question ? How to use wild cards with arguments ?
 
Hi,
There exist ~/docs/office/report.txt
why does following command fails to get it.
~>find ./ -name report*

where as if i give the full name report.txt it works ! Any ideas Why ?

Thanks,

markush 12-27-2012 06:27 AM

Hi,

on my system it works
Code:

markus@samsung:~$ find ./ -name report*
./test/report.txt

which shell and which version of find are you using?

btw: you should try "report*" instead.

Markus

.product 12-27-2012 06:34 AM

Thanks for the quick response using "report*" worked !
I am noob and have few more questions.
why "" works ?
I am using tcsh how do i find the version of it ?

markush 12-27-2012 06:36 AM

Well, I'm using Bash, but I also (sometimes) had issues when using wildcard without "", I don't know why.

If you want to know the version of tcsh use the command
Code:

tcsh --version
which works for most commandlineprgrams.

Markus

.product 12-27-2012 06:46 AM

%> man find
SYNOPSIS
find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression]

Could it be that last option is expression and "" might be required to evaluate input as string ?

Thanks,

markush 12-27-2012 07:06 AM

No, I don't think so. The word expression in the find manpage is used with several meanings, don't be confused. I would recommend that you read the manpage for find and afterwards read here http://rute.2038bug.com/node7.html.g...00000000000000 and here http://content.hccfl.edu/pollock/unix/findcmd.htm

Markus

rknichols 12-27-2012 02:43 PM

Quote:

Originally Posted by .product (Post 4857633)
Hi,
There exist ~/docs/office/report.txt
why does following command fails to get it.
~>find ./ -name report*

where as if i give the full name report.txt it works !

When an argument to a command uses a shell meta-character, like '*', you should always quote that argument to protect it from being evaluated by the shell. In this case, the shell will try to expand that argument in the current directory, and if anything matches then the result of that expansion is what gets passed to find. If the current directory happened to contain a file named "reporters", then the command that is actually executed would be
Code:

find ./ -name reporters
and that is not going to match a file named "report.txt".

Now if someone tries your command line when there is not any matching file in the current directory, then the argument gets passed unaltered and find does what was expected.

Incidentally, if the pattern happens to match more and one name in the current directory, then all of those names will be included in the find command, and the result is the rather confusing error message, "find: paths must precede expression: ...".

.product 12-28-2012 03:20 AM

Thanks folks. Very helpful :)


All times are GMT -5. The time now is 12:53 PM.