Find duplicated file and remove it

#!/bin/sh find "$@" -type f -print0 | xargs -0 md5sum | sort | perl -ne 'chomp;$x=$y;($y,$z)=split(/\s+/,$_,2); print "$z"."\x00" if ($x eq $y)' | xargs -0 rm -v -- #OR #if wanna find out size of all files to calculate space storage #change the # xargs -0 stat -c %s | awk'{SUM+=$1}END{print SUM/1024/1024}'
Simple bash script to files with duplicated name and remove 1 of them.

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

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.