Mailinglist Archive: opensuse (4547 mails)

< Previous Next >
Re: [SLE] find and delete older file
  • From: Robert Paulsen <robert@xxxxxxxxxxxxxxxxx>
  • Date: Fri, 21 May 2004 06:08:35 -0500
  • Message-id: <200405210608.35833.robert@xxxxxxxxxxxxxxxxx>
On Friday 21 May 2004 01:30, Agi Subagio wrote:
> I have a script that create a backup file in regular schedule (run everyday
> at 2 AM).
> But after several weeks, my harddisk is getting full.
> I want to delete older backup file that not modified/create after 30 days
> ago.
>
> I have used command;
> $ find ./test -mtime +30 -exec 'rm -f *'
> But it seems, the rm command is not work.
>

The command "rm -f *" will remove all (non-hidden) files regardless of exactly
which files are found by the find command. Let's say the find command found 3
files. That will simply result in the following 3 commands being issued:

rm -f *
rm -f *
rm -f *

Not what you wanted! You really wanted something like the following:

rm -f ./test/old_file_one
rm -f ./test/old_file_two
rm -f ./test/old_file_three

You need something like this:

find test -mtime +30 -exec rm {} \;

The {} tells the find command where in the executed command to place the name
of each found file (one at a time). The ; tells -exec where the end of the
command is. The \ is needed to hide the ; from the shell which otherwise
would strip it off before passing the command line to the find command.

--
Robert C. Paulsen, Jr.
robert@xxxxxxxxxxxxxxxxx

< Previous Next >
References