Created
October 24, 2019 15:26
-
-
Save psolru/a3a81dffc6eff456abfd30be638fa320 to your computer and use it in GitHub Desktop.
quick and dirty php script for some interval clean up
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
chdir(__DIR__); | |
function se($str) { | |
$str = preg_replace('/[\\x0-\\x1F]/', '', $str); | |
$str = preg_replace('/\\x7F/', '', $str); | |
$str = str_replace("'", '\'"\'"\'', $str); | |
return "'".$str."'"; | |
} | |
$dirs = [ | |
'/home/patrick/.temp/', | |
'/home/patrick/.local/share/Trash/files/', | |
]; | |
foreach ($dirs as $dir) { | |
$dir = rtrim($dir, '/'); | |
$interval = trim(file_get_contents($dir.'/__AUTODELETE')); | |
if ($interval) { | |
var_dump($dir.'/{,.}[!.,!..]*'); | |
foreach (glob($dir.'/{,.}[!.,!..]*', GLOB_MARK|GLOB_BRACE) as $el) { | |
if (basename($el) == '__AUTODELETE') continue; | |
echo "- ".$el; | |
if (filemtime($el) <= strtotime("-".$interval." days")) { | |
shell_exec('rm -rf '.se($el)); | |
echo "delete"; | |
} | |
echo "\n"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
must create __AUTODELETE in temp deleted directory with content: [0-9]+