command-line – Difference Between find . and find . -print

command linefind

What is the difference between:

find .

and

find . -print

What does -print actually do?

$ find .
.
./hello.txt
./hello
./hello/txt
./hello/hello2
./hello/hello2/hello3
./hello/hello2/hello3/txt
./hello/hello2/txt
$ find . -print
.
./hello.txt
./hello
./hello/txt
./hello/hello2
./hello/hello2/hello3
./hello/hello2/hello3/txt
./hello/hello2/txt

Best Answer

From the findutils find manpage:

If no expression is given, the expression -print is used (but you should probably consider using -print0 instead, anyway).

(-print is a find expression.)

The POSIX documentation confirms this:

If no expression is present, -print shall be used as the expression.

So find . is exactly equivalent to find . -print; the first has no expression so -print is added internally.

The explanation of what -print does comes further down in the manpage:

-print

True; print the full file name on the standard output, followed by a newline. If you are piping the output of find into another program and there is the faintest possibility that the files which you are searching for might contain a newline, then you should seriously consider using the -print0 option instead of -print. See the UNUSUAL FILENAMES section for information about how unusual characters in filenames are handled.