find /path/to/files/* -mtime +15Delete files more than 15 days old:
find /path/to/files/* -mtime +15 -exec rm {} \;These can, of course, be scripted (and cron'd, if you set the -mtime flag instead of using a variable). A script to show the files and directories older than x days would look like:
#!/bin/bash --
find /path/to/files/* -mtime $1And to delete those same files:
#!/bin/bash --
find /path/to/files/* -mtime $1 -exec rm {} \;Just remember to set the permissions of the script to allow execution, and pass the variable on the command line like so:
# MyScriptName +15howtogeek.com has a detailed explanation of the command.
0 comments:
Post a Comment