LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 08:43 PM   #1
azheruddin
Member
 
Registered: Dec 2011
Posts: 91
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-07-2013, 11:03 PM   #2
Ztcoracat
LQ Guru
 
Registered: Dec 2011
Distribution: Slackware, MX 18
Posts: 9,484
Blog Entries: 15

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

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

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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
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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:55 PM.

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
Open Source Consulting | Domain Registration