help with a bash script
Kurt Wall
kwall
Mon May 17 12:00:44 PDT 2004
In a 1.9K blaze of typing glory, Joel Hammer wrote:
> xargs has always been an extra nuisance to me...
>
> But,
> shouldn't these scripts have some provision for file names with
> blanks and other annoying characters?
>
> So, shouldn't your script be:
>
> find . -type f -mtime +5 | xargs -i{} rm {}
Yup. I'm supposing that the OP has properly named files. And,
as I said, the script was (mostly) untested.
> My script has the same problem.
>
> So:
> dir -1 | find -atime +5 -maxdepth 1 -type f > junk
> while read a
> do
> rm "$a"
> done < junk
Just remove junk when you're done. I have no principled objection to
using a temporary file. They can make things considerably easier.
> On the other hand, I do not think my original script can be salvaged so
> easily:
> rm "$(find -atime +5 -maxdepth 1 -type f)"
> Doesn't work. It is all one long line.
Just peel the files off the list one at a time:
for file in $(find -atime +5 -maxdepth 1 -type f)
do
rm $file
done
Kurt
--
... and furthermore ... I don't like your trousers.
More information about the Linux-users
mailing list