I have the following script, though I would like to change it to deleting content once the directory reaches a certain size. What are my options?
find /home/scott/google-drive/CAMMEDIA/* -mtime +1 -exec rm -rf {} \;
This is pseudo code. You will have to set the folder size and what you want to remove yourself (you were not clear on what you wanted to be removed so I'm running the same thing you were)
MAX_SIZE=50000
DIR_SIZE=$(du /home/scott/google-drive/CAMMEDIA/*)
if [$MAXSIZE -gt $DIR_SIZE]
then
find /home/scott/google-drive/CAMMEDIA/* -mtime +1 -exec rm -rf {} \;
fi
du -h
but I think you will want the raw number for your code. If this answer works for you please upvote and accept it.
if [ $MAXSIZE -gt $DIR_SIZE ]
-size
flag with your needed parameters, I would also add the-type
to search only for directories and not for files if you want that. So as an example search for all directories bigger than 10K you need thisfind /place/to/search -type d -size +10K
and then you can continue however you like.