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. $ ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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. |
| |||
| 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 |
| |||
| 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 \) |
| ||||
| 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" |
| Thread Tools | |
| Display Modes | |
|
|