UNIX ls command with wild card

I have a need to search for files.

One type has name like this, where I just need the SUE part, the rest is wildcard:
SUE - Elliott

here is my working code:


set file_path to (do shell script "ls  'volumes/DW/700Club/Features/SCRIPTS/Setup - SU/'" & producer_code's quoted form & "*/" & project_code's quoted form & "*")


the other file is reversed, the wildcard is FIRST, the last part is what I need
Operation blessing - OB
here is code that is NOT working:
what am I doing wrong


set file_path to (do shell script "ls  'volumes/DW/700Club/Features/Scripts/'" & "*" & producer_code's quoted form & "/" & project_code's quoted form & "*")

here is an option that does not work:


set file_path to (do shell script "ls 'volumes/DW/700Club/Features/SCRIPTS/'*' '" & producer_code's quoted form & "/" & project_code's quoted form & "*")

Hi. To my recollection, the ls command doesn’t directly handle regex; it could be piped to grep for that. Find can do it directly. Go back and look at my example from the similar thread on this subject, which used ‘.*’ The period is a wildcard for any character. The asterisk is a quantifier indicating ‘none or more times,’ and both of those are within the quoted area.

It’s true that ls doesn’t handle regex. Bash itself has expansions and can be used with any command you like. At first it may seem like regex but it’s not the same. What sebrady’s using here is called filename expansion.

So when I say:

[format]ls $HOME/Desktop/*[/format]

The $HOME/Desktop/* argument is replaced (expanded) by an array of paths to all the files on my desktop. So after bash has interpreted the command above it will look something like ($HOME will be replaced with the path to home folder as well):

[format]ls $HOME/Desktop/file1.txt $HOME/Desktop/directory1…[/format]

nothing I do works.
It seems to me ls is faster then find

if this works: variable *
why doesn’t this work: * variable

this does not work


set theTarget to (do shell script "find -E " & "/volumes/DW/700Club/Features/SCRIPTS/"'s quoted form & " -maxdepth 3 -type f -regex " & ".*" & project_code's quoted form) as POSIX file as alias

Both doesn’t work, spaces should be quoted or escaped. I can place the ‘’ everywhere I want an it works just fine. Don’t forget it is case sensitive and the '’ should be used in unquoted form.

Return the contents of every directory whose name starts with a small letter ‘t’ inside every dictory starting with an capital D of my home folder.

[format]ls $HOME/D*/t*[/format]

Return the contents of every directory whose name ends with a small letter ‘t’ inside every directory starting with an capital D of my home folder.

[format]ls $HOME/D*/*t[/format]

As explained in my previous comment. Using wildcards in Bash has nothing to do with the performance of the command itself. It’s an feature provided by Bash, nothing else.

Also keep in mind that filename expansion can exceed the maximum number of arguments of the shell making the command incomplete or return an error. The number is not insanely high so it’s safer to use find.

When you eliminated the second regex, you changed the meaning. Your search logic requires the filename to end with the project code, where my version searched at any point in the path.