[HPADM] SUMMARY: find with prune command help

From: Cruz, Alfredo (Alfredo.Cruz@cancercare.on.ca)
Date: Mon Oct 27 2003 - 17:01:46 EST


I tried Mike Keighley suggestion which worked for me is:
find /filesystem \( -name "*.log" -print \) -o \( -name ".snapshot" -prune
\)
 
I haven't tried Andy Craston's suggestions yet but this is his response is
as follows:
 

Some time ago I wrote a small filter called "unfind" which might help you.
A very helpful UNIX admin called Dennis has a copy of it on his website:
http://www.lovelady.com/unix-source.html#unfind
The basic idea is to use the find command to get all the files of interest
and if this list contains some files you don't want pipe though unfind to
remove those entries. So if you have the following directories:
/fs
/fs/.snapshot
and you want to find *.log files under /fs but not under /fs/.snapshot then
use find and unfind in the following way:
find /fs -name "*.log" -print | unfind /fs/.snapshot
Email me if you need any help with it.
Regards,
Andy Cranston.

 
 
 
Bob Vance had another approach but I haven't tested it yet:
 

Consider this example:
/tmp contains some files and directories that I want to delete -- and some
that I want to keep.
linux1 ## ll /tmp | sed 's/^/ /'
total 23
drwxrwxrwt 8 root root 4096 Oct 26 08:23 .
drwxr-xr-x 22 root root 1024 Feb 3 2003 ..
drwxrwxrwt 2 xfs xfs 1024 Oct 25 08:45 .font-unix
-rw-r--r-- 1 root root 0 Oct 26 08:15 keep1
-rw-r--r-- 1 root root 0 Oct 26 08:15 keep12
drwxr-xr-x 2 root root 1024 Oct 26 07:45 keepd
-rw-r--r-- 1 root root 113 Oct 25 16:54 l
drwxr-xr-x 2 root root 12288 Mar 11 2000 lost+found
-rw-r--r-- 1 root root 0 Oct 26 08:15 morkeep11
-rw-r--r-- 1 root root 0 Oct 26 08:15 morkeep12
drwx------ 2 bobv users 1024 Jul 30 08:45 ssh-WMZr3021
drwx------ 2 bobv users 1024 Jul 29 00:41 ssh-YRnw4469
drwx------ 2 bobv users 1024 Feb 18 2003 ssh-dmN24803
-rw-r--r-- 1 root root 0 Oct 26 08:15 trash1
-rw-r--r-- 1 root root 0 Oct 26 08:15 trash2
linux1 ## ll /tmp/keepd | sed 's/^/ /'
total 5
drwxr-xr-x 2 root root 1024 Oct 26 07:45 .
drwxrwxrwt 8 root root 4096 Oct 26 08:23 ..
-rw-r--r-- 1 root root 0 Oct 26 07:45 f1
-rw-r--r-- 1 root root 0 Oct 26 07:45 f2
-rw-r--r-- 1 root root 0 Oct 26 07:45 f3
 
(notice, in the following, that I'm debugging the command by using 'echo' in
front of the actual command to execute.
)
Let's try this:
linux1 ## find /tmp \( -name keepd -o -name lost+found -o -name .font-unix
\) -prune -o -exec echo ' rm -r' {} \;
rm -r /tmp
rm -r /tmp/keep1
rm -r /tmp/keep12
rm -r /tmp/morkeep11
rm -r /tmp/morkeep12
rm -r /tmp/trash1
rm -r /tmp/trash2
rm -r /tmp/l
rm -r /tmp/ssh-YRnw4469
rm -r /tmp/ssh-YRnw4469/agent.4469
rm -r /tmp/ssh-WMZr3021
rm -r /tmp/ssh-WMZr3021/agent.3021
rm -r /tmp/ssh-dmN24803
rm -r /tmp/ssh-dmN24803/agent.24803
This excludes the directory "keepd", but has a few other problems:
it deletes the "keep" files
*and* it includes the base directory "/tmp" !!!!
 
So, let's exclude that stuff:
linux1 ## find /tmp \( -name keepd -o -name lost+found -o -name .font-unix
\) -prune -o \( ! -path /tmp -a ! -name 'keep*' -a ! -name 'morkeep*'
\) -a -exec echo ' rm -r' {} \;
rm -r /tmp/trash1
rm -r /tmp/trash2
rm -r /tmp/l
rm -r /tmp/ssh-YRnw4469
rm -r /tmp/ssh-YRnw4469/agent.4469
rm -r /tmp/ssh-WMZr3021
rm -r /tmp/ssh-WMZr3021/agent.3021
rm -r /tmp/ssh-dmN24803
rm -r /tmp/ssh-dmN24803/agent.24803

 
You can see that this just gets rid of the stuff we don't want anymore.
 
 
 
 
Sundararajan Swaminathan approach is not use the -prune but exclude
/<filesystem/.snapshot. I did a quick test on this and it did not work for
me:

 # find /<filesystem> ! -path /<filesystem>/.snapshot -name "*.log" -atime
+7 -exec rm {} \;

 
Thanks to Mike, Bob and Sundararajan for their input.
 
Alfredo
 
 
 
 

-----Original Message-----
From: Cruz, Alfredo [mailto:Alfredo.Cruz@cancercare.on.ca]
Sent: Saturday, October 25, 2003 6:32 PM
To: 'hpux-admin@dutchworks.nl'
Subject: [HPADM] find with prune command help

Hi,
 
I'm having trouble getting my find command to work with the -prune option.
What I basically want to do is find *.log on a mounted file system but
exclude the directory /<filesystem>.snapshot. When I ran the command, it
still goes to the .snapshot directory which is something I don't want to
happen. The .snapshot directory is a feature of Network Appliance NAS
server which are created for each mounted file systems. It contains
snapshots of the directories and files for the file system. The .snapshot
could have been just a regular subdirectories and the find command still
doesn't work.
 
The command I used is:
find /<filesystem> -name "*.log" -print -name ".snapshot" -exec rm {} \;
 
I even tried but this didn't work either:
 
find /<filesystem> -name "*.log" -print -path /<filesystem>/.snapshot -exec
rm {} \;
 
Any suggestions?
 
Thanks,
 
Alfredo

This e-mail message (and any attachments) may contain confidential and/or
privileged information for the sole use of the intended recipient. Any
review or distribution by anyone other than the person for whom it was
originally intended is strictly prohibited. If you have received this e-mail
in error, please contact the sender and delete all copies. Opinions,
conclusions or other information contained in this e-mail may not be that of
the organization.

This e-mail message (and any attachments) may contain confidential and/or
privileged information for the sole use of the intended recipient. Any
review or distribution by anyone other than the person for whom it was
originally intended is strictly prohibited. If you have received this e-mail
in error, please contact the sender and delete all copies. Opinions,
conclusions or other information contained in this e-mail may not be that of
the organization.

--
             ---> Please post QUESTIONS and SUMMARIES only!! <---
        To subscribe/unsubscribe to this list, contact majordomo@dutchworks.nl
       Name: hpux-admin@dutchworks.nl     Owner: owner-hpux-admin@dutchworks.nl
 
 Archives:  ftp.dutchworks.nl:/pub/digests/hpux-admin       (FTP, browse only)
            http://www.dutchworks.nl/htbin/hpsysadmin   (Web, browse & search)


This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 11:02:35 EDT