Portál AbcLinuxu, 6. května 2025 06:36
date
ti vykouzlí jakýkoliv formát data a kdykoliv v minulosti. A pokud chceš přeskočit prvního, tak stačí jedna podmínka opět v kombinaci s příkazem date
na den v měsíci (bacha na toto :) ).find
.
date_default_timezone_set('Europe/Berlin'); $file_list = array(); $stack[] = '/var/www'; while ($stack) { $current_dir = array_pop($stack); if ($dh = opendir($current_dir)) { while (($file = readdir($dh)) !== false) { if ($file !== '.' AND $file !== '..') { $current_file = "{$current_dir}/{$file}"; $report = array(); if (is_file($current_file)) { $file_list[] = "{$current_dir}/{$file}"; } elseif (is_dir($current_file)) { $stack[] = $current_file; $file_list[] = "{$current_dir}/{$file}/"; } } } } } foreach ($file_list as $id => $file) { if (is_file($file)) { $file_dayofmonth = date ("j", filemtime("$file")); $file_dayofweek = date ("N", filemtime("$file")); if ($file_dayofmonth == "1") { echo "nemazat (1. v mesici) $file\n"; break; } if ($file_dayofweek == "1") { echo "nemazat (1. den v tydnu) $file\n"; break; } if (filemtime($file) < (time()-(7*24*60*60))) { echo "mazat (stari) $file\n"; # unlink($file); } else { echo "nemazat (stari) $file\n"; } } }
#!/bin/bash sourceDir="/backups" files=($(find $sourceDir -type f -regex "^.*$")) for item in ${files[*]} do dayofweek=$(date --date=`stat -c %y $item | sed 's/^\([0-9\-]*\).*/\1/'` +"%u") dayofmonth=$(date --date=`stat -c %y $item | sed 's/^\([0-9\-]*\).*/\1/'` +"%d") if ( [ `find $item -mtime +7` ] && [[ $dayofweek -gt 1 || `find $item -mtime +30` ]] && [[ $dayofmonth -ne 1 || `find $item -mtime +365` ]] ); then echo "$item mazat" else echo "$item nemazat" fi done
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.