Operating System - HP-UX
1832474 Members
2669 Online
110043 Solutions
New Discussion

Re: how to use `find´ without searching in subdirectories

 

how to use `find´ without searching in subdirectories

Hi,

I want to find files in a directory, without searching in subdirectories. The subdirectories are on the same volume.

Find /tmp –type f –exec ls {} \; set temp_var = áwk ´{print $1}´´

I have made some Trials with the option –prune and –depth, but this was not successful. I hope you can help me.

Thank you

Rudiger
7 REPLIES 7
Ralph Grothe
Honored Contributor

Re: how to use `find´ without searching in subdirectories

Use the -prune flag of find
Madness, thy name is system administration
Senthil Prabu.S_1
Trusted Contributor

Re: how to use `find´ without searching in subdirectories

Hi,
you can use the find command with following option to exclude directories;

find . -name $DIRNAME -prune -o -print

where, $DIRNAME is the name of the directory to be excluded.

To Exclude multiple directories

find / -type d \( -name DIR1 -o -name DIR2 -o -name DIR3 \) -prune -o -type d -print

HTH,

Prabu.S
One man's "magic" is another man's engineering. "Supernatural" is a null word.
john korterman
Honored Contributor

Re: how to use `find´ without searching in subdirectories

Hi,

other prune examples:


one sub-dir
# find /etc/* -prune -type f -name "T*"
/etc/TIMEZONE
/etc/TIVGUID

two sub-dirs
# find /etc/*/* -prune -type f -name "T*"
/etc/zoneinfo/Turkey

three sub-dirs
# find /etc/*/*/* -prune -type f -name "T*"
/etc/zoneinfo/Australia/Tasmania

regards,
John K.
it would be nice if you always got a second chance
Rodney Hills
Honored Contributor

Re: how to use `find´ without searching in subdirectories

use "-path" option of find command-

find /tmp -type f -path "./*" -prune -exec ls {} \;

or if you get the gnu version of find at
http://hpux.cs.utah.edu/hppd/hpux/Gnu/findutils-4.2.23/

then you could do-
find /tmp -type f -maxdepth 1 exec ls {} \;

HTH

--Rod Hills
There be dragons...
Rodney Hills
Honored Contributor

Re: how to use `find´ without searching in subdirectories

Oops, that first find should have been-
find /tmp -type f -path "/tmp/*" -prune -exec ls -l {} \;

-- Rod Hills
There be dragons...

Re: how to use `find´ without searching in subdirectories

Hi Rod,

find /tmp -type f -path "/tmp/*" -prune -exec ls -l {} \;

will not skip subdirectories.

I have now tested the command

find /tmp -type f ! -path "/tmp/*/*" -exec ls -l {} \;

and it is working well

Thanks to all for your help

Rudiger
Rodney Hills
Honored Contributor

Re: how to use `find´ without searching in subdirectories

Try putting the -type f after the -prune. That has worked for me.

find /tmp -path "/tmp/*" -prune -type f -exec ls -l {} \;

HTH

-- Rod Hills
There be dragons...