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


  Search this Thread
Old 11-11-2006, 05:02 PM   #1
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$ find -name *test*
find: paths must precede expression
Usage: find [path...] [expression]
jchen:~/tmp$ rm -f ./test.txt~
jchen:~/tmp$ find -name *test*
jchen:~/tmp$ touch ./test2.txt
jchen:~/tmp$ find -name *test*
find: paths must precede expression
Usage: find [path...] [expression]
Old 11-11-2006, 05:11 PM   #2
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975
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, 05:22 PM   #3
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

find -name "*test*"
Old 11-11-2006, 05:27 PM   #4
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,397
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
find ./ -name "*test*"
But, sometimes I want to do
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, 05:43 PM   #5
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


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

All times are GMT -5. The time now is 02:18 PM.

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