LinuxQuestions.org
Visit Jeremy's Blog.
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 01-07-2013, 09:43 PM   #1
azheruddin
Member
 
Registered: Dec 2011
Posts: 77
Blog Entries: 1

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


Hi,

want to delete files older than 2 days through script can i have a snippet of code..
 
Old 01-08-2013, 12:03 AM   #2
Ztcoracat
LQ Guru
 
Registered: Dec 2011
Distribution: Slackware
Posts: 6,407
Blog Entries: 6

Rep: Reputation: Disabled
Hi!

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-

http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://linuxconfig.org/Bash_scripting_Tutorial
http://www.tldp.org/

This is a very good Bash Guide and was recommended by a Moderator; think you will find it helpful.
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html

http://tldp.org/LDP/abs/html/

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, 01:20 AM   #3
kooru
Senior Member
 
Registered: Sep 2012
Posts: 1,385

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

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

Rep: Reputation: 42
Quote:
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 {} \;
 
  


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


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

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration