LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 07-08-2009, 03:56 PM   #1
Joan Murt
LQ Newbie
 
Registered: Jul 2006
Posts: 14

Rep: Reputation: 0
find -exec command to recursively delete files and folders in folders with X name


Hello all,

First of all I'm a Linux newbie (at much) so be gentle please... :P

I've been able to see that the version control software that the people on the design department is generating a special folder named OBSOLETE for each project.

The data Inside each of those folders is not important.

I'm trying to delete all the contents inside those folders recursively without deleting the folder itself.

Now I've been able to delete the obsolete folders, and even the help in the software tells me that doing it won't hurt the system... I would like not to do it.

Now I've used:

find . -name obsolete -exec rm -rf {} \;

The problem here is that I also remove the folder obsolete...

Does anyone know what should I write in order to remove the contents of all the obsolete folders and not the folders it selves?

Thank you in advance.
 
Old 07-08-2009, 04:18 PM   #2
bytepool
LQ Newbie
 
Registered: Feb 2005
Location: /home/sweden/gothenburg
Distribution: Debian, Ubuntu
Posts: 7

Rep: Reputation: 0
Hi,

I believe the following should do the trick:
Code:
find ./ -wholename './obsolete/*' -exec echo "rm -rf" {} ';'
It basically says to delete all the subdirectories and files of ./obsolete. Remove the echo when you think it gives the correct output.

Edit:
Eh, I just saw that is not what you want, obsolete may also appear somewhere in the directory structure, right? Then '*/obsolete/*' should do it, if I am not mistaken.

Edit2:
No, that won't do it either, that will also remove the whole path from your current directory to the obsolete directory. Mhh, not as simple as I thought.

Edit3:
The version from pengrath below should work, but it did not really appeal to me, so this is what I came up with instead; borrowing his approach though.
Code:
find . -name obsolete -prune | while read content; do rm -rfv ${content}/*; done
This one actually works.

Regards,
bytepool

Last edited by bytepool; 07-08-2009 at 05:24 PM.
 
Old 07-08-2009, 04:35 PM   #3
pengrath
LQ Newbie
 
Registered: Feb 2009
Distribution: Arch
Posts: 13

Rep: Reputation: 0
I'm using bash:

not sure if this is the kind of thing you are looking for but perhaps try this on a test case of your own.

rm -rf `find . -name obsolete | sed s/$/\\\/*/g `

note on syntax:
`` - means execute whats inside here as if it were a command you can also use $()

*this will give you an error if there is an empty obsolete directory.
*I love regular expressions

Last edited by pengrath; 07-08-2009 at 04:37 PM. Reason: syntax mistake
 
  


Reply


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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
command to delete folders on /tmp ceantuco Linux - Newbie 7 01-08-2009 08:10 AM
find -delete folders Meson Linux - General 7 04-16-2008 01:30 PM
Entering folders recursively to run script on files nested inside, ubuntu 7.10 aidansmoker Linux - Newbie 4 11-11-2007 11:39 PM
what is the command to delete files and folders quickly. ravi Linux - General 1 03-13-2007 12:09 PM
How to unzip files recursively inside folders? jessdog9001 Linux - Software 2 03-22-2006 12:59 PM


All times are GMT -5. The time now is 10:37 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration