Operating System - HP-UX
1748198 Members
2587 Online
108759 Solutions
New Discussion юеВ

Re: Removing files with find

 
SOLVED
Go to solution
Stuart McKay
Advisor

Removing files with find

What is the syntax in HP-UX for removing files with the find command, or is there another way to do it.
5 REPLIES 5
Christopher Caldwell
Honored Contributor
Solution

Re: Removing files with find

find [dir] [spec] -exec rm {} \;

example

cd /home/me

find . -name *.o -exec rm {} \;

will remove all of the *.o files in the me home directory.
Bill Hassell
Honored Contributor

Re: Removing files with find

Just a note of caution: find is recursive and be default will descend through all subdirectories. Always leave off the -exec portion for the first run to make sure it finds the files you want to remove. There is no unremove command in HP-UX.


Bill Hassell, sysadmin
Patrick Wallek
Honored Contributor

Re: Removing files with find

Bill has a good point. If I'm going to remove files with find, I will generally do something like:

find /dir -name "filename.*" -exec ll -d {} \;

and then if the list is what I want I'll change the 'll -d' to an 'rm' and let it run.
Tim D Fulford
Honored Contributor

Re: Removing files with find

Yet another point to bear in mind is that if the file is a directory (expecially if you use *'s). use ls -ld or ll -d which does not list the directory entries but the directory itself.

I use
find -name -exec ls -ld {} \;
if this is ok then
find -name -exec rm {} \;

Cheers

Tim
-
Bruce Regittko_1
Esteemed Contributor

Re: Removing files with find

Hi,

Another way you can remove files with find that may be more efficient is to couple it with the xargs command:

find | xargs rm <-options>

To remove all files name core from the /home directory that have not been accessed within a week, issue

find /home -name core -atime +7 | xargs rm

--Bruce
www.stratech.com/training