Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Deleting old files

Received: by 10.180.75.197 with SMTP id e5mr3125947wiw.1.1350352537476;
        Mon, 15 Oct 2012 18:55:37 -0700 (PDT)
MIME-Version: 1.0
Path: q10ni65138168wif.0!nntp.google.com!feeder3.cambriumusenet.nl!feed.tweaknews.nl!94.232.116.13.MISMATCH!feed.xsnews.nl!border-3.ams.xsnews.nl!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news.panservice.it!feeder.erje.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Barry Margolin <bar...@alum.mit.edu>
Newsgroups: comp.unix.shell
Subject: Re: Deleting old files
Date: Mon, 08 Oct 2012 15:54:47 -0400
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <barmar-FC1EC6.15544708102012@news.eternal-september.org>
References: <06f77a1c-e04c-4551-88b8-de11f841dff6@googlegroups.com>
Injection-Info: barmar.motzarella.org; posting-host="78fb7125a45724f15e21604c94a7d968";
	logging-data="26508"; mail-complaints-to="ab...@eternal-september.org";	posting-account="U2FsdGVkX18SnpXy/cw5LLLocJq4O1LG"
User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)
Cancel-Lock: sha1:19answY56etZjyZRn8OK7dtg07s=
Bytes: 2042

In article <06f77a1c-e04c-4551-88b8-de11f841dff6@googlegroups.com>,
 contrace...@gmail.com wrote:

> Hi,
> 
> Please help me to fix this script, I need delete old files (> 90 days)
> 
> #!/bin/ksh
> set -x
> SIZE=`df -P /home/devalias | grep -v Filesystem | awk '{ print $5 }' | tr -d 
> %`
> if [[ $SIZE -gt "10" ]]
> then
> /usr/bin/find /home/devalias/transfer* -type f -name "*.txt" -mtime +90 -exec 
> rm -f {} \;
> /usr/bin/find /home/devalias/transfer* -type f -name "*.cfm" -mtime +90 -exec 
> rm -f {} \;
> fi

What's wrong with it? I can see ways to improve it, but I don't see any 
serious problems with it.

You can combine the two finds into one, and run rm only once with all 
the filenames, with:

/usr/bin/find /home/devalias/transfer* -type f \( -name '*.txt' -o -name 
'*.cfm' \) -mtime +90 -exec rm -f {} +

And awk can do its own grepping and tr'ing:

SIZE=`df -P /home/devalias | awk '!/Filesystem/ {gsub("%", "", $5); 
print $5}'`

-- 
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***