removing files in a given subfolder | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

removing files in a given subfolder

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-08-2012
Hugi Hugi is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 9 October 2012, 10:10 AM EDT
Posts: 3
Thanks: 1
Thanked 1 Time in 1 Post
removing files in a given subfolder

Hello,

im new to this forum and directly start with a problem...

I have a folder structure like :

Code:
/folder/01/1/oldfiles
/folder/01/2/oldfiles
/folder/02/1/oldfiles
/folder/0x/y/oldfiles

Every Month a new folder adds automaticly from the system.

Now i need an idea how to search for files inside every oldfiles folder and remove files older than 20 days.
I can use "find . -mtime +20 -exec rm {} \;" to remove all files older than 20 days.
With "ls -lR|grep "\/Oldfiles" i recieve a list of all folders.

How can i combine this without big scripting?

thanks
Andreas

Moderator's Comments:
Please use code tags next time for your code and data.

Last edited by vbe; 10-08-2012 at 09:39 AM..
Sponsored Links
    #2  
Old 10-08-2012
Lem Lem is offline
Registered User
 
Join Date: Jun 2012
Last Activity: 13 June 2014, 10:20 AM EDT
Location: Lombardia, Italy
Posts: 182
Thanks: 5
Thanked 38 Times in 38 Posts
For example:

Code:
find /folder -maxdepth 4 -mindepth 4 -type f -mtime +20 -delete

--
Bye
Sponsored Links
    #3  
Old 10-08-2012
Hugi Hugi is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 9 October 2012, 10:10 AM EDT
Posts: 3
Thanks: 1
Thanked 1 Time in 1 Post
Sorry, dont ask me why i posted in german..

"your idea sounds nice, but if there is another folder on same level, the files inside will be deleted too."

Wirkt verführerisch, jedoch trifft das dann auch auf Ordner zu die evtl auf gleicher Ebene angelegt wurden.
Ich würde schon gerne genauer sortieren. Dann bleibt mir doch wohl nur scripten...

Last edited by Hugi; 10-08-2012 at 04:51 PM..
    #4  
Old 10-08-2012
Lem Lem is offline
Registered User
 
Join Date: Jun 2012
Last Activity: 13 June 2014, 10:20 AM EDT
Location: Lombardia, Italy
Posts: 182
Thanks: 5
Thanked 38 Times in 38 Posts
Pardon? I'm sorry, but I don't know a word of German.
However Google translator helped me a bit, this time.

I thought it was your case, and that you didn't have any other directories at level 4 in your structure. You could try:

Code:
find /folder -maxdepth 4 -mindepth 4 -path "*/folder/0[0-9]/[0-9]/oldfiles/*" -type f -mtime +20 -delete

--
Bye
The Following User Says Thank You to Lem For This Useful Post:
Hugi (10-09-2012)
Sponsored Links
    #5  
Old 10-08-2012
alister alister is offline
Registered User
 
Join Date: Dec 2009
Last Activity: 11 June 2014, 8:40 PM EDT
Posts: 3,231
Thanks: 179
Thanked 973 Times in 789 Posts
Quote:
Originally Posted by Hugi View Post
Wirkt verführerisch, jedoch trifft das dann auch auf Ordner zu die evtl auf gleicher Ebene angelegt wurden.
Ich würde schon gerne genauer sortieren. Dann bleibt mir doch wohl nur scripten...
Please read the rules.

From The UNIX and Linux Forum Rules: You Must Read this Before Posting (emphasis is mine):
Quote:
(9) Edit your posts if you see spelling or grammar errors (don't write in cyberchat or cyberpunk style). English only.
Regards and welcome to the forum,
Alister
Sponsored Links
    #6  
Old 10-09-2012
Hugi Hugi is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 9 October 2012, 10:10 AM EDT
Posts: 3
Thanks: 1
Thanked 1 Time in 1 Post
This looks great. Sorry again for the german.

I will test it tomorrow and give you an report. I forget over the years how powerfull the find command in Linux was.. More and more i feel like the stupid windows Administrator i laughed about 10 years ago.

Hugi

---------- Post updated 9th Oct 2012 at 08:53 AM ---------- Previous update was 8th Oct 2012 at 03:53 PM ----------

Quote:
Originally Posted by Lem View Post

Code:
find /folder -maxdepth 4 -mindepth 4 -path "*/folder/0[0-9]/[0-9]/oldfiles/*" -type f -mtime +20 -delete

--
Bye
This was the solution, i changed -path to -wholename (-iwholename because of case sensitive problem in my structure), did some modifications to the pattern, and it work as wanted.

Thank you
The Following User Says Thank You to Hugi For This Useful Post:
alister (10-09-2012)
Sponsored Links
    #7  
Old 10-09-2012
alister alister is offline
Registered User
 
Join Date: Dec 2009
Last Activity: 11 June 2014, 8:40 PM EDT
Posts: 3,231
Thanks: 179
Thanked 973 Times in 789 Posts
Thank you for reporting back with your solution. In the future, it may help someone else.

Regards,
Alister
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Create subfolder within folder in one command lalitpct Shell Programming and Scripting 3 05-28-2012 05:03 AM
Link multiple files from different subfolder to a new subfolder total_ysf Shell Programming and Scripting 6 07-19-2011 04:13 AM
Unzip subfolder to some path. mrwatkin UNIX for Dummies Questions & Answers 0 11-09-2009 10:19 AM
How to Get the count fo files in each subfolder sanjangr UNIX for Dummies Questions & Answers 1 10-06-2009 05:30 AM
Samba read only subfolder. sparcman UNIX and Linux Applications 0 10-05-2009 11:59 AM



All times are GMT -4. The time now is 02:41 AM.