Why is my find not recursive?
I am running the following command, but it is not performed recursively:
find . -name *.java
I know there are java files further down in the current directory but it is performing the find
on the current directory only. I am using OS X, 10.9.
shell find wildcards
add a comment |
I am running the following command, but it is not performed recursively:
find . -name *.java
I know there are java files further down in the current directory but it is performing the find
on the current directory only. I am using OS X, 10.9.
shell find wildcards
@Gilles : This Q&A is much clearer and less localized than the dupe -- if one of them should be closed, it's the other one.
– goldilocks
Apr 7 '14 at 1:50
add a comment |
I am running the following command, but it is not performed recursively:
find . -name *.java
I know there are java files further down in the current directory but it is performing the find
on the current directory only. I am using OS X, 10.9.
shell find wildcards
I am running the following command, but it is not performed recursively:
find . -name *.java
I know there are java files further down in the current directory but it is performing the find
on the current directory only. I am using OS X, 10.9.
shell find wildcards
shell find wildcards
edited Apr 6 '14 at 22:59
Gilles
530k12810621590
530k12810621590
asked Apr 6 '14 at 22:02
user11498user11498
86141124
86141124
@Gilles : This Q&A is much clearer and less localized than the dupe -- if one of them should be closed, it's the other one.
– goldilocks
Apr 7 '14 at 1:50
add a comment |
@Gilles : This Q&A is much clearer and less localized than the dupe -- if one of them should be closed, it's the other one.
– goldilocks
Apr 7 '14 at 1:50
@Gilles : This Q&A is much clearer and less localized than the dupe -- if one of them should be closed, it's the other one.
– goldilocks
Apr 7 '14 at 1:50
@Gilles : This Q&A is much clearer and less localized than the dupe -- if one of them should be closed, it's the other one.
– goldilocks
Apr 7 '14 at 1:50
add a comment |
3 Answers
3
active
oldest
votes
The problem is, you didn't quote your -name
parameter. Do this instead:
find . -name '*.java'
Explanation
Without the quotes, the shell interprets *.java
as a glob pattern and expands it to any file names matching the glob before passing it to find
. This way, if you had, say, foo.java
in the current directory, find
's actual command line would be:
find . -name foo.java
which would obviously list the file in the current directory only (unless you happen to have some similarly-named files further down the tree).
Quoting prevents glob expansion and passes the command line to find
as-is.
Incidentally, if the glob had failed to match (no *.java
files in the current directory), you would get one of two behaviors depending on how your shell is set up to handle globs that don't match (this is governed by the nullglob
option in Bash, for example):
- If a glob that doesn't match is not expanded by the shell,
find
will (accidentally, mind you) exhibit correct behavior. - If a glob that doesn't match is expanded into an empty string by the shell,
find
will complain that it is missing an argument to-name
.
add a comment |
I had a situation similar where I was surrounding the -name value in quotes, but still wasn't getting all of the find hits that I was hoping for. I conjectured that it was because of symlinks and sure enough that was the case. If you want to force find to search through symlinks you can modify the command to the following:
find -L . -name '*.java'
add a comment |
Escape the *
find . -name *.java
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2f123440%2fwhy-is-my-find-not-recursive%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
The problem is, you didn't quote your -name
parameter. Do this instead:
find . -name '*.java'
Explanation
Without the quotes, the shell interprets *.java
as a glob pattern and expands it to any file names matching the glob before passing it to find
. This way, if you had, say, foo.java
in the current directory, find
's actual command line would be:
find . -name foo.java
which would obviously list the file in the current directory only (unless you happen to have some similarly-named files further down the tree).
Quoting prevents glob expansion and passes the command line to find
as-is.
Incidentally, if the glob had failed to match (no *.java
files in the current directory), you would get one of two behaviors depending on how your shell is set up to handle globs that don't match (this is governed by the nullglob
option in Bash, for example):
- If a glob that doesn't match is not expanded by the shell,
find
will (accidentally, mind you) exhibit correct behavior. - If a glob that doesn't match is expanded into an empty string by the shell,
find
will complain that it is missing an argument to-name
.
add a comment |
The problem is, you didn't quote your -name
parameter. Do this instead:
find . -name '*.java'
Explanation
Without the quotes, the shell interprets *.java
as a glob pattern and expands it to any file names matching the glob before passing it to find
. This way, if you had, say, foo.java
in the current directory, find
's actual command line would be:
find . -name foo.java
which would obviously list the file in the current directory only (unless you happen to have some similarly-named files further down the tree).
Quoting prevents glob expansion and passes the command line to find
as-is.
Incidentally, if the glob had failed to match (no *.java
files in the current directory), you would get one of two behaviors depending on how your shell is set up to handle globs that don't match (this is governed by the nullglob
option in Bash, for example):
- If a glob that doesn't match is not expanded by the shell,
find
will (accidentally, mind you) exhibit correct behavior. - If a glob that doesn't match is expanded into an empty string by the shell,
find
will complain that it is missing an argument to-name
.
add a comment |
The problem is, you didn't quote your -name
parameter. Do this instead:
find . -name '*.java'
Explanation
Without the quotes, the shell interprets *.java
as a glob pattern and expands it to any file names matching the glob before passing it to find
. This way, if you had, say, foo.java
in the current directory, find
's actual command line would be:
find . -name foo.java
which would obviously list the file in the current directory only (unless you happen to have some similarly-named files further down the tree).
Quoting prevents glob expansion and passes the command line to find
as-is.
Incidentally, if the glob had failed to match (no *.java
files in the current directory), you would get one of two behaviors depending on how your shell is set up to handle globs that don't match (this is governed by the nullglob
option in Bash, for example):
- If a glob that doesn't match is not expanded by the shell,
find
will (accidentally, mind you) exhibit correct behavior. - If a glob that doesn't match is expanded into an empty string by the shell,
find
will complain that it is missing an argument to-name
.
The problem is, you didn't quote your -name
parameter. Do this instead:
find . -name '*.java'
Explanation
Without the quotes, the shell interprets *.java
as a glob pattern and expands it to any file names matching the glob before passing it to find
. This way, if you had, say, foo.java
in the current directory, find
's actual command line would be:
find . -name foo.java
which would obviously list the file in the current directory only (unless you happen to have some similarly-named files further down the tree).
Quoting prevents glob expansion and passes the command line to find
as-is.
Incidentally, if the glob had failed to match (no *.java
files in the current directory), you would get one of two behaviors depending on how your shell is set up to handle globs that don't match (this is governed by the nullglob
option in Bash, for example):
- If a glob that doesn't match is not expanded by the shell,
find
will (accidentally, mind you) exhibit correct behavior. - If a glob that doesn't match is expanded into an empty string by the shell,
find
will complain that it is missing an argument to-name
.
answered Apr 6 '14 at 22:04
Joseph R.Joseph R.
28.1k374114
28.1k374114
add a comment |
add a comment |
I had a situation similar where I was surrounding the -name value in quotes, but still wasn't getting all of the find hits that I was hoping for. I conjectured that it was because of symlinks and sure enough that was the case. If you want to force find to search through symlinks you can modify the command to the following:
find -L . -name '*.java'
add a comment |
I had a situation similar where I was surrounding the -name value in quotes, but still wasn't getting all of the find hits that I was hoping for. I conjectured that it was because of symlinks and sure enough that was the case. If you want to force find to search through symlinks you can modify the command to the following:
find -L . -name '*.java'
add a comment |
I had a situation similar where I was surrounding the -name value in quotes, but still wasn't getting all of the find hits that I was hoping for. I conjectured that it was because of symlinks and sure enough that was the case. If you want to force find to search through symlinks you can modify the command to the following:
find -L . -name '*.java'
I had a situation similar where I was surrounding the -name value in quotes, but still wasn't getting all of the find hits that I was hoping for. I conjectured that it was because of symlinks and sure enough that was the case. If you want to force find to search through symlinks you can modify the command to the following:
find -L . -name '*.java'
answered Aug 5 '15 at 22:32
gaoagonggaoagong
27123
27123
add a comment |
add a comment |
Escape the *
find . -name *.java
add a comment |
Escape the *
find . -name *.java
add a comment |
Escape the *
find . -name *.java
Escape the *
find . -name *.java
answered Dec 31 '18 at 14:39
Stuart CardallStuart Cardall
831610
831610
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.
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%2f123440%2fwhy-is-my-find-not-recursive%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
@Gilles : This Q&A is much clearer and less localized than the dupe -- if one of them should be closed, it's the other one.
– goldilocks
Apr 7 '14 at 1:50