How does find -name work?Rename All Files with a Certain NameUsing sed to find and replace complex string...

David slept with Bathsheba because she was pure?? What does that mean?

Why do (or did, until very recently) aircraft transponders wait to be interrogated before broadcasting beacon signals?

In The Incredibles 2, why does Screenslaver's name use a pun on something that doesn't exist in the 1950s pastiche?

Do they make "karaoke" versions of concertos for solo practice?

As easy as Three, Two, One... How fast can you go from Five to Four?

When editor does not respond to the request for withdrawal

Print "N NE E SE S SW W NW"

Nth term of Van Eck Sequence

Is tuition reimbursement a good idea if you have to stay with the job

Why is it bad to use your whole foot in rock climbing

Changing the PK column of a data extension without completely recreating it

Is the first of the 10 Commandments considered a mitzvah?

Realistic, logical way for men with medieval-era weaponry to compete with much larger and physically stronger foes

In American Politics, why is the Justice Department under the President?

Can I use 220 V outlets on a 15 ampere breaker and wire it up as 110 V?

Am I allowed to determine tenets of my contract as a warlock?

Is there a radar system monitoring the UK mainland border?

Is it true that "only photographers care about noise"?

Boss making me feel guilty for leaving the company at the end of my internship

About the paper by Buekenhout, Delandtsheer, Doyen, Kleidman, Liebeck and Saxl

What is Gilligan's full name?

How to import .txt file with missing data?

A life of PhD: is it feasible?

Are athlete's college degrees discounted by employers and graduate school admissions?



How does find -name work?


Rename All Files with a Certain NameUsing sed to find and replace complex string (preferrably with regex)Trouble getting regex to work with findWhat types of regex DO support (e.g.) negative lookbehind?Filename Expansion: Find Utility Pattern Matching vs Bash Shell Pattern Matchingfind and md5sum not yielding any output (find -o limit?)How do the {} and + get expanded inside find with the -execdir optionExtended Regular Expressions (EREs): How do I include pattern but exclude specific superset of pattern in matches?Why does “find / -name '*.txt' | cp /junk” not work?Can someone explain bash substring matching to me?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I can't for the life of me figure out how find with the test -name works.



I run find / -name *in and returns a bunch of results:



/sbin
/sbin/sulogin
/dev/stdin


to name a few.



It's as if it performed filename expansion, but that happens before the shell runs the command, so that can't be it. Also because I don't have any files in the current directory that match *in. Plus, single quoting *in yields the same results, which further supports that this can't be filename expansion.



The documentation leads me to believe that find with -name uses regular expressions, but the regex pattern *in doesn't match the results I showed above.



Can someone enlighten me?










share|improve this question









New contributor



Find is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • "It's as if it performed filename expansion, but that happens before the shell runs the command, so that can't be it." But that's exactly what it is! Only that instead of matching the *in pattern against the files from the cwd, it matches it against the the files from the directories it's walking through.

    – mosvy
    41 mins ago











  • "The documentation kind of suggests that find with -name uses regular expressions" the documentation does not suggest such thing.

    – mosvy
    36 mins ago











  • @mosvy I edited my question.

    – Find
    34 mins ago











  • If you need regular expressions, you can use -regex pattern which is used to match the whole path (including slashes), while -name pattern operates on the filename and uses shell patterns.

    – Freddy
    30 mins ago




















0















I can't for the life of me figure out how find with the test -name works.



I run find / -name *in and returns a bunch of results:



/sbin
/sbin/sulogin
/dev/stdin


to name a few.



It's as if it performed filename expansion, but that happens before the shell runs the command, so that can't be it. Also because I don't have any files in the current directory that match *in. Plus, single quoting *in yields the same results, which further supports that this can't be filename expansion.



The documentation leads me to believe that find with -name uses regular expressions, but the regex pattern *in doesn't match the results I showed above.



Can someone enlighten me?










share|improve this question









New contributor



Find is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • "It's as if it performed filename expansion, but that happens before the shell runs the command, so that can't be it." But that's exactly what it is! Only that instead of matching the *in pattern against the files from the cwd, it matches it against the the files from the directories it's walking through.

    – mosvy
    41 mins ago











  • "The documentation kind of suggests that find with -name uses regular expressions" the documentation does not suggest such thing.

    – mosvy
    36 mins ago











  • @mosvy I edited my question.

    – Find
    34 mins ago











  • If you need regular expressions, you can use -regex pattern which is used to match the whole path (including slashes), while -name pattern operates on the filename and uses shell patterns.

    – Freddy
    30 mins ago
















0












0








0








I can't for the life of me figure out how find with the test -name works.



I run find / -name *in and returns a bunch of results:



/sbin
/sbin/sulogin
/dev/stdin


to name a few.



It's as if it performed filename expansion, but that happens before the shell runs the command, so that can't be it. Also because I don't have any files in the current directory that match *in. Plus, single quoting *in yields the same results, which further supports that this can't be filename expansion.



The documentation leads me to believe that find with -name uses regular expressions, but the regex pattern *in doesn't match the results I showed above.



Can someone enlighten me?










share|improve this question









New contributor



Find is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I can't for the life of me figure out how find with the test -name works.



I run find / -name *in and returns a bunch of results:



/sbin
/sbin/sulogin
/dev/stdin


to name a few.



It's as if it performed filename expansion, but that happens before the shell runs the command, so that can't be it. Also because I don't have any files in the current directory that match *in. Plus, single quoting *in yields the same results, which further supports that this can't be filename expansion.



The documentation leads me to believe that find with -name uses regular expressions, but the regex pattern *in doesn't match the results I showed above.



Can someone enlighten me?







find regular-expression






share|improve this question









New contributor



Find is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










share|improve this question









New contributor



Find is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








share|improve this question




share|improve this question








edited 35 mins ago







Find













New contributor



Find is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








asked 58 mins ago









FindFind

133




133




New contributor



Find is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




New contributor




Find is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • "It's as if it performed filename expansion, but that happens before the shell runs the command, so that can't be it." But that's exactly what it is! Only that instead of matching the *in pattern against the files from the cwd, it matches it against the the files from the directories it's walking through.

    – mosvy
    41 mins ago











  • "The documentation kind of suggests that find with -name uses regular expressions" the documentation does not suggest such thing.

    – mosvy
    36 mins ago











  • @mosvy I edited my question.

    – Find
    34 mins ago











  • If you need regular expressions, you can use -regex pattern which is used to match the whole path (including slashes), while -name pattern operates on the filename and uses shell patterns.

    – Freddy
    30 mins ago





















  • "It's as if it performed filename expansion, but that happens before the shell runs the command, so that can't be it." But that's exactly what it is! Only that instead of matching the *in pattern against the files from the cwd, it matches it against the the files from the directories it's walking through.

    – mosvy
    41 mins ago











  • "The documentation kind of suggests that find with -name uses regular expressions" the documentation does not suggest such thing.

    – mosvy
    36 mins ago











  • @mosvy I edited my question.

    – Find
    34 mins ago











  • If you need regular expressions, you can use -regex pattern which is used to match the whole path (including slashes), while -name pattern operates on the filename and uses shell patterns.

    – Freddy
    30 mins ago



















"It's as if it performed filename expansion, but that happens before the shell runs the command, so that can't be it." But that's exactly what it is! Only that instead of matching the *in pattern against the files from the cwd, it matches it against the the files from the directories it's walking through.

– mosvy
41 mins ago





"It's as if it performed filename expansion, but that happens before the shell runs the command, so that can't be it." But that's exactly what it is! Only that instead of matching the *in pattern against the files from the cwd, it matches it against the the files from the directories it's walking through.

– mosvy
41 mins ago













"The documentation kind of suggests that find with -name uses regular expressions" the documentation does not suggest such thing.

– mosvy
36 mins ago





"The documentation kind of suggests that find with -name uses regular expressions" the documentation does not suggest such thing.

– mosvy
36 mins ago













@mosvy I edited my question.

– Find
34 mins ago





@mosvy I edited my question.

– Find
34 mins ago













If you need regular expressions, you can use -regex pattern which is used to match the whole path (including slashes), while -name pattern operates on the filename and uses shell patterns.

– Freddy
30 mins ago







If you need regular expressions, you can use -regex pattern which is used to match the whole path (including slashes), while -name pattern operates on the filename and uses shell patterns.

– Freddy
30 mins ago












1 Answer
1






active

oldest

votes


















2














The parameter passed to -name is a filesystem glob pattern, the same as the you'd enter for other commands, such as ls -l *in.



For each file it finds it compares the basename of the file to the pattern you passed. So when it finds /bin/foobar it compares foobar to *in, doesn't match, skips; but with /bin/login it compares login to *in and this does match, and so prints.



Now you need to be careful because *in might be matched on the command line depending on files in the current directory.



So, for example:



$ find /bin -name *in
/bin
/bin/login

$ touch foobarin

$ find /bin -name *in
$


Notice the same find command returned two different results.



We can see why if we set the shell to debug mode:



$ rm foobarin 

$ set -x

$ find /bin -name *in
+ find /bin -name '*in'
/bin
/bin/login

$ touch foobarin
+ touch foobarin

$ find /bin -name *in
+ find /bin -name foobarin

$


The lines starting with a + are what the shell interpreted the command entered. We can see that the second find command expanded the *in to match the existing filename.



Because of this it's recommended to quote names



$ find /bin -name '*in'
+ find /bin -name '*in'
/bin
/bin/login





share|improve this answer
























  • Thank you, that's helpful. When you say that we should quote names. Should it be, more precisely, single quote them?

    – Find
    41 mins ago











  • The quote will depend on how you want the command line to interpret your input, same as everywhere else. So if you're looking for a file called $foo then you may use '$foo' but if you want to expand the variable then you may use "$foo". This isn't specific to the find command, but is how the command line works.

    – Stephen Harris
    38 mins ago











  • But won't the variable be expanded just like * was when you used single quotes? EDIT: I understand this expansion occurs after the command is ran, contrarily to "regular expansion".

    – Find
    36 mins ago













  • No; command line globs don't follow variable expansion. eg if we set $ foo='*in' then the command $ find /bin -name "$foo" will give the debug output + find /bin -name '*in' which is exactly what we want.

    – Stephen Harris
    34 mins ago












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
});


}
});






Find is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f524331%2fhow-does-find-name-work%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














The parameter passed to -name is a filesystem glob pattern, the same as the you'd enter for other commands, such as ls -l *in.



For each file it finds it compares the basename of the file to the pattern you passed. So when it finds /bin/foobar it compares foobar to *in, doesn't match, skips; but with /bin/login it compares login to *in and this does match, and so prints.



Now you need to be careful because *in might be matched on the command line depending on files in the current directory.



So, for example:



$ find /bin -name *in
/bin
/bin/login

$ touch foobarin

$ find /bin -name *in
$


Notice the same find command returned two different results.



We can see why if we set the shell to debug mode:



$ rm foobarin 

$ set -x

$ find /bin -name *in
+ find /bin -name '*in'
/bin
/bin/login

$ touch foobarin
+ touch foobarin

$ find /bin -name *in
+ find /bin -name foobarin

$


The lines starting with a + are what the shell interpreted the command entered. We can see that the second find command expanded the *in to match the existing filename.



Because of this it's recommended to quote names



$ find /bin -name '*in'
+ find /bin -name '*in'
/bin
/bin/login





share|improve this answer
























  • Thank you, that's helpful. When you say that we should quote names. Should it be, more precisely, single quote them?

    – Find
    41 mins ago











  • The quote will depend on how you want the command line to interpret your input, same as everywhere else. So if you're looking for a file called $foo then you may use '$foo' but if you want to expand the variable then you may use "$foo". This isn't specific to the find command, but is how the command line works.

    – Stephen Harris
    38 mins ago











  • But won't the variable be expanded just like * was when you used single quotes? EDIT: I understand this expansion occurs after the command is ran, contrarily to "regular expansion".

    – Find
    36 mins ago













  • No; command line globs don't follow variable expansion. eg if we set $ foo='*in' then the command $ find /bin -name "$foo" will give the debug output + find /bin -name '*in' which is exactly what we want.

    – Stephen Harris
    34 mins ago
















2














The parameter passed to -name is a filesystem glob pattern, the same as the you'd enter for other commands, such as ls -l *in.



For each file it finds it compares the basename of the file to the pattern you passed. So when it finds /bin/foobar it compares foobar to *in, doesn't match, skips; but with /bin/login it compares login to *in and this does match, and so prints.



Now you need to be careful because *in might be matched on the command line depending on files in the current directory.



So, for example:



$ find /bin -name *in
/bin
/bin/login

$ touch foobarin

$ find /bin -name *in
$


Notice the same find command returned two different results.



We can see why if we set the shell to debug mode:



$ rm foobarin 

$ set -x

$ find /bin -name *in
+ find /bin -name '*in'
/bin
/bin/login

$ touch foobarin
+ touch foobarin

$ find /bin -name *in
+ find /bin -name foobarin

$


The lines starting with a + are what the shell interpreted the command entered. We can see that the second find command expanded the *in to match the existing filename.



Because of this it's recommended to quote names



$ find /bin -name '*in'
+ find /bin -name '*in'
/bin
/bin/login





share|improve this answer
























  • Thank you, that's helpful. When you say that we should quote names. Should it be, more precisely, single quote them?

    – Find
    41 mins ago











  • The quote will depend on how you want the command line to interpret your input, same as everywhere else. So if you're looking for a file called $foo then you may use '$foo' but if you want to expand the variable then you may use "$foo". This isn't specific to the find command, but is how the command line works.

    – Stephen Harris
    38 mins ago











  • But won't the variable be expanded just like * was when you used single quotes? EDIT: I understand this expansion occurs after the command is ran, contrarily to "regular expansion".

    – Find
    36 mins ago













  • No; command line globs don't follow variable expansion. eg if we set $ foo='*in' then the command $ find /bin -name "$foo" will give the debug output + find /bin -name '*in' which is exactly what we want.

    – Stephen Harris
    34 mins ago














2












2








2







The parameter passed to -name is a filesystem glob pattern, the same as the you'd enter for other commands, such as ls -l *in.



For each file it finds it compares the basename of the file to the pattern you passed. So when it finds /bin/foobar it compares foobar to *in, doesn't match, skips; but with /bin/login it compares login to *in and this does match, and so prints.



Now you need to be careful because *in might be matched on the command line depending on files in the current directory.



So, for example:



$ find /bin -name *in
/bin
/bin/login

$ touch foobarin

$ find /bin -name *in
$


Notice the same find command returned two different results.



We can see why if we set the shell to debug mode:



$ rm foobarin 

$ set -x

$ find /bin -name *in
+ find /bin -name '*in'
/bin
/bin/login

$ touch foobarin
+ touch foobarin

$ find /bin -name *in
+ find /bin -name foobarin

$


The lines starting with a + are what the shell interpreted the command entered. We can see that the second find command expanded the *in to match the existing filename.



Because of this it's recommended to quote names



$ find /bin -name '*in'
+ find /bin -name '*in'
/bin
/bin/login





share|improve this answer













The parameter passed to -name is a filesystem glob pattern, the same as the you'd enter for other commands, such as ls -l *in.



For each file it finds it compares the basename of the file to the pattern you passed. So when it finds /bin/foobar it compares foobar to *in, doesn't match, skips; but with /bin/login it compares login to *in and this does match, and so prints.



Now you need to be careful because *in might be matched on the command line depending on files in the current directory.



So, for example:



$ find /bin -name *in
/bin
/bin/login

$ touch foobarin

$ find /bin -name *in
$


Notice the same find command returned two different results.



We can see why if we set the shell to debug mode:



$ rm foobarin 

$ set -x

$ find /bin -name *in
+ find /bin -name '*in'
/bin
/bin/login

$ touch foobarin
+ touch foobarin

$ find /bin -name *in
+ find /bin -name foobarin

$


The lines starting with a + are what the shell interpreted the command entered. We can see that the second find command expanded the *in to match the existing filename.



Because of this it's recommended to quote names



$ find /bin -name '*in'
+ find /bin -name '*in'
/bin
/bin/login






share|improve this answer












share|improve this answer



share|improve this answer










answered 45 mins ago









Stephen HarrisStephen Harris

28.3k35585




28.3k35585













  • Thank you, that's helpful. When you say that we should quote names. Should it be, more precisely, single quote them?

    – Find
    41 mins ago











  • The quote will depend on how you want the command line to interpret your input, same as everywhere else. So if you're looking for a file called $foo then you may use '$foo' but if you want to expand the variable then you may use "$foo". This isn't specific to the find command, but is how the command line works.

    – Stephen Harris
    38 mins ago











  • But won't the variable be expanded just like * was when you used single quotes? EDIT: I understand this expansion occurs after the command is ran, contrarily to "regular expansion".

    – Find
    36 mins ago













  • No; command line globs don't follow variable expansion. eg if we set $ foo='*in' then the command $ find /bin -name "$foo" will give the debug output + find /bin -name '*in' which is exactly what we want.

    – Stephen Harris
    34 mins ago



















  • Thank you, that's helpful. When you say that we should quote names. Should it be, more precisely, single quote them?

    – Find
    41 mins ago











  • The quote will depend on how you want the command line to interpret your input, same as everywhere else. So if you're looking for a file called $foo then you may use '$foo' but if you want to expand the variable then you may use "$foo". This isn't specific to the find command, but is how the command line works.

    – Stephen Harris
    38 mins ago











  • But won't the variable be expanded just like * was when you used single quotes? EDIT: I understand this expansion occurs after the command is ran, contrarily to "regular expansion".

    – Find
    36 mins ago













  • No; command line globs don't follow variable expansion. eg if we set $ foo='*in' then the command $ find /bin -name "$foo" will give the debug output + find /bin -name '*in' which is exactly what we want.

    – Stephen Harris
    34 mins ago

















Thank you, that's helpful. When you say that we should quote names. Should it be, more precisely, single quote them?

– Find
41 mins ago





Thank you, that's helpful. When you say that we should quote names. Should it be, more precisely, single quote them?

– Find
41 mins ago













The quote will depend on how you want the command line to interpret your input, same as everywhere else. So if you're looking for a file called $foo then you may use '$foo' but if you want to expand the variable then you may use "$foo". This isn't specific to the find command, but is how the command line works.

– Stephen Harris
38 mins ago





The quote will depend on how you want the command line to interpret your input, same as everywhere else. So if you're looking for a file called $foo then you may use '$foo' but if you want to expand the variable then you may use "$foo". This isn't specific to the find command, but is how the command line works.

– Stephen Harris
38 mins ago













But won't the variable be expanded just like * was when you used single quotes? EDIT: I understand this expansion occurs after the command is ran, contrarily to "regular expansion".

– Find
36 mins ago







But won't the variable be expanded just like * was when you used single quotes? EDIT: I understand this expansion occurs after the command is ran, contrarily to "regular expansion".

– Find
36 mins ago















No; command line globs don't follow variable expansion. eg if we set $ foo='*in' then the command $ find /bin -name "$foo" will give the debug output + find /bin -name '*in' which is exactly what we want.

– Stephen Harris
34 mins ago





No; command line globs don't follow variable expansion. eg if we set $ foo='*in' then the command $ find /bin -name "$foo" will give the debug output + find /bin -name '*in' which is exactly what we want.

– Stephen Harris
34 mins ago










Find is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















Find is a new contributor. Be nice, and check out our Code of Conduct.













Find is a new contributor. Be nice, and check out our Code of Conduct.












Find is a new contributor. Be nice, and check out our Code of Conduct.
















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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f524331%2fhow-does-find-name-work%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Hudson River Historic District Contents Geography History The district today Aesthetics Cultural...

The number designs the writing. Feandra Aversely Definition: The act of ingrafting a sprig or shoot of one...

Ayherre Geografie Demografie Externe links Navigatiemenu43° 23′ NB, 1° 15′ WL43° 23′ NB, 1°...