General
Showing results for 
Search instead for 
Do you mean 

Removing files with find

SOLVED
Go to Solution
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.
1 ACCEPTED SOLUTIONS
Honored Contributor Honored Contributor

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.
5 REPLIES
Honored Contributor Honored Contributor

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.
Honored Contributor 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.
Honored Contributor 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.
Honored Contributor 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
-
Highlighted
Esteemed Contributor 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