Operating System - HP-UX
1752781 Members
5978 Online
108789 Solutions
New Discussion юеВ

Re: About the "find" comand

 
SOLVED
Go to solution
peterchu
Super Advisor

About the "find" comand

I want to use the below "find" command to search the files, this statement will search all the files under /tmp includes subdirecties , how to make it only the files under /tmp but exclude its subdirecties ? thx


find /tmp -mtime +10 -exec ls -lt {} \;
9 REPLIES 9
Robert-Jan Goossens
Honored Contributor
Solution

Re: About the "find" comand

Hi,

I don't think it is possible in one single find command.

You could use
find /tmp -mtime +10 -exec ls -lt {} \; | grep -v xxxx | grev -v xxxx

and exclude the subdirectories.

Hope this helps,
Robert-Jan
Sanjay Kumar Suri
Honored Contributor

Re: About the "find" comand

Can you try using -prune option of find command (for example):

$find /var/home/sks -name big -o -type d -prune

Also refer the link:

http://www.grymoire.com/Unix/Find.html

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Ralph Grothe
Honored Contributor

Re: About the "find" comand

I'm afraid, the HP-UX find is a pretty basic version of find with few features.
Therefore if you stick to this find you will have to "-prune" all directories that need to be excluded, which can really get a bit of a pain (i.e. lots of logical operands and ugly brackets).
The only little alleviation would be to maybe restrict the serach to the filesystem, and using -xdev to prevent crossing of filesystems (but this doesn't improve anything in your case)

To make your job easier I'd suggest you install the GNU find on your HP-UX box.
This find offers apart from many more other features an option -maxdepth where you can restrict the search depth (not to be mixed up with the -depth option!)

http://www.gnu.org/software/findutils/manual/html_mono/find.html

Lust but not least you could use Perl and File::Find which offers you the biggest flexibilty in searching for files easily.

http://search.cpan.org/search?query=File%3A%3AFind&mode=all
Madness, thy name is system administration
bhoopathi_1
Frequent Advisor

Re: About the "find" comand

You can use -type -f option.

find /tmp -mtime +10 -type f -exec ls -lt {}\;

you can also include -xdev option to search files only in the particular mount point.
Michael D. Zorn
Regular Advisor

Re: About the "find" comand

Sanjay gave a link to grymoire. Atthe end they mention "Fast Find", which seems to be a patch to find that lets it search a database first.

I've been using something similiar for a few years: at midnight, my crontab runs a script that calls find:

find /home/zorn -type f -exec ll -o {} \; > /home/zorn/Zfiles

When I need to find a file, I just grep Zfiles.

You could easily have this run off /home.

For finding system files, I use

find /bin /etc /lib /opt /sbin /usr /var -type f -name $1 -exec ll {} \;




Hein van den Heuvel
Honored Contributor

Re: About the "find" comand


How about a....

find /tmp/* -prune -mtime +10 -exec ls -lt {} \;



Hein.
Rodney Hills
Honored Contributor

Re: About the "find" comand

gnu "find" is more flexible, but you can use the "path" option with the Hpux supplied "find" to get only one level-

find /tmp -type f -path "/tmp/*" -prune -print

HTH

-- Rod Hills
There be dragons...
Sanjay_6
Honored Contributor

Re: About the "find" comand

Hi,

try "-only" option with find,

find /tmp -only -mtime +10 -exec ls -lt {} \;

Hope this helps.

Regds
Cheryl Griffin
Honored Contributor

Re: About the "find" comand

You can reward the many people who have assisted you by assigning points to their posts.

For steps how to assign points see:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33
"Downtime is a Crime."