1

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

Thomas
  • 893

1 Answers1

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'
FelixJN
  • 13,566