The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Deleting / finding files older than X days missess a day guruparan18 Shell Programming and Scripting 4 05-08-2008 07:09 AM
Removing files older than 7 days texasoeb UNIX for Dummies Questions & Answers 3 04-20-2007 05:04 PM
tar files older than 30 days wfch UNIX for Dummies Questions & Answers 6 04-19-2004 05:40 AM
How can I delete files older than 7 days? odogbolu98 UNIX for Dummies Questions & Answers 3 02-26-2002 08:35 PM
delete files older than 7 days lesstjm UNIX for Dummies Questions & Answers 1 11-06-2001 10:43 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-25-2008
shezam shezam is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 2
Deleting files older than 7 days

Hi Guys,

I want to delete folder/files older than 7 days. Im using the command below.

find /test/test1 -mtime +7 -print0 | xargs -0 rm -Rf /test/test1/*

which works ok, but it deletes the test1 folder as well which i dont want. The test1 folder will have a list of sub-folders which in turn will have files.I wont know the name of these sub-folders or files. I want to delete these sub -folders and files and preserve the test1 folder.

Any one any ideas.

Help much appreciated. Thanks.
  #2 (permalink)  
Old 04-25-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,441
Take a look at:
advanced/complex uses of the find command
delete file older than N days
  #3 (permalink)  
Old 04-25-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,807
another way:

Code:
cd /test/test1
find . -mtime +7 -exec rm -f {} \;

  #4 (permalink)  
Old 04-25-2008
shezam shezam is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 2
Quote:
Originally Posted by jim mcnamara View Post
another way:

Code:
cd /test/test1
find . -mtime +7 -exec rm -f {} \;
When i try this which i know should work im weirdly getting

find: missing argument to `-exec'
  #5 (permalink)  
Old 07-09-2008
abiinfa abiinfa is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 3
you might be missing -type f in the command.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:27 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0