1

This question already has an answer here:

Here is my directory tree (not showing all dirs, files, just the essential):

a_root_dir/ (directory)
a_root_dir/dynamo/local/run.sh
a_root_dir/dynamo/local/run_local.sh

Now when I do

> cd a_root_dir
> find . -name *.sh
./dynamo/local/run.sh
########### IT DOESN'T SHOW run_local.sh !!!!
> cd dynamo
> pwd
...../a_root_dir/dynamo
> find . -name *.sh
./local/run.sh
./local/run_local.sh
######## NOW IT FOUND IT

How come this happens?

Files and directories and scripts are "usual", there is no symlink. Many thanks

marked as duplicate by Gilles find Nov 24 '16 at 23:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4

The problem is that your asterisk is interpreted by the shell BEFORE it is passed to find as an argument.

I.e. if you have a file like script.sh in the current working directory from where you execute find, your command will look like this:

#command you type:
find . -name *.sh
#command the shell creates:
find . -name script.sh

So in your case it is the first match for *.sh in a_root_dir as interpreted by the shell, and your command literally is this:

find . -name run.sh

What you need to do is using hard quotes to suppress the shell expanding the asterisk before find is executed:

find . -name '*.sh'

Not the answer you're looking for? Browse other questions tagged or ask your own question.