find(1) question on HP-UX 11

find(1) question on HP-UX 11

Post by [Frank » Tue, 04 Sep 2001 18:58:23



Greetings,

I need to process all sub-directories in a particular directory,
but not their sub-directories.

I have something akin to this:

    find ${DIR} -type d -print | while read dirname
    do
       ... stuff ...
    done

I do NOT want to descend below the directory specified ${DIR} but
find recursively descends the directories.  I thought -prune is
what I want but that's not it either.

I know, using GNU find, I can specify -maxdepth 1 but I only can
use HPUX 11.0 find(1).

I'd be greatful for any pointers.

Thanks in advance.

 
 
 

find(1) question on HP-UX 11

Post by Juergen Hec » Tue, 04 Sep 2001 19:25:31


Quote:> Greetings,

> I need to process all sub-directories in a particular directory,
> but not their sub-directories.

> I have something akin to this:

>     find ${DIR} -type d -print | while read dirname
>     do
>        ... stuff ...
>     done

> I do NOT want to descend below the directory specified ${DIR} but
> find recursively descends the directories.  I thought -prune is
> what I want but that's not it either.

> I know, using GNU find, I can specify -maxdepth 1 but I only can
> use HPUX 11.0 find(1).

> I'd be greatful for any pointers.

> Thanks in advance.

Try:
# .-directories, but not " .."  will be processed, too
ls -d  $DIR/.*  $DIR/*  | grep -v '^..$'  | while read file
do
   [  -d "$file" ]  && { ... stuff ...    ; }
done

Juergen

 
 
 

find(1) question on HP-UX 11

Post by Chris F.A. Johnso » Tue, 04 Sep 2001 19:40:28


On Mon, 3 Sep 2001, it was written:

Quote:> Greetings,

> I need to process all sub-directories in a particular directory,
> but not their sub-directories.

> I have something akin to this:

>     find ${DIR} -type d -print | while read dirname
>     do
>        ... stuff ...
>     done

> I do NOT want to descend below the directory specified ${DIR} but
> find recursively descends the directories.  I thought -prune is
> what I want but that's not it either.

> I know, using GNU find, I can specify -maxdepth 1 but I only can
> use HPUX 11.0 find(1).

 cd ${DIR}
 find . -type d -print |
   cut -d '/' -f2 |
      sort -u | while read dirname
                do
                    ... stuff ...
                done

--
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2001, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

 
 
 

find(1) question on HP-UX 11

Post by Chris F.A. Johnso » Tue, 04 Sep 2001 19:59:54



> > I need to process all sub-directories in a particular directory,
> > but not their sub-directories.

> > I have something akin to this:

> >     find ${DIR} -type d -print | while read dirname
> >     do
> >        ... stuff ...
> >     done

> > I do NOT want to descend below the directory specified ${DIR} but
> > find recursively descends the directories.  I thought -prune is
> > what I want but that's not it either.

> > I know, using GNU find, I can specify -maxdepth 1 but I only can
> > use HPUX 11.0 find(1).

> > I'd be greatful for any pointers.

> Try:
> # .-directories, but not " .."  will be processed, too
> ls -d  $DIR/.*  $DIR/*  | grep -v '^..$'  | while read file
> do
>    [  -d "$file" ]  && { ... stuff ...    ; }

UUO grep

 ls -dA  $DIR/* | ## list dot files/dirs but not "." or ".."
  while read file
  do
    if [ -d "$file" ]
    then
        ... stuff ...
    fi
  done

--
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2001, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

 
 
 

find(1) question on HP-UX 11

Post by t.. » Tue, 04 Sep 2001 20:27:22



> I need to process all sub-directories in a particular directory,
> but not their sub-directories.

> I have something akin to this:

>     find ${DIR} -type d -print | while read dirname
>     do
>        ... stuff ...
>     done

> I do NOT want to descend below the directory specified ${DIR} but
> find recursively descends the directories.  I thought -prune is
> what I want but that's not it either.

How did you use -prune? Try

find ${DIR} -type d ! -path ${DIR} -prune -print | ...

--
Tapani Tarvainen

 
 
 

find(1) question on HP-UX 11

Post by Frank Slootwe » Tue, 04 Sep 2001 20:45:00


ls -ap | grep '\/$' | grep -v -e '\.\/$' -e '\.\\\\$' | while read dirname
do
   ... stuff ...
done

[The first grep selects only "dir/" lines, the second grep excludes "./"
and "../".]

  If you do not care about .something directories, then it becomes
simpler:

ls -p | grep '\/$' | while read dirname
do
   ... stuff ...
done


> Greetings,

> I need to process all sub-directories in a particular directory,
> but not their sub-directories.

> I have something akin to this:

>     find ${DIR} -type d -print | while read dirname
>     do
>        ... stuff ...
>     done

> I do NOT want to descend below the directory specified ${DIR} but
> find recursively descends the directories.  I thought -prune is
> what I want but that's not it either.

> I know, using GNU find, I can specify -maxdepth 1 but I only can
> use HPUX 11.0 find(1).

> I'd be greatful for any pointers.

> Thanks in advance.

 
 
 

find(1) question on HP-UX 11

Post by Oliver Kiessli » Tue, 04 Sep 2001 23:22:19



> Greetings,

> I need to process all sub-directories in a particular directory,
> but not their sub-directories.

> I have something akin to this:

>     find ${DIR} -type d -print | while read dirname
>     do
>        ... stuff ...
>     done

> I do NOT want to descend below the directory specified ${DIR} but
> find recursively descends the directories.  I thought -prune is
> what I want but that's not it either.

> I know, using GNU find, I can specify -maxdepth 1 but I only can
> use HPUX 11.0 find(1).

Why do you think you need to use 'find'?

ls -ap "$DIR" | sed -n "s|/$||gp" | while read dirname; do
   ... stuff ...
done

Verified under HP-UX B.11.00 C 9000/800

Quote:

> I'd be greatful for any pointers.

> Thanks in advance.

- Oliver
 
 
 

find(1) question on HP-UX 11

Post by laura fairhe » Wed, 05 Sep 2001 00:43:08



>Greetings,

>I need to process all sub-directories in a particular directory,
>but not their sub-directories.

>I have something akin to this:

>    find ${DIR} -type d -print | while read dirname
>    do
>       ... stuff ...
>    done

>I do NOT want to descend below the directory specified ${DIR} but
>find recursively descends the directories.  I thought -prune is
>what I want but that's not it either.

>I know, using GNU find, I can specify -maxdepth 1 but I only can
>use HPUX 11.0 find(1).

>I'd be greatful for any pointers.

Rather than using 'find' you could just use a 'for' loop;

#!/bin/sh
DIR=${DIR%/}
for dirname in $DIR/* $DIR/.[!.]* $DIR/..?*
do
[ -d "$dirname" ] &&
  {
  echo "processing directory: $dirname"
  # do whatever...
  }
done

line 2 deletes any trailing slash on the directory name (this is
because some end with / and some don't). then line3 uses 3 patterns
to match every filename except '.' and '..', then line5 tests
for a directory and executes the code if it is. it should work
for directory names with awkward characters like embedded spaces,
newlines and asterisks, also it should be more efficient with
resources (since you lose the pipe + extra process).

bye,

--
: ${L} # http://lf.8k.com:80

- Show quoted text -

Quote:>Thanks in advance.

 
 
 

find(1) question on HP-UX 11

Post by laura fairhe » Wed, 05 Sep 2001 01:17:02




>>Greetings,

>>I need to process all sub-directories in a particular directory,
>>but not their sub-directories.

>>I have something akin to this:

>>    find ${DIR} -type d -print | while read dirname
>>    do
>>       ... stuff ...
>>    done

>>I do NOT want to descend below the directory specified ${DIR} but
>>find recursively descends the directories.  I thought -prune is
>>what I want but that's not it either.

>>I know, using GNU find, I can specify -maxdepth 1 but I only can
>>use HPUX 11.0 find(1).

>>I'd be greatful for any pointers.

>Rather than using 'find' you could just use a 'for' loop;

>#!/bin/sh
>DIR=${DIR%/}
>for dirname in $DIR/* $DIR/.[!.]* $DIR/..?*
>do
>[ -d "$dirname" ] &&
>  {
>  echo "processing directory: $dirname"
>  # do whatever...
>  }
>done

>line 2 deletes any trailing slash on the directory name (this is
>because some end with / and some don't). then line3 uses 3 patterns
>to match every filename except '.' and '..', then line5 tests
>for a directory and executes the code if it is. it should work
>for directory names with awkward characters like embedded spaces,
>newlines and asterisks, also it should be more efficient with
>resources (since you lose the pipe + extra process).

The note here about directory names with embedded spaces and newlines
only applies to the sub-directories of $DIR. In the case that you want
to be able to deal with $DIR itself possibly containing embedded newlines
and spaces then change line 3 to the following;

for dirname in "$DIR"/* "$DIR"/.[!.]* "$DIR"/..?*

--
: ${L} # http://lf.8k.com

 
 
 

find(1) question on HP-UX 11

Post by those who know me have no need of my nam » Thu, 06 Sep 2001 03:05:55



Quote:>The note here about directory names with embedded spaces and newlines
>only applies to the sub-directories of $DIR. In the case that you want
>to be able to deal with $DIR itself possibly containing embedded newlines
>and spaces then change line 3 to the following;

>for dirname in "$DIR"/* "$DIR"/.[!.]* "$DIR"/..?*

i'd tend to go with

ls -1a $DIR/ | while read dirname && [ -n "$dirname" ]
do
  test -d "$DIR/$dirname" || continue
  test "$dirname" = "." -o "$dirname" = ".." && continue
  ...
done

--
okay, have a sig then

 
 
 

find(1) question on HP-UX 11

Post by laura fairhe » Wed, 26 Sep 2001 04:08:18





>>  ls -dA  $DIR/* | ## list dot files/dirs but not "." or ".."

>"*" won't get ".*".  Maybe

>ls -A "$DIR" | xargs ls -1dA

>but that runs into problems with some filenames.

>And youmight want to  do

>ls -1dA

>lest ls put the output in multiple columns.  I'm not sure whether that's a
>problem here.

'ls' should actually check if stdout is a terminal, and if it isn't
then you shouldn't have to force a '-1'. I'd be interested to know if
you've found something that doesn't conform to that behaviour though
(is that why you said you're not sure?)

--
: ${L:-aura} # http://lf.8k.com:80

- Show quoted text -

>--

>             This message was created using recycled electrons.
><html><body><!

 
 
 

1. Makefile syntax question (HP-UX 10.20/11.x)

Hi,

I'm trying to move some existing Makefiles written for Solaris over to
HP-UX 10.20 systems.  The Makefiles are used to install host specific
configuation files.

On the Suns I can define the machine's hostname with:

HOSTNAME=sh:uname -n

However, on the HPs I don't have the option of using '=sh:'. I tried using
single backquotes. From what I was able to find from HP it looked like I
should have been able to do:

HOSTNAME=`uname -n`

Unfortunately, this results in make telling me that it can't make
fstab.`uname

Explictly setting the shell in the Makefile to Bourne doesn't help.  I can
get the make to work correctly if I specify the HOSTNAME variable on the
command line:

HOSTNAME=`uname -n` make -d install

Since this option sorts of negates at least part of the point in using
make to deal with these files I'd like to find a better solution.

It looks like I can use GNU Make and be able to run (shell <cmd>) to get
the info I need, but I'd rather not install it unless I have to.

Any ideas?

Thanks,

        brian

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
brian davies                       Fluke Corporation

2. System Information

3. How install SSL on HP 580 HP-UX 11 with Iplanet 4.1?, pcumming

4. telnet/telnetd flowcontrol.

5. resetting the Disk Suite disk status

6. lynx for HP-UX 11.x?

7. HELP: configuring apache server path

8. Audit (log) on HP-UX 11 ?

9. Compiling Apache 0.8.11 under HP-UX

10. getpwnam fails in setuid program using NIS+ on HP-UX 11

11. recvfrom on HP-UX 11.

12. Moving files from one filesystem to another on HP-UX 11