LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-11-2006, 03:49 AM   #1
postiwala
LQ Newbie
 
Registered: Oct 2005
Posts: 18

Rep: Reputation: 0
find command is not working


Hi all,
I am trying to run a commnd

find ./ -name *.xml

sometimes this command works fine and sometimes it gives error and says
find: paths must precede expression
Usage: find [-H] [-L] [-P] [path...] [expression]

I am not able to understand the inconsitent behaviour.

my sole purpose is to run this commnad is to search *.xml in subdirectories and display it.

Thanks.
 
Old 09-11-2006, 03:50 AM   #2
w3bd3vil
Senior Member
 
Registered: Jun 2006
Location: Hyderabad, India
Distribution: Fedora
Posts: 1,191

Rep: Reputation: 49
either use a .(dot) or a slash, why do you want to use both

find / -name *.xml


find . -name *.xml
 
Old 09-11-2006, 03:51 AM   #3
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
try

find ./ -name "*.xml"

the quotes seem to make it work for me.
 
Old 09-11-2006, 03:56 AM   #4
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
as an aside, w3bd3vil, ./ and . are synonymous, whereas / is the root directory. doing
Code:
find ./ -name some_file
and
Code:
file . -name some_file
will, as far as I know, generate the same results. so . and ./ are both the current directory.

Last edited by pwc101; 09-11-2006 at 03:58 AM.
 
Old 09-11-2006, 04:00 AM   #5
zulfilee
Member
 
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430

Rep: Reputation: 39
For wildcard and case insensitive search use iname

fine . -iname "*.xml"
 
Old 09-11-2006, 05:00 AM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by pwc101
try

find ./ -name "*.xml"

the quotes seem to make it work for me.
And it's worth elaborating on that!

The reason is that *.xml (w/o quotes) gets globbed
by the shell before find gets the string. Therefore,
if there's a file with that extension in that directory
find will search for this one file (which is quite unlikely
to be the intention).

So, if there's ONE file with that extension, find will find
that one file. If there's more than one, find will fail, because
only the first returned glob will be used as a name -
the others are garbage to find:
Code:
find: paths must precede expression
Usage: find [path...] [expression]
is what you'll see.


Cheers,
Tink
 
Old 09-11-2006, 05:42 AM   #7
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
i did wonder why it needed the quotes; every day's a school day!
 
Old 09-11-2006, 01:25 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Indeed. Using Unix-like Operating Systems is much like brain-gym. I still
learn new things every day :} ... one of the reasons that I love it so much ;}


Cheers,
Tink
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 9 06-30-2016 05:30 PM
find command not working correctly? hak_uc Linux - General 10 05-30-2006 08:59 PM
find command DotHQ Red Hat 3 04-24-2006 06:02 AM
same find command not working in bash script, quotes? QuakerOatz Linux - Software 1 07-14-2003 12:04 PM
makeing Find command not case sensitive? -ilname isnt working. systemgsr Linux - General 2 12-25-2001 12:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration