Posted By

brm on 06/16/15


Tagged

sysadmin perl1liner


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

brm
polehead


Find duplicate file and remove


 / Published in: Bash
 

Perl 1 liner + additional linux command to find duplicate files and remove it - only spare 1 file.

  1. #!/bin/sh
  2.  
  3. find "[email protected]" -type f -print0 | xargs -0 md5sum | sort | perl -ne
  4.  
  5. 'chomp;$x=$y;($y,$z)=split(/\s+/,$_,2); print "$z"."\x00" if ($x eq $y)' | xargs -0 rm -v --
  6.  
  7. #OR
  8. #if wanna find out size of all files to calculate space storage
  9. #change the
  10. # xargs -0 stat -c %s | awk'{SUM+=$1}END{print SUM/1024/1024}'

Report this snippet  

You need to login to post a comment.