LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   deleting files recursively, but not directories (https://www.linuxquestions.org/questions/linux-general-1/deleting-files-recursively-but-not-directories-535303/)

tantan 03-07-2007 02:40 AM

deleting files recursively, but not directories
 
Hi,
I'm dealing with this kind of problem.
I have a tree of many directories and subdirectories, and I wanto to make a script that delete all files existing in this tree, but not directories, so I can have my tree empty.
The problem is that if I use " rm -rf * " , the command deletes also directories, because with " -r * " it deletes also directories if empty, not only files.
Does anybody have a tip?

Thanks in advance

ygloo 03-07-2007 02:45 AM

hello
"find" can delete only files in a directory tree,
(better check result or can delete something important!):
Code:

find dir -type f -print0 | xargs -0 ls -l
then:
Code:

find dir -type f -print0 | xargs -0 rm

tantan 03-07-2007 06:01 AM

Wonderful!!!
it was so simple...

Thanks a lot!


All times are GMT -5. The time now is 08:15 AM.