Query: I'm looking for a perl script or bash to delete ALL files from a folder and all subfolders, but it should NOT delete any folders & subfolders. Solution: Well it could look something like this if it was run from in the directory that you want to remove the contents from. Code: rm */*/*/*
This goes down three levels plus the origional directory. But be carful with the 'rm' command once used there is
no getting it back.
or
If you can find a way of skipping directories with: Code: rm -rf directory/*
or
Easy, no perl needed, just one line bash. Make sure you run it in the directory you want to have your files (only) removed Code: find . -type f -exec rm -rf {} \;
or This code was originally written to delete all folders and subfolders with in a directory. Commenting out rmdir can suit your need. #!/usr/bin/perl
sub deldir {
@files = grep { !/^\.{1,2}/ } @files;
#rmdir($dirtodel);
Have a Linux Problem
Linux Books
Linux Home: Linux System Administration Hints and Tips (c) www.gotothings.com All material on this site is Copyright.
|