What is the difference between find . and find . -print
up vote
24
down vote
favorite
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
command-line find
add a comment |
up vote
24
down vote
favorite
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
command-line find
add a comment |
up vote
24
down vote
favorite
up vote
24
down vote
favorite
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
command-line find
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
command-line find
command-line find
edited Apr 22 '15 at 9:45
Stéphane Chazelas
296k54559904
296k54559904
asked Apr 22 '15 at 8:19
faressoft
303129
303129
add a comment |
add a comment |
6 Answers
6
active
oldest
votes
up vote
38
down vote
accepted
From the findutils
find
manpage:
If no expression is given, the expression
-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:
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
Sort of beginner level question but what's this expression you are talkng about? is this regular expression?
– Rishi Prakash
Apr 20 '17 at 14:33
2
@Rishi see the manpage.
– Stephen Kitt
Apr 20 '17 at 14:35
add a comment |
up vote
19
down vote
-print
is the default action. Some find
predicates are considered as actions as opposed to filters or conditions. For instance, -type f
is not an action. -exec
is an action even though it can also be used as a condition.
Actions include -print
, -exec
and -ok
. Some find
implementations have other non-standard action predicates like the -print0
, -printf
, -execdir
, -okdir
, -ls
...
find files <some-predicates>
Where none of <some-predicates>
contain actions is equivalent to:
find files ( <some-predicates> ) -print
(note the parentheses above which are important if there are some -o
operators).
When in doubt, best is to use -print
explicitly (or -exec printf '%s' {} +
(or -print0
where available) so that output can be post-processed).
The default -print
action is specified by POSIX. Some old find
implementations required an explicit -print
, but those are usually not found in the wild nowadays.
Also note that some find
implementations allow omitting the files
, in which case they default to searching into the current directory. That is, for them,
find
is equivalent to
find .
find . -print
That is however not standard, so is best avoided.
On the more verbose (and useful) end of the spectrum, some find
implementations also allow passing file paths as argument to a -f
option as in:
find -f "$file1" -f "$file2" -print
They are the only find
implementations that allow passing arbitrary file paths to find
. Other implementations cannot accept file paths like !
or -print
... so find "$file" -print
(or even find -- "$file" -print
) assumes $file
is not the name of a find
predicate (or option in the first case).
Unfortunately that's not standard nor portable either.
If it is non-standard and is best avoided why name it at all?
– Isaac
Nov 27 at 22:19
@Isaac, because they can be handy/are possible typos...
– vonbrand
Nov 28 at 0:31
add a comment |
up vote
7
down vote
They are the same, they both write out the entire directory hierarchy from the current directory.
From POSIX find documentation:
The following commands are equivalent:
find .
find . -print
add a comment |
up vote
3
down vote
In Linux there is no difference, but other systems (like AIX for instance) need -print
if you want the output of the command displayed on your screen.
3
That would be very very old versions of AIX then. AIX 4.3find
doesn't need it. AIX has been POSIX conformant for decades.
– Stéphane Chazelas
Apr 22 '15 at 9:13
add a comment |
up vote
2
down vote
For many years the find command did not have a default action. A common error was forgetting to add the -print option to your find command. I still to this day type it out of habit.
But at some point it was added as the default action so now find .
and find . -print
are equivalent.
add a comment |
up vote
0
down vote
It is sometimes useful to use -print
explicitly when you are performing another action so the filename is displayed as that action is performed.
find . -print -delete
would be similar to
rm -rfv *
where -print
corresponds to -v
. If you don't include -print
then the filenames aren't displayed.
In order to make the rm
command even more similar, by the way, issue this Bash command first
shopt -s dotglob
which will make the *
match dot (hidden) files.
add a comment |
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
38
down vote
accepted
From the findutils
find
manpage:
If no expression is given, the expression
-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:
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
Sort of beginner level question but what's this expression you are talkng about? is this regular expression?
– Rishi Prakash
Apr 20 '17 at 14:33
2
@Rishi see the manpage.
– Stephen Kitt
Apr 20 '17 at 14:35
add a comment |
up vote
38
down vote
accepted
From the findutils
find
manpage:
If no expression is given, the expression
-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:
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
Sort of beginner level question but what's this expression you are talkng about? is this regular expression?
– Rishi Prakash
Apr 20 '17 at 14:33
2
@Rishi see the manpage.
– Stephen Kitt
Apr 20 '17 at 14:35
add a comment |
up vote
38
down vote
accepted
up vote
38
down vote
accepted
From the findutils
find
manpage:
If no expression is given, the expression
-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:
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
From the findutils
find
manpage:
If no expression is given, the expression
-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:
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
edited Apr 22 '15 at 8:55
answered Apr 22 '15 at 8:29
Stephen Kitt
160k24357432
160k24357432
Sort of beginner level question but what's this expression you are talkng about? is this regular expression?
– Rishi Prakash
Apr 20 '17 at 14:33
2
@Rishi see the manpage.
– Stephen Kitt
Apr 20 '17 at 14:35
add a comment |
Sort of beginner level question but what's this expression you are talkng about? is this regular expression?
– Rishi Prakash
Apr 20 '17 at 14:33
2
@Rishi see the manpage.
– Stephen Kitt
Apr 20 '17 at 14:35
Sort of beginner level question but what's this expression you are talkng about? is this regular expression?
– Rishi Prakash
Apr 20 '17 at 14:33
Sort of beginner level question but what's this expression you are talkng about? is this regular expression?
– Rishi Prakash
Apr 20 '17 at 14:33
2
2
@Rishi see the manpage.
– Stephen Kitt
Apr 20 '17 at 14:35
@Rishi see the manpage.
– Stephen Kitt
Apr 20 '17 at 14:35
add a comment |
up vote
19
down vote
-print
is the default action. Some find
predicates are considered as actions as opposed to filters or conditions. For instance, -type f
is not an action. -exec
is an action even though it can also be used as a condition.
Actions include -print
, -exec
and -ok
. Some find
implementations have other non-standard action predicates like the -print0
, -printf
, -execdir
, -okdir
, -ls
...
find files <some-predicates>
Where none of <some-predicates>
contain actions is equivalent to:
find files ( <some-predicates> ) -print
(note the parentheses above which are important if there are some -o
operators).
When in doubt, best is to use -print
explicitly (or -exec printf '%s' {} +
(or -print0
where available) so that output can be post-processed).
The default -print
action is specified by POSIX. Some old find
implementations required an explicit -print
, but those are usually not found in the wild nowadays.
Also note that some find
implementations allow omitting the files
, in which case they default to searching into the current directory. That is, for them,
find
is equivalent to
find .
find . -print
That is however not standard, so is best avoided.
On the more verbose (and useful) end of the spectrum, some find
implementations also allow passing file paths as argument to a -f
option as in:
find -f "$file1" -f "$file2" -print
They are the only find
implementations that allow passing arbitrary file paths to find
. Other implementations cannot accept file paths like !
or -print
... so find "$file" -print
(or even find -- "$file" -print
) assumes $file
is not the name of a find
predicate (or option in the first case).
Unfortunately that's not standard nor portable either.
If it is non-standard and is best avoided why name it at all?
– Isaac
Nov 27 at 22:19
@Isaac, because they can be handy/are possible typos...
– vonbrand
Nov 28 at 0:31
add a comment |
up vote
19
down vote
-print
is the default action. Some find
predicates are considered as actions as opposed to filters or conditions. For instance, -type f
is not an action. -exec
is an action even though it can also be used as a condition.
Actions include -print
, -exec
and -ok
. Some find
implementations have other non-standard action predicates like the -print0
, -printf
, -execdir
, -okdir
, -ls
...
find files <some-predicates>
Where none of <some-predicates>
contain actions is equivalent to:
find files ( <some-predicates> ) -print
(note the parentheses above which are important if there are some -o
operators).
When in doubt, best is to use -print
explicitly (or -exec printf '%s' {} +
(or -print0
where available) so that output can be post-processed).
The default -print
action is specified by POSIX. Some old find
implementations required an explicit -print
, but those are usually not found in the wild nowadays.
Also note that some find
implementations allow omitting the files
, in which case they default to searching into the current directory. That is, for them,
find
is equivalent to
find .
find . -print
That is however not standard, so is best avoided.
On the more verbose (and useful) end of the spectrum, some find
implementations also allow passing file paths as argument to a -f
option as in:
find -f "$file1" -f "$file2" -print
They are the only find
implementations that allow passing arbitrary file paths to find
. Other implementations cannot accept file paths like !
or -print
... so find "$file" -print
(or even find -- "$file" -print
) assumes $file
is not the name of a find
predicate (or option in the first case).
Unfortunately that's not standard nor portable either.
If it is non-standard and is best avoided why name it at all?
– Isaac
Nov 27 at 22:19
@Isaac, because they can be handy/are possible typos...
– vonbrand
Nov 28 at 0:31
add a comment |
up vote
19
down vote
up vote
19
down vote
-print
is the default action. Some find
predicates are considered as actions as opposed to filters or conditions. For instance, -type f
is not an action. -exec
is an action even though it can also be used as a condition.
Actions include -print
, -exec
and -ok
. Some find
implementations have other non-standard action predicates like the -print0
, -printf
, -execdir
, -okdir
, -ls
...
find files <some-predicates>
Where none of <some-predicates>
contain actions is equivalent to:
find files ( <some-predicates> ) -print
(note the parentheses above which are important if there are some -o
operators).
When in doubt, best is to use -print
explicitly (or -exec printf '%s' {} +
(or -print0
where available) so that output can be post-processed).
The default -print
action is specified by POSIX. Some old find
implementations required an explicit -print
, but those are usually not found in the wild nowadays.
Also note that some find
implementations allow omitting the files
, in which case they default to searching into the current directory. That is, for them,
find
is equivalent to
find .
find . -print
That is however not standard, so is best avoided.
On the more verbose (and useful) end of the spectrum, some find
implementations also allow passing file paths as argument to a -f
option as in:
find -f "$file1" -f "$file2" -print
They are the only find
implementations that allow passing arbitrary file paths to find
. Other implementations cannot accept file paths like !
or -print
... so find "$file" -print
(or even find -- "$file" -print
) assumes $file
is not the name of a find
predicate (or option in the first case).
Unfortunately that's not standard nor portable either.
-print
is the default action. Some find
predicates are considered as actions as opposed to filters or conditions. For instance, -type f
is not an action. -exec
is an action even though it can also be used as a condition.
Actions include -print
, -exec
and -ok
. Some find
implementations have other non-standard action predicates like the -print0
, -printf
, -execdir
, -okdir
, -ls
...
find files <some-predicates>
Where none of <some-predicates>
contain actions is equivalent to:
find files ( <some-predicates> ) -print
(note the parentheses above which are important if there are some -o
operators).
When in doubt, best is to use -print
explicitly (or -exec printf '%s' {} +
(or -print0
where available) so that output can be post-processed).
The default -print
action is specified by POSIX. Some old find
implementations required an explicit -print
, but those are usually not found in the wild nowadays.
Also note that some find
implementations allow omitting the files
, in which case they default to searching into the current directory. That is, for them,
find
is equivalent to
find .
find . -print
That is however not standard, so is best avoided.
On the more verbose (and useful) end of the spectrum, some find
implementations also allow passing file paths as argument to a -f
option as in:
find -f "$file1" -f "$file2" -print
They are the only find
implementations that allow passing arbitrary file paths to find
. Other implementations cannot accept file paths like !
or -print
... so find "$file" -print
(or even find -- "$file" -print
) assumes $file
is not the name of a find
predicate (or option in the first case).
Unfortunately that's not standard nor portable either.
edited Nov 28 at 8:30
answered Apr 22 '15 at 9:06
Stéphane Chazelas
296k54559904
296k54559904
If it is non-standard and is best avoided why name it at all?
– Isaac
Nov 27 at 22:19
@Isaac, because they can be handy/are possible typos...
– vonbrand
Nov 28 at 0:31
add a comment |
If it is non-standard and is best avoided why name it at all?
– Isaac
Nov 27 at 22:19
@Isaac, because they can be handy/are possible typos...
– vonbrand
Nov 28 at 0:31
If it is non-standard and is best avoided why name it at all?
– Isaac
Nov 27 at 22:19
If it is non-standard and is best avoided why name it at all?
– Isaac
Nov 27 at 22:19
@Isaac, because they can be handy/are possible typos...
– vonbrand
Nov 28 at 0:31
@Isaac, because they can be handy/are possible typos...
– vonbrand
Nov 28 at 0:31
add a comment |
up vote
7
down vote
They are the same, they both write out the entire directory hierarchy from the current directory.
From POSIX find documentation:
The following commands are equivalent:
find .
find . -print
add a comment |
up vote
7
down vote
They are the same, they both write out the entire directory hierarchy from the current directory.
From POSIX find documentation:
The following commands are equivalent:
find .
find . -print
add a comment |
up vote
7
down vote
up vote
7
down vote
They are the same, they both write out the entire directory hierarchy from the current directory.
From POSIX find documentation:
The following commands are equivalent:
find .
find . -print
They are the same, they both write out the entire directory hierarchy from the current directory.
From POSIX find documentation:
The following commands are equivalent:
find .
find . -print
edited Apr 22 '15 at 8:59
answered Apr 22 '15 at 8:26
cuonglm
101k23197299
101k23197299
add a comment |
add a comment |
up vote
3
down vote
In Linux there is no difference, but other systems (like AIX for instance) need -print
if you want the output of the command displayed on your screen.
3
That would be very very old versions of AIX then. AIX 4.3find
doesn't need it. AIX has been POSIX conformant for decades.
– Stéphane Chazelas
Apr 22 '15 at 9:13
add a comment |
up vote
3
down vote
In Linux there is no difference, but other systems (like AIX for instance) need -print
if you want the output of the command displayed on your screen.
3
That would be very very old versions of AIX then. AIX 4.3find
doesn't need it. AIX has been POSIX conformant for decades.
– Stéphane Chazelas
Apr 22 '15 at 9:13
add a comment |
up vote
3
down vote
up vote
3
down vote
In Linux there is no difference, but other systems (like AIX for instance) need -print
if you want the output of the command displayed on your screen.
In Linux there is no difference, but other systems (like AIX for instance) need -print
if you want the output of the command displayed on your screen.
answered Apr 22 '15 at 8:43
YoMismo
3,0561724
3,0561724
3
That would be very very old versions of AIX then. AIX 4.3find
doesn't need it. AIX has been POSIX conformant for decades.
– Stéphane Chazelas
Apr 22 '15 at 9:13
add a comment |
3
That would be very very old versions of AIX then. AIX 4.3find
doesn't need it. AIX has been POSIX conformant for decades.
– Stéphane Chazelas
Apr 22 '15 at 9:13
3
3
That would be very very old versions of AIX then. AIX 4.3
find
doesn't need it. AIX has been POSIX conformant for decades.– Stéphane Chazelas
Apr 22 '15 at 9:13
That would be very very old versions of AIX then. AIX 4.3
find
doesn't need it. AIX has been POSIX conformant for decades.– Stéphane Chazelas
Apr 22 '15 at 9:13
add a comment |
up vote
2
down vote
For many years the find command did not have a default action. A common error was forgetting to add the -print option to your find command. I still to this day type it out of habit.
But at some point it was added as the default action so now find .
and find . -print
are equivalent.
add a comment |
up vote
2
down vote
For many years the find command did not have a default action. A common error was forgetting to add the -print option to your find command. I still to this day type it out of habit.
But at some point it was added as the default action so now find .
and find . -print
are equivalent.
add a comment |
up vote
2
down vote
up vote
2
down vote
For many years the find command did not have a default action. A common error was forgetting to add the -print option to your find command. I still to this day type it out of habit.
But at some point it was added as the default action so now find .
and find . -print
are equivalent.
For many years the find command did not have a default action. A common error was forgetting to add the -print option to your find command. I still to this day type it out of habit.
But at some point it was added as the default action so now find .
and find . -print
are equivalent.
answered Apr 22 '15 at 16:59
Kevin
211
211
add a comment |
add a comment |
up vote
0
down vote
It is sometimes useful to use -print
explicitly when you are performing another action so the filename is displayed as that action is performed.
find . -print -delete
would be similar to
rm -rfv *
where -print
corresponds to -v
. If you don't include -print
then the filenames aren't displayed.
In order to make the rm
command even more similar, by the way, issue this Bash command first
shopt -s dotglob
which will make the *
match dot (hidden) files.
add a comment |
up vote
0
down vote
It is sometimes useful to use -print
explicitly when you are performing another action so the filename is displayed as that action is performed.
find . -print -delete
would be similar to
rm -rfv *
where -print
corresponds to -v
. If you don't include -print
then the filenames aren't displayed.
In order to make the rm
command even more similar, by the way, issue this Bash command first
shopt -s dotglob
which will make the *
match dot (hidden) files.
add a comment |
up vote
0
down vote
up vote
0
down vote
It is sometimes useful to use -print
explicitly when you are performing another action so the filename is displayed as that action is performed.
find . -print -delete
would be similar to
rm -rfv *
where -print
corresponds to -v
. If you don't include -print
then the filenames aren't displayed.
In order to make the rm
command even more similar, by the way, issue this Bash command first
shopt -s dotglob
which will make the *
match dot (hidden) files.
It is sometimes useful to use -print
explicitly when you are performing another action so the filename is displayed as that action is performed.
find . -print -delete
would be similar to
rm -rfv *
where -print
corresponds to -v
. If you don't include -print
then the filenames aren't displayed.
In order to make the rm
command even more similar, by the way, issue this Bash command first
shopt -s dotglob
which will make the *
match dot (hidden) files.
answered Apr 22 '15 at 19:21
Dennis Williamson
5,32812232
5,32812232
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f197824%2fwhat-is-the-difference-between-find-and-find-print%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown