Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 01-07-2013, 08:43 PM   #1
Registered: Dec 2011
Posts: 83
Blog Entries: 1

Rep: Reputation: Disabled
How to delete two days older files through script


want to delete files older than 2 days through script can i have a snippet of code..
Old 01-07-2013, 11:03 PM   #2
LQ Guru
Registered: Dec 2011
Distribution: Slackware
Posts: 7,553
Blog Entries: 10

Rep: Reputation: Disabled

A good place to start would be to do some reading to be able to write your first script.
After you compose your script you could post it and other can give you insight/advice-

This is a very good Bash Guide and was recommended by a Moderator; think you will find it helpful.

You mentioned that you want to delete files that are more than 2 days old-
What type of files do you mean?

Some files are configured to run your OS and should not under any circumstances be deleted or removed.
Old 01-08-2013, 12:20 AM   #3
Senior Member
Registered: Sep 2012
Posts: 1,385

Rep: Reputation: 273Reputation: 273Reputation: 273
find /path/for/your/files -mtime +2 -exec rm {} \;
1 members found this post helpful.
Old 01-08-2013, 09:04 AM   #4
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,697

Rep: Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261
you forgot to quote the {} which happens to be a shell special character... (you did remember the ; though)
Old 01-08-2013, 12:18 PM   #5
Registered: Mar 2005
Distribution: Red Hat / Fedora
Posts: 355

Rep: Reputation: 42
Originally Posted by jpollard View Post
you forgot to quote the {} which happens to be a shell special character... (you did remember the ; though)
his quote will work the way it is

find /path/ -mtime +num_days -exec rm {} \;


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
[SOLVED] script to delete files older than X days fstab has noatime enabled panseluta Linux - Server 2 07-27-2011 12:18 PM
Automated script to DELETE files older than 2 days in a Particular folder siddhartha_ece2004 Linux - Newbie 14 07-11-2008 05:46 AM
Script help - delete files older than 45 days but exclude the system files jojothedogboy Linux - Software 3 06-13-2008 03:43 PM
Delete files older then 30 days stefaandk *BSD 1 01-07-2008 08:31 PM
script to auto delete files older than X days nocnoc Programming 17 12-06-2006 08:30 AM

All times are GMT -5. The time now is 09:51 AM.

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