Re: find command to not print "current" directory name with prune options
- From: Geoff Clare <geoff@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 7 Feb 2012 13:36:00 +0000
brumik wrote:
I have these files/directories in my current directory.
.
./dir
./dir/log
./log
I want to just prune ./log *only*
find . -name 'log' -prune -o -print
.
./dir
As you see it also pruned ./dir/log, how can I get find to prune the
current directory only, I tried various methods.
You need a version of find that supports "-path". This was added
to POSIX in 2008, but I don't know whether Solaris 11 find supports
it (Solaris 10 and earlier did not). If you have GNU find (perhaps
as gfind) you can use that:
[g]find . -path './log' -prune -o -print
Alternatively you can filter the output of find, which will be fine
for the example given, but will be less efficient if what you are
pruning is a directory with many files below it.
find . | grep -vE '^\./log(/|$)'
--
Geoff Clare <netnews@xxxxxxxxxxxxx>
.
- References:
- Prev by Date: Re: curl problem on Solaris
- Next by Date: LiveUpgrade and zones behaving badly
- Previous by thread: Re: find command to not print "current" directory name with prune options
- Next by thread: installing centos in lx branded zone fails
- Index(es):