Operating System - HP-UX
1819794 Members
3423 Online
109607 Solutions
New Discussion юеВ

I need a script to delete all files from a folder and all subfolders

 
SOLVED
Go to solution
'chris'
Super Advisor

I need a script to delete all files from a folder and all subfolders

hi

I need a perl script or bash to delete ALL files from a folder and from the all subfolders, but it should NOT delete any folders & subfolders.

kind regards
chris
4 REPLIES 4
Tony Scully_2
Valued Contributor
Solution

Re: I need a script to delete all files from a folder and all subfolders

Chris,

I think you can do this with find, from the directory you wan to remove the fiels from:

find . -exec rm {} \;

This wil only remove files, not directories.

T
You CAN do that on HP
Biswajit Tripathy
Honored Contributor

Re: I need a script to delete all files from a folder and all subfolders

Here is a ksh script to do this.

# find /parent_dir -type f | xargs rm -rf

Replace /parent_dir with the parent directory name.
This will delete all regular files in the /parent_dir
directory tree (including subdirectories) and leave
directory files alone.

WARNING: Test before use as the above script will
delete all the files. You can test this by replacing
"rm -rf" in the above script with "echo" and it will
only print the file names. Make sure that those are
the ones you want to delete before using "rm -rf".

- Biswajit
:-)
H.Merijn Brand (procura
Honored Contributor

Re: I need a script to delete all files from a folder and all subfolders

# perl -MFile::Find -e'find(sub{-d or unlink$_},".")'

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Ross Minkov
Esteemed Contributor

Re: I need a script to delete all files from a folder and all subfolders

find . -type f -exec rm {} \;