I have a game server. It auto-gets players’ screenshots and stores at /home/gameserver/serverfiles/screenshots
.
I want to delete old screenshots when it reaches 1000. I mean if it’s 1000 screenshots, when a new screenshot comes, it auto-deletes the 1000th screenshot.
How can I do that, which scripts can I use? Can anyone give suggestion or codes?
Note: I am using Ubuntu 18.04 and my game server user hasn't sudo access.
I want to maintain my screenshot folder to hold max 1000 images.
head -n 1000
withtail -n -1000
it will output the oldest files where there are more than 1000 files (so if you have 1007 files, it will report the 7 oldest files which you can then delete. Also watch out for file names with a space in them (may not be relevant on your system), but you may want to quote ("
) $i in the rm line and the $( ...) section – Nick Sillito Aug 27 '18 at 12:12