Operating System - HP-UX
1820485 Members
2405 Online
109624 Solutions
New Discussion юеВ

Re: how to use "find" command

 
public
Regular Advisor

how to use "find" command

I want to use "find" command ,only search in the current directory,not include the sub-directory.
how can I do?
12 REPLIES 12
Yogeeraj_1
Honored Contributor

Re: how to use "find" command

hi,

I can't find any switch in the find command for this purpose.

maybe you can instead use:

ls -al |grep

maybe others have a better solution

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Senthil Prabu.S_1
Trusted Contributor

Re: how to use "find" command

Hi,
Yes, you can do it using "depth" switch. On my linux machine, I can parse only on current dir, not on its sub-dir with this command;

#find . -maxdepth 1

where, 1 is the depth of dir to parse....

I am not sure this switch works on HP-UX.

Note:
I dont have a HP mac to test it.

HTH,
Prabu.S
One man's "magic" is another man's engineering. "Supernatural" is a null word.
Stanislav Bocinec
Regular Advisor

Re: how to use "find" command

and is there a necessity of using find command?
if you want to find only in current dir,i would use combination of 'ls' and 'grep' command,e.g. ls -al|grep "what u want" ;)
s.
Peter Godron
Honored Contributor

Re: how to use "find" command

Hi,
not the nicest solution, but this may work:
# Produce a list of direct sub-directories
ls -p1 | grep -e'/' > a.lis
# Get list of files, but exclude all direct sub-directories
find . | egrep -v -f a.lis

example:
I have two files called a.c, one in current and one in test sub-directory
$ find . -name a.c
./a.c
./test/a.c

$ ls -p1 | grep -e'/' > a.lis
$ find . -name a.c | egrep -v -f a.lis
./a.c

Only the current a.c is found !
lawrenzo
Trusted Contributor

Re: how to use "find" command

find -prune works on AIX but not sure on HP.

from the man page:

-prune
Always evaluates to the value True. Stops the descent of the current path name if it is a directory. If the -depth flag is
specified, the -prune flag is ignored.
hello
James R. Ferguson
Acclaimed Contributor

Re: how to use "find" command

Hi:

Well, you could do the following. The example assumes that you want to find all *files* that begin with the letter "p" in the working directory:

# cd /pathname
# find . -type f -name "p*" ! -path "./*/*"

Regards!

...JRF...

Raj D.
Honored Contributor

Re: how to use "find" command

Public,

You can use the -xdev option if pointing to a mount point directory ,

Cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
Sp4admin
Trusted Contributor

Re: how to use "find" command

Hi

just cd into the directory you want to look in and do "find . -name filename" or to chek the whole system do "find / -name filename"

sp,
Jonathan Fife
Honored Contributor

Re: how to use "find" command

I use:

find . \( -type d ! -name . -prune \) -o \( -print \)
Decay is inherent in all compounded things. Strive on with diligence
Sandman!
Honored Contributor

Re: how to use "find" command

To see all files in the current folder w/o searching any sub-directories:

# find . -path "./*" -prune -type f

To see all files and sub-dirs in the current dir (without going into any sub-dir) remove the "-type" option to the above find command, i.e.

# find . -path "./*" -prune

~hope it helps
TwoProc
Honored Contributor

Re: how to use "find" command

One more - much like the above one:

find * .* -prune
We are the people our parents warned us about --Jimmy Buffett
TwoProc
Honored Contributor

Re: how to use "find" command

Just for fun,

I kept fooling with this idea and got a neater output - which is funny enough - almost like "ls -a 1". It takes JRF's output and removes the leading "./*"

find . -path "./*" -prune -exec basename {} \;

I liked the output, but I didn't like how the hidden files (files starting with ".") didn't come out first, so I sorted them to get that "almost ls" look.

find . -path "./*" -prune -exec basename {} \; | sort

Of course, as noted before - by adding "-type f" or "-type d" to the find command returns just files or directories, respectively.


We are the people our parents warned us about --Jimmy Buffett