LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 11-11-2006, 06:02 PM   #1
chen666
LQ Newbie
 
Registered: Nov 2006
Posts: 3

Rep: Reputation: 0
Question Confused by command "find"


Hi, greetings from a newbie. I have been using Linux for 5 years, but not really good at anything

I am getting really confused by the command (GNU) find. Depending on the files existing in the current directory, "find" gave me different responses. Could anyone please give me a hint? I am using Debian, Sarge5. Thanks a lot!

-------------------
jchen:~/tmp$ ls -l
total 4
-rw-r--r-- 1 jchen jchen 13 2006-11-11 17:47 test.txt
-rw-r--r-- 1 jchen jchen 0 2006-11-11 17:41 test.txt~
jchen:~/tmp$
jchen:~/tmp$ find -name *test*
find: paths must precede expression
Usage: find [path...] [expression]
jchen:~/tmp$
jchen:~/tmp$ rm -f ./test.txt~
jchen:~/tmp$
jchen:~/tmp$ find -name *test*
./test.txt
jchen:~/tmp$
jchen:~/tmp$ touch ./test2.txt
jchen:~/tmp$
jchen:~/tmp$ find -name *test*
find: paths must precede expression
Usage: find [path...] [expression]
jchen:~/tmp$
 
Old 11-11-2006, 06:11 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
yeah that caught me for a long time too... essnetially the *'s are doing filename expansion in the shell, so it just screws up the logic of what you're trying to do. put single quotes around that *test* and it should work as you'd expect it to do, as find itself will use the *'s not the underlying bash process.
 
Old 11-11-2006, 06:22 PM   #3
dxqcanada
Member
 
Registered: Sep 2006
Location: Canada
Distribution: Gentoo
Posts: 702

Rep: Reputation: 43
-name pattern

man page says to enclose the peattern in quotes in order to protect if from expansion by the shell

Code:
find -name "*test*"
 
Old 11-11-2006, 06:27 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Just because I try to be explicit about everything, I generally do
Code:
find ./ -name "*test*"
But, sometimes I want to do
Code:
find /some/directory/of/interest -name "*fub*"
And to clarify, in case acid_kewpie's answer didn't make complete sense to you, the difference between *test* and "*test*" is what ends up being seen by find. Without the quotes, bash (or whatever shell, generally) will expand "*test*" into a whole list of matching files, and hands them to find. Find only knows how to deal with one filespec, and complains or does something unexpected. By putting the quotes on your filespec, bash just hands the string '*test*' to find. find sees it as a single argument, and recognizes that it must do the wildcard expansion.

This is a subtle point that many people don't immediately grasp, and once understood can help make sense out of a lot that previously did not.

--- rod
 
Old 11-11-2006, 06:43 PM   #5
chen666
LQ Newbie
 
Registered: Nov 2006
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks a lot, guys! Learned more than what I asked. Should be coming here more later on
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
giving search-string(s) from a file to linux "find" command Fond_of_Opensource Linux - Newbie 3 02-02-2009 07:14 PM
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 08:42 AM
A regularly executing "find" command without my intention freaks me simber Linux - Newbie 2 05-21-2006 11:29 AM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 03:32 PM
Help,I can't find my USB mouse when I run "kudzu" command in RH9. aeolus Red Hat 0 03-27-2004 10:14 PM


All times are GMT -5. The time now is 06:34 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration