LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Script to delete older files not running . (https://www.linuxquestions.org/questions/linux-newbie-8/script-to-delete-older-files-not-running-696263/)

linuxlover.chaitanya 01-10-2009 04:06 AM

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.

billymayday 01-10-2009 04:12 AM

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?

Vit77 01-10-2009 07:45 AM

Quote:

Originally Posted by linuxlover.chaitanya (Post 3403344)
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 {} \;

yzhong 01-11-2009 06:09 PM

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)

linuxlover.chaitanya 01-11-2009 11:08 PM

None of the find commands are working. I tried both of them before coming here.

your_shadow03 01-11-2009 11:44 PM

Try This...It wont disappoint you :

Code:

find /path/to/files* -mtime +5 -exec rm {} \;

linuxlover.chaitanya 01-11-2009 11:58 PM

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.

your_shadow03 01-12-2009 12:06 AM

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.

linuxlover.chaitanya 01-12-2009 12:12 AM

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.

chrism01 01-12-2009 01:25 AM

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.

:)

linuxlover.chaitanya 01-12-2009 01:27 AM

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


All times are GMT -5. The time now is 06:05 AM.