Using find
:
quotemeta() { printf '%s' "$1" | perl -0777ne'print quotemeta($_)'; }
path=constellation/netcool/aws_netcool_db2/trunk/src
find "$path" \
-path "$( quotemeta "$path/base" )" \
-prune \
-o \
\! -type d \
-print
Note that this doesn't work for paths starting with -
. Prepend ./
to those.
Using Perl:
use File::Find::Rule qw( );
my $path = "constellation/netcool/aws_netcool_db2/trunk/src";
my $FFR = File::Find::Rule::;
my @files =
$FFR->or(
$FFR
->exec(sub{ $_[2] eq "$path/base" })
->prune
->discard,
$FFR
->not( $FFR->directory ),
)
->in($path);
Note that this doesn't work for all paths (e.g. .
, those that end with /
, etc) because F::F::R cleans up the paths. You would need to apply those same undocumented cleanups to the value against which $_[2]
is compared if you wish to support arbitrary paths.