Unix Technical Forum

Find files in current directory excluding sub-directories

This is a discussion on Find files in current directory excluding sub-directories within the HP-UX Operating System forums, part of the Unix Operating Systems category; --> I use following two methods to find files in a directory but not its sub-directories on HP-UX B.11.11. $ ...


Go Back   Unix Technical Forum > Unix Operating Systems > HP-UX Operating System

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-17-2008, 06:48 AM
lovecreatesbea...@gmail.com
 
Posts: n/a
Default Find files in current directory excluding sub-directories

I use following two methods to find files in a directory but not its
sub-directories on HP-UX B.11.11.

$ find /home/jhl -type f ! -path './*/*' -name "*.c"
$ find /home/jhl -type f -prune -name "*.c"

But both present me with files in sub-directories.

Can you teach me how to find files in current directory only? Thank you.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-17-2008, 06:48 AM
Jon Fife
 
Posts: n/a
Default Re: Find files in current directory excluding sub-directories


lovecreatesbea...@gmail.com wrote:
> I use following two methods to find files in a directory but not its
> sub-directories on HP-UX B.11.11.
>
> $ find /home/jhl -type f ! -path './*/*' -name "*.c"
> $ find /home/jhl -type f -prune -name "*.c"
>
> But both present me with files in sub-directories.
>
> Can you teach me how to find files in current directory only? Thank you.


Hi,

Try the following:
$ find /home/jhl -path "/home/jhl/*" -prune -name "*.c"

Jon

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-17-2008, 06:48 AM
lovecreatesbea...@gmail.com
 
Posts: n/a
Default Re: Find files in current directory excluding sub-directories


Jon Fife wrote:
> lovecreatesbea...@gmail.com wrote:
> > I use following two methods to find files in a directory but not its
> > sub-directories on HP-UX B.11.11.
> >
> > $ find /home/jhl -type f ! -path './*/*' -name "*.c"
> > $ find /home/jhl -type f -prune -name "*.c"
> >
> > But both present me with files in sub-directories.
> >
> > Can you teach me how to find files in current directory only? Thank you.

>
> Try the following:
> $ find /home/jhl -path "/home/jhl/*" -prune -name "*.c"


Thank you.

Your method works on Linux. I will try it later on HP-UX.

I've learnt following two commands from other people. When I put real
absolute pathname instead of . (dot) after find, the find command will
find files in sub-directories still, so I change the directory then
issue find command with . (dot), I don't understand why it works this
way.

$ cd /home/jhl \
find . -name "*" -type f ! -path '.*/*/*'

$ cd /home/jhl \
find . -name "*" -type f \( -path '.*/*/*' -prune -o -print \)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-17-2008, 06:48 AM
lovecreatesbea...@gmail.com
 
Posts: n/a
Default Re: Find files in current directory excluding sub-directories


Jon Fife wrote:
> lovecreatesbea...@gmail.com wrote:
> > I use following two methods to find files in a directory but not its
> > sub-directories on HP-UX B.11.11.
> >
> > $ find /home/jhl -type f ! -path './*/*' -name "*.c"
> > $ find /home/jhl -type f -prune -name "*.c"
> >
> > But both present me with files in sub-directories.
> >
> > Can you teach me how to find files in current directory only? Thank you.

>
> Hi,
>
> Try the following:
> $ find /home/jhl -path "/home/jhl/*" -prune -name "*.c"


Thank you.

I can put full pathname in the pathname list of find now.

$ find /home/jhl -name "*.txt" -maxdepth 1

$ p='/home/jhl'; d='/*'; \
find "$p" -path "$p$d" -prune -name "*" -type f

$ p='/home/jhl'; d='/*/*'; \
find "$p" -name "*.c" -type f \( -path "$p$d" -prune -o -print \)

$ p='/home/jhl'; d='/*/*'; \
find "$p" -name "*.h" -type f ! -path "$p$d"

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:36 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com