Re: Removing files with find (194 Views)
Posts: 17
Registered: ‎04-11-2001
Message 1 of 6 (194 Views)
Accepted Solution

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.
Honored Contributor
Posts: 697
Registered: ‎06-04-1996
Message 2 of 6 (194 Views)

Re: Removing files with find

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


cd /home/me

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

will remove all of the *.o files in the me home directory.
Honored Contributor
Posts: 14,293
Registered: ‎05-29-2000
Message 3 of 6 (194 Views)

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
Posts: 13,832
Registered: ‎06-21-2000
Message 4 of 6 (194 Views)

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
Posts: 1,424
Registered: ‎12-11-2000
Message 5 of 6 (194 Views)

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 {} \;


Esteemed Contributor
Posts: 273
Registered: ‎11-15-2000
Message 6 of 6 (194 Views)

Re: Removing files with find


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

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.