LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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-10-2009, 04:06 AM   #1
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,629

Rep: Reputation: Disabled
Script to delete older files not running .


Hello all,

I have got a script that deletes the files older than 1 day.
Code:
find /path/to/files -type f -mtime +1 | xargs rm -f
But After running this script no file is being deleted. I still have all the files intact in the directory that are older than 1 day.
Anything that need to be changed.
 
Old 01-10-2009, 04:12 AM   #2
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
I do mine off ctime, but I guess it depends what you want. I don't bother with xargs for this either, I use -exec.

Does just
Code:
find /path/to/files -type f -mtime +1
throw anything up?
 
Old 01-10-2009, 07:45 AM   #3
Vit77
Member
 
Registered: Jun 2008
Location: Toronto, Canada
Distribution: SuSE, RHEL, Mageia
Posts: 132

Rep: Reputation: 17
Quote:
Originally Posted by linuxlover.chaitanya View Post
Code:
find /path/to/files -type f -mtime +1 | xargs rm -f
Actually, I'd recommend to use -exec option in a find command, like:
Code:
find /path/to/files -type f -mtime +1 -exec rm -f {} \;
 
Old 01-11-2009, 06:09 PM   #4
yzhong
Member
 
Registered: Jun 2007
Location: sydney
Distribution: redhat , ubuntu, centos
Posts: 56

Rep: Reputation: 16
I use the following it works

touch -d "5 days ago" /tmp/OLD
find . -name '*' ! -newer /tmp/OLD -type f -print0|xargs -0 rm -rf {}

(notes:-print0 will always print the exact filename,can handle space, new line... otherwise file like "ABC DEF.xxx" won't delete)

Last edited by yzhong; 01-11-2009 at 06:11 PM.
 
Old 01-11-2009, 11:08 PM   #5
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,629

Original Poster
Rep: Reputation: Disabled
None of the find commands are working. I tried both of them before coming here.
 
Old 01-11-2009, 11:44 PM   #6
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,461
Blog Entries: 6

Rep: Reputation: 51
Try This...It wont disappoint you :

Code:
find /path/to/files* -mtime +5 -exec rm {} \;
 
Old 01-11-2009, 11:58 PM   #7
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,629

Original Poster
Rep: Reputation: Disabled
Tried the command with -mtime +1 to delete all the files older than one day. Todays 12th Jan and it should delete files created on 10th Jan. But its not deleting them.
 
Old 01-12-2009, 12:06 AM   #8
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,461
Blog Entries: 6

Rep: Reputation: 51
Do this:

Find those files first through
Code:
find /path/to/files* -mtime +5
And Then try deleting anyone of them directly through :
Code:
rm -fr
Is it working?
I guess the permission being the issue?
Do check.
 
Old 01-12-2009, 12:12 AM   #9
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,629

Original Poster
Rep: Reputation: Disabled
Permissions are not the issues. I know bit about linux.
I resolved it. I do not know but removing "+" preceding mtime did it for me.
I went through man page for find more than couple of time and then just gave it a chance and it deleted all the files created on 10th Jan.
 
Old 01-12-2009, 01:25 AM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,326

Rep: Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364
The key point from the manpage:
Code:
       Numeric arguments can be specified as

       +n     for greater than n,

       -n     for less than n,

       n      for exactly n.
 
Old 01-12-2009, 01:27 AM   #11
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,629

Original Poster
Rep: Reputation: Disabled
Yeah I went through it and felt I should give it a try. But mtime should have worked since I had some files that were older than 1 day. So it should have deleted them with mtime +1
 
  


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
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
Help to Delete older Files on asterisk n33d Linux - Server 3 06-05-2008 08:20 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 12:40 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration