LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices


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

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

Rep: Reputation: 30
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

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

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

Thanks a lot!
 
  


Reply



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 06:16 PM
777 directories and deleting files? emme0032 Linux - Security 4 10-31-2006 11:27 AM
trouble deleting files / directories neocontrol Linux - Software 1 07-16-2005 04:09 PM
List all files and recursively open directories. unreal128 Linux - General 2 07-16-2005 02:06 PM
Deleting directories with files in them AMDPwred Linux - General 7 02-16-2003 12:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:04 PM.

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