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$ |
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.
|
-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*" |
Just because I try to be explicit about everything, I generally do
Code:
find ./ -name "*test*" Code:
find /some/directory/of/interest -name "*fub*" 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 |
Thanks a lot, guys! Learned more than what I asked. Should be coming here more later on :)
|
All times are GMT -5. The time now is 09:10 AM. |