1

I've been having trouble with this for some time. Here is what I finally came up with that seems to work, though I have very limited abilities with piping.

I'm guessing this is a poor way to achieve my goal, are there some simpler ways I could do this that would be more efficient?

$ find /home/data/cam*/* -maxdepth 0 -type d -mtime +30 \
    -exec du -sm {} \;| awk '{if ( $1 > 3000 ) print $2}' | xargs rm -rf

1 Answer 1

1

It's pretty good actually. Assuming the /home/data/cam*/* -maxdepth 0 part is fine, and assuming your directory names don't contain newlines, I'd do it like this:

find /home/data/cam*/* -maxdepth 0 -type d -mtime +30 -exec du -sm {} + | \
    awk '$1 > 3000' | cut -f 2- | xargs rm -rf

-exec du -sm {} + is an optimisation, it doesn't run du for each directory. And awk '$1 > 3000' | cut -f 2- makes sure this still works if your directory names contain spaces.

1
  • ok great, I saw some stuff like that around online but I didnt know what it was for, thank you
    – nathan
    Jun 30, 2015 at 7:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .