Simpler Navigation coming for Servers and Operating Systems
Coming soon: a much simpler Servers and Operating Systems section of the Community. We will combine many of the older boards, and you won't have to click through so many levels to get at the information you need. If you are looking for an older board and do not find it, check the consolidated boards, as the posts are still there.
cancel
Showing results for 
Search instead for 
Did you mean: 

Removing files with find

SOLVED
Go to solution
Highlighted
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
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