Find files in current directory excluding sub-directories - HP UX

This is a discussion on Find files in current directory excluding sub-directories - HP UX ; 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 ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Find files in current directory excluding sub-directories

  1. 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.


  2. 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


  3. 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 \)


  4. 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"


  5. Re: Find files in current directory excluding sub-directories

    Quote Originally Posted by unix View Post
    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 \)
    Well, great work! You have helped me to improve my knowledge about this field. Thank you so much for sharing.

+ Reply to Thread