Operating System - HP-UX
1834926 Members
2708 Online
110071 Solutions
New Discussion

Re: Delete files with .Z extension

 
Glenn Bohrman
Occasional Contributor

Delete files with .Z extension

I am trying to find a way to delete all files in a few different directories with .Z exetension in HP UX 11.11. I also have a few folders called archive that I would like to delete with a script rather than search for all of them.
4 REPLIES 4
Pete Randall
Outstanding Contributor

Re: Delete files with .Z extension

Try:

find /dir1 /dir2 -name "*.Z" -exec rm {} \;

-and-

find /dir1 -name archive -exec rm {} \;


Pete

Pete
Bharat Katkar
Honored Contributor

Re: Delete files with .Z extension

One more way to do it:

# find ./ -name *.Z -print | xargs rm

Regards,
You need to know a lot to actually know how little you know
Alan Meyer_4
Respected Contributor

Re: Delete files with .Z extension

To remove the ALL archive "folders";

find / -type d -name archive -exec rmdir {} \;

if you don't wish to remove ALL archive "folders", cd to the parent directory and change the command to;

find . -type d -name archive -exec rmdir {} \;
" I may not be certified, but I am certifiable... "

Re: Delete files with .Z extension

It might make sense to list the files and directories to verify that you are removing what you want to remove prior to running the commands above:

find /dir1 /dir2 -name "*.Z" -exec ls -ldb {} \+

-and-

find /dir1 -name archive -exec ls -ldb {} \+


Just a suggestion to save the headaches of accidently removing something you didn't intend, or to at least have a report of what is being removed for reporting purposes.

Also note the plus (+) at the end of the "find" command as opposed to a semicolon makes the find run much faster. I say this with all due respect to Pete and Alan.

Regards,
Steve