R Syed
R Syed

Reputation: 1093

Searching for particular files in a directory non-recursively using find. AIX

I have a script which has the following command. I am trying to edit this in such a way that it only searches the files in the directory of the path without going in the subdirectories. That is not recursive search

find {Path} -name "cor*" -type f -exec ls -l {} \;

Example: The command should give cor123.log only and not cor456.log. Currently it gives both

<Path>
     ..cor123.log
    <directory>
      ..cor456.log

I tried using -maxdepth but it's not supported in AIX. -prune and -depth didn't help either.

Will appreciate any help. Thanks

Upvotes: 2

Views: 2061

Answers (3)

Omari Victor Omosa
Omari Victor Omosa

Reputation: 2879

Late answer but may save some. In aix

find /some/directory/* -prune -type f -name *.log

For instance make your path have the last forward slash with a wildcard then -prune

/*

find /some/directory/* -prune -name "cor*" -type f -exec ls -l {} \

Tested.

Upvotes: 0

Walter A
Walter A

Reputation: 20022

Do you need find for selecting files only?
When you know that all files starting with cor are regula files, you can use
ls -l ${Path}/cor*
or
ls -l ${Path}/cor*.log

When you need the -type f, you can try to filter the results.
The filename can not have a /, so remove everything with an / after the Path.
We do not know the last char of ${Path}. It can be /, which will make the grep -Ev "${Path}/.*/" filter useless. After the Path at least one character is needed before looking for the next /.

find "${Path}" -name "cor*" -type f 2>/dev/null| grep -Ev "${Path}..*/" | xargs -ls

Upvotes: 0

MichalH
MichalH

Reputation: 1074

You can use

find . -name . -o -prune

to find files and directories non-recursively.

So in your case this one will work:

find . -name . -o -prune -name 'cor*' -type f -exec ls -l {} \;

Upvotes: 1

Related Questions