Absurd Minds
http://forums.absurdminds.net/

Script to delete unused maps
http://forums.absurdminds.net/viewtopic.php?f=58&t=2469
Page 1 of 1

Author:  Amaroq [ 13 Jun 2014 13:12 ]
Post subject:  Script to delete unused maps

Because the workshop doesn't manage map collections very well, our custom map server has a lot of unused maps in it. These would be maps that maybe I added to the collection and then later removed.

I would like to create a script, executable through crontab, that deletes files, and hopefully their parent directories, if the file has not been accessed in a particular amount of time.

I'm thinking I would just scan for files by Access date, then delete files, then scan for empty directories, then delete them. Would this work?

Author:  Amaroq [ 13 Jun 2014 13:50 ]
Post subject:  Re: Script to delete unused maps

It looks like the relevant command would be
Code:
find ./directory -atime +N -exec rm {} \;
where N is the number of days ago that you would want it to have been accessed last. Eg, +10 would give you a list of all files that have been accessed 10 or more days ago. It would then execute a removal command for those files.

Now all I have to figure out is how to delete empty subdirectories.

Author:  Amaroq [ 13 Jun 2014 13:54 ]
Post subject:  Re: Script to delete unused maps

Alright, it looks like I can delete empty directories using this command:
Code:
find . -empty -type d -delete
Last step is figuring out how to get this together into a useful script.

Author:  Amaroq [ 13 Jun 2014 14:03 ]
Post subject:  Re: Script to delete unused maps

Current script delete.sh: Jero, can you fact check this before I execute it and fubar my maps?
Code:
#!/bin/bash

find ~/go/*/csgo/maps/workshop -atime +14 -exec rm {} \;
sleep 5
find ~/go/*/csgo/maps/workshop -empty -type d -delete

Author:  jero [ 13 Jun 2014 18:06 ]
Post subject:  Re: Script to delete unused maps

Looks okay, even though I haven't touched a Linux console in months. You could just move them to an "unused" directory instead of deleting them.

Author:  Amaroq [ 13 Jun 2014 18:15 ]
Post subject:  Re: Script to delete unused maps

Well, they will just redownload if they're actually part of the compilation but not being used. (eg, if there is a map on the server but maybe it's less popular). Then I'd have tons of duplications.

Page 1 of 1 All times are UTC-04:00
Powered by phpBB® Forum Software © phpBB Limited
https://www.phpbb.com/