LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-05-2014, 04:02 AM   #1
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
find command -- sometimes error, sometimes not


Hi,

when I execute this command
Code:
markus@slackvm:~$ find /home/markus/ -name *.pdf
find: paths must precede expression: find.pdf
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
I get an errormessage (obviously). But when I execute it for example as root:
Code:
slackvm:~# find /home/markus/ -name *.pdf
/home/markus/Praes/authent.pdf
/home/markus/signal.pdf
/home/markus/groff_out.pdf
 ....
it works.

Normally I would use -name "*.pdf" when searching with a wildcard, but now I found out that it sometimes works without the "".
I know that it would also work with -name \*.pdf and suppose that the shell will normally expand the *.

Can anyone explain this behaviour? why does it sometimes work and sometimes not. What exactly does the shell do in this cases?

Thanks in advance

Markus
 
Old 02-05-2014, 04:08 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
shell tries to understand and evaluate the string *.pdf. If shell could find something, it will be replaced. If not, shell will leave it as it was - and find can use it. Using \ or " will avoid shell evaluation.
 
1 members found this post helpful.
Old 02-05-2014, 04:12 AM   #3
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Original Poster
Rep: Reputation: Disabled
Thanks to pan64, that's the solution.

The shell looks within the directory where the command is executed for *.pdf, since in /root/ there are no pdf-files, it executes the find command as it is. When I change as root to /home/markus/ I get the error because there are pdf files.

Markus

Last edited by markush; 02-05-2014 at 05:23 AM.
 
  


Reply

Tags
find command, shell



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux FIle System Error while running find command farhanzahidi Linux - General 3 10-20-2012 02:54 PM
find command give error file not found vishesh Linux - Newbie 5 05-28-2011 08:17 AM
Find command with standard error output and mail error file montblanc Programming 2 11-11-2010 09:06 PM
Find/grep/wc command to find matching files, print filename and word count dbasch Linux - Newbie 10 09-14-2009 05:55 PM
linux command error message bash: /usr/bin/find: No such file or directory sundaram123 Linux - General 8 04-02-2002 07:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:51 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