Jump to content
 English      
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
     Forums advanced search
HP.com Home
IT Resource Center Forums > HP-UX > system administration

how to use "find" command

» 

IT Resource Center

» Login
» Register
» My profile
» Search knowledge base
» Forums
» Patch database
» Download drivers, software and firmware
» Warranty check
» Support Case Manager
» Software Update Manager
» Training and Education
» More maintenance and support options
» Online help
» Site map

Member icons
 
 HP moderator  HP moderator
 Expert in this area  Expert in this area
Member status
ITRC Pro ITRC Pro
250 points
ITRC Graduate ITRC Graduate
500 points
ITRC Wizard ITRC Wizard
1000 points
ITRC Royalty ITRC Royalty
2500 points
ITRC Pharaoh ITRC Pharaoh
7500 points
Olympian Olympian
20000 points
1-Star Olympian 1-Star Olympian
40000 points
2-Star Olympian 2-Star Olympian
80000 points
»  How to earn points
»  Support forums FAQs
Question status
Magical answer Magical answer
Message with a response that solved the author's question
Favorites status
Add to my favorites Add to my favorites
Delete from my favorites Delete from my favorites
This thread has been closed Thread closed
 

Content starts here
   Create a new message    Receive e-mail notification if a new reply is posted  Reply to this message
Author Subject: how to use "find" command      Add to my favorites
public
Dec 19, 2006 01:34:29 GMT   

I want to use "find" command ,only search in the current directory,not include the sub-directory.
how can I do?
Note: If you are the author of this question and wish to assign points to any of the answers, please login first.For more information on assigning points ,click here


Sort Answers By: Date or Points
Yogeeraj This member has accumulated 7500 or more points
Dec 19, 2006 01:45:46 GMT    Unassigned

hi,

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

maybe you can instead use:

ls -al |grep <file to find>

maybe others have a better solution

kind regards
yogeeraj
Senthil Prabu.S This member has accumulated 1000 or more points
Dec 19, 2006 04:21:23 GMT    Unassigned

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
Stanislav Bocinec
Dec 19, 2006 04:58:14 GMT    Unassigned

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 This member has accumulated 7500 or more points
Dec 19, 2006 05:12:27 GMT    Unassigned

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 This member has accumulated 500 or more points
Dec 19, 2006 05:33:03 GMT    Unassigned

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.
James R. Ferguson This member has accumulated 80000 or more points
Dec 19, 2006 07:26:07 GMT    Unassigned

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. This member has accumulated 7500 or more points
Dec 19, 2006 10:00:48 GMT    Unassigned

Public,

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

Cheers,
Raj.
Sp4admin This member has accumulated 1000 or more points
Dec 19, 2006 13:59:45 GMT    Unassigned

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 This member has accumulated 1000 or more points
Dec 19, 2006 14:05:11 GMT    Unassigned

I use:

find . \( -type d ! -name . -prune \) -o \( <search terms> -print \)
Sandman! This member has accumulated 7500 or more points
Dec 19, 2006 14:24:23 GMT    Unassigned

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 This member has accumulated 2500 or more points
Dec 19, 2006 14:36:00 GMT    Unassigned

One more - much like the above one:

find * .* -prune
TwoProc This member has accumulated 2500 or more points
Dec 19, 2006 15:18:27 GMT    Unassigned

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.
 
Create a new message    Receive e-mail notification if a new reply is posted   Reply to this message
 
 
Printable version
Privacy statement Using this site means you accept its terms
© 2010 Hewlett-Packard Development Company, L.P.