Supprimer des fichiers d'un répertoire en masse

From Tuxunix
Jump to: navigation, search

Code


#!/usr/bin/perl
use POSIX qw/strftime/;
opendir DIR, "." or die; $i=0; printf "DELETING IN PROGRESS...";
 
while (my $f = readdir DIR) {
 unlink $f;
 $i++;
 if ($i % 300 == 0) {
  printf "...$i files deleted\n".strftime("%Y-%m-%d %H:%M:%S",localtime)." : PAUSE...";
  $| = 1; 
  sleep 1 ; 
  printf "...DONE. "; 
  printf "DELETING IN PROGRESS..."
 }
}; 
  printf "...DONE";
closedir DIR'
  • Sur une ligne entière :

Code


perl -le 'use POSIX qw/strftime/; opendir DIR, "." or die; $i=0; printf "DELETING IN PROGRESS..."; while (my $f = readdir DIR) { unlink $f; $i++; if ($i % 300 == 0) { printf "...$i files deleted\n".strftime("%Y-%m-%d %H:%M:%S",localtime)." : PAUSE..."; $| = 1; sleep 1 ; printf "...DONE. "; printf "DELETING IN PROGRESS..."}}; printf "...DONE"; closedir DIR'