LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Significance of "." with "find" command (https://www.linuxquestions.org/questions/linux-newbie-8/significance-of-with-find-command-4175471859/)

andrew.comly 08-02-2013 08:53 AM

Significance of "." with "find" command
 
I enter in both the following commands and get the same result:
1) find . -print | grep -i foo
2) find -print | grep -i foo

What is the role(significance) of the period? In what situation would there be a difference? Doesn't "." mean hidden?

Even though I was sucessful, I am still curious to understand ".".

Razaliel 08-02-2013 09:05 AM

Hi,

When . is put in the beginning of a file name, it makes the file(or directory) hidden indeed. Another meaning of . is the current directory. if you do : ls -a, you can see that there are two particular directories, the . and the .. , the first one . points to the current directory while the second one .. points to the parent directory.

With the command find, you must specify where to look for what you seek. And when you put . after the command find, you tell the command to search in the current directory. It doesn't make a difference if you don't put . because by default it searches in the current directory.

druuna 08-02-2013 09:07 AM

The dot tells find to start looking from the directory you are executing the command from.

You can tell find to start in a different place: find /etc ...... would start looking in /etc

Also have a look at the EXAMPLES section in the find manual page.

haertig 08-02-2013 10:14 AM

I'm from the old school where you had to tell find exactly where you wanted to search, and what you wanted it to do with the results:
Code:

$ find . -name Misc -print
./Misc
$ find . -name Misc -ls
53609606    4 drwxr-xr-x  2 fred    fred        4096 Jul  8 23:54 ./Misc
$

But these days there are lots of defaults you can take advantage of (note the last variation returns different results):
Code:

$ find -name Misc -print
./Misc
$ find . -name Misc
./Misc
$ find -name Misc
./Misc
$ find Misc
Misc
Misc/tcvol_68
Misc/tcvol_69
$


David the H. 08-02-2013 03:09 PM

The basic syntax for find is this:

Code:

find <startingdirs> <globalopts> <tests> <actions>
All of the sections can have multiple entries.

If you don't include any starting directories then most versions of find will default to the $PWD, but it's generally better to explicitly set them anyway. At the very least it removes any ambiguity.

(If you aren't aware yet, "." is a hardlink to the current directory. This is built into the file system itself.)


In addition, if you don't include any actions, the default is usually to print the files. But if you have a compound "or" expression you generally have to include your actions explicitly. So again, I think it's better to always include them anyway.

Finally, be aware that I'm mostly writing from experience with gnu find, and I don't know much about other versions.


Here are a couple of good links about using find:
http://mywiki.wooledge.org/UsingFind
http://www.grymoire.com/Unix/Find.html


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