Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 03-07-2007, 03:40 AM   #1
LQ Newbie
Registered: May 2006
Location: Italy
Distribution: RedHat
Posts: 13

Rep: Reputation: 0
deleting files recursively, but not directories

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
Old 03-07-2007, 03:45 AM   #2
Registered: Aug 2006
Distribution: slack
Posts: 323

Rep: Reputation: 30
"find" can delete only files in a directory tree,
(better check result or can delete something important!):
find dir -type f -print0 | xargs -0 ls -l
find dir -type f -print0 | xargs -0 rm

Last edited by ygloo; 03-07-2007 at 03:51 AM.
Old 03-07-2007, 07:01 AM   #3
LQ Newbie
Registered: May 2006
Location: Italy
Distribution: RedHat
Posts: 13

Original Poster
Rep: Reputation: 0
it was so simple...

Thanks a lot!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using chmod to recursively change directories / files [GOD]Anck Linux - Software 6 11-10-2008 07:16 PM
777 directories and deleting files? emme0032 Linux - Security 4 10-31-2006 12:27 PM
trouble deleting files / directories neocontrol Linux - Software 1 07-16-2005 05:09 PM
List all files and recursively open directories. unreal128 Linux - General 2 07-16-2005 03:06 PM
Deleting directories with files in them AMDPwred Linux - General 7 02-16-2003 01:06 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:02 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration