Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Typically, one sees find commands that look like this:

$ find . -name foo.txt

when the search is to begin from the current directory. I'm finding that on my machines (Ubuntu, Cygwin) I get the same results without the dot.

Why is it typically included? Is it just a convention to be explicit, or was/is it required on certain systems?

share|improve this question

2 Answers 2

up vote 20 down vote accepted

Some versions* of find require that you provide a path argument which is a directory from which to start searching. Dot . simply represents the current directory is is usually where you want to search.

You could replace this with any path that you want to be the base of the search. In some versions of find this can be left because the current directory is implied if no path argument is present.

You can run man find in your shell for details about the arguments. For example the usage synopsis for mine indicates that the path argument is optional (inside square brackest []):

   find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression]

If you ran my find with no arguments at all all files and directories starting from the current folder would be returned. Your example simply expressly states that the search should start from . and includes the expression -name foo.txt as one of the search filters.

* Notably all the BSD variants and anything sticking strictly to the POSIX standard. GNU find allows it to be optional.

share|improve this answer
1  
Do you know off-hand what versions of find require this? Or where I could look to investigate further? (find is hard to google) –  Eric Wilson Aug 5 '11 at 13:09
    
Interesting thing about the default search path. –  rozcietrzewiacz Aug 5 '11 at 13:10
    
@FarmBoy +1 for noting the google problem :D (Who'd have thought... Find+Google looks like a perfect match!) –  rozcietrzewiacz Aug 5 '11 at 13:12
2  
I believe most BSD find variants require a path argument while in GNU find it is optional. Variations may exist. –  Caleb Aug 5 '11 at 13:15
2  
Note that in at least the 2008 POSIX standard specifications, path is a required argument to find. –  Caleb Aug 5 '11 at 13:20

The AIX version of find for example, requires the path and won't run if one isn't provided.

# oslevel -s
5300-08-03-0831
# find -name bob
Usage: find [-H | -L] Path-list [Expression-list]

# oslevel -s
6100-03-01-0921
# find -name bob
Usage: find [-H | -L] Path-list [Expression-list]

Although some AIX machines may have a GNU find installed, which can cope without the path,

# oslevel -s
6100-03-01-0921
# /opt/freeware/bin/find -version
GNU find version 4.1
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.