LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Find not searching subdirectories (https://www.linuxquestions.org/questions/linux-software-2/find-not-searching-subdirectories-819431/)

JosephS 07-12-2010 11:44 AM

Find not searching subdirectories
 
I tried searching for files in documents:
joe@Debian:~/documents$ find -iname *.odt
./canadian-public-holidays.odt

I then moved to the work_search directory which is located in documents:
cd work_search
joe@Debian:~/documents/work_search$

joe@Debian:~/documents/work_search$ find -iname *.odt

Find finds more .odt files in the subdirectories.
./search/applications/sent/2009/7.13.bindery/2009.07.13.asap-print-depot-attach.odt
./search/applications/sent/2009/7.13.bindery/2009.07.13.all-canadian-printing-attach.odt
./search/applications/sent/2009/7.13.bindery/2009.07.13.signature-press-attach.odt
./search/applications/sent/2009/7.13.bindery/2009.07.13.octavia+co-press-attach.odt
./search/applications/sent/2009/7.13.bindery/2009.07.13.central-web-calgary-atttach.odt
./search/applications/sent/2009/7.13.bindery/2009.07.13.apache-superior-printing-attach.odt
./search/applications/sent/2009/7.13.bindery/2009.07.13.kallen-graphics-attach.odt
./search/applications/sent/2009/7.13.bindery/2009.07.13.copy-repro-inc-attach.odt
./search/applications/sent/2009/7.13.bindery/2009.07.13.mcAra-printing-attach.odt
./search/applications/sent/2009/7.13.bindery/2009.07.13.active-bindery-attach.odt
./search/applications/sent/2009/7.13.bindery/2009.07.13.bolder-graphics-attach.odt

Why didn't find locate these files from the documents directory; I thought it was
supposed to search all the subdirectories; when I changed into work_search it searched
the subdirectories under it? what am I not understanding here?

Thanks

Berhanie 07-12-2010 12:19 PM

You need to prevent the shell from expanding the *:
Code:

find -iname '*.odt'

pixellany 07-12-2010 12:25 PM

Don't you also need to specify the search path (or maybe it defaults to current directory)?

for many reasons, I now ALWAYS do find thusly:

assume the search term is "fred"

find <path> -name "*fred*"
(finds all files with a name containing "fred" anywhere.

tredegar 07-12-2010 12:36 PM

locate is excellent, and pre-installed on all the distros I've used. It's much faster than find
Code:

locate .odt
If you get too much information, narrow it down with grep to select things in the /path/to/file that you think might apply. Eg:
Code:

locate .odt | grep Documents
The locate database is generally updated daily, so if you want to locate a very recent file, update the database first by running (as root)
Code:

updatedb
then run locate

Berhanie 07-12-2010 12:37 PM

i think linux defaults to ., while bsd doesn't. best to always specify the path, as pixellany says.

salasi 07-12-2010 04:39 PM

Quote:

Originally Posted by tredegar (Post 4031080)
locate is excellent,

agreed, but the excellence of locate has always stopped me learning find properly, and locate only searches its database of filenames, so you can't do everything with it.

Quote:

If you get too much information, narrow it down with grep to select things in the /path/to/file that you think might apply. Eg:
Code:

locate .odt | grep Documents

in this case, it seems to be documents and not Documents, which makes me feel a bit smug (it won't last) about the fact that I would habitually do
Code:

locate .odt | grep -i Documents
without thinking. (Actually, that's a lie, what i'd do without thinking is
Code:

locate documents | grep -i .odt
or
Code:

locate documents | grep -i canadian | grep -i .odt
) (Ha! Lots of Irritating Single Parenthesise, beat that :p)

JosephS 07-12-2010 10:16 PM

Thanks for help.
I forgot about quoting:'*.odt'
I'll take a look at locate.


All times are GMT -5. The time now is 06:23 AM.