Find in a given directory, if there exist 2 files that have exactly the same content irrespective of their...












0
















This question already has an answer here:




  • Can I get the opposite of `diff -q` — matching identical files without printing their contents

    4 answers



  • Find duplicate files

    7 answers




if the problem could be solved using a series of commands on the command line, it would be better for me than writing a script










share|improve this question















marked as duplicate by Rui F Ribeiro, Christopher, RalfFriedl, Jeff Schaller, G-Man Jan 28 at 19:01


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Hi and welcome to Unix Stack Exchange. I think to do this, you would need to use the diff command. You would probably have to construct a for loop to compare each file in the directory to every other. Could do it with a fairly simple script.

    – Time4Tea
    Jan 28 at 18:05
















0
















This question already has an answer here:




  • Can I get the opposite of `diff -q` — matching identical files without printing their contents

    4 answers



  • Find duplicate files

    7 answers




if the problem could be solved using a series of commands on the command line, it would be better for me than writing a script










share|improve this question















marked as duplicate by Rui F Ribeiro, Christopher, RalfFriedl, Jeff Schaller, G-Man Jan 28 at 19:01


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Hi and welcome to Unix Stack Exchange. I think to do this, you would need to use the diff command. You would probably have to construct a for loop to compare each file in the directory to every other. Could do it with a fairly simple script.

    – Time4Tea
    Jan 28 at 18:05














0












0








0









This question already has an answer here:




  • Can I get the opposite of `diff -q` — matching identical files without printing their contents

    4 answers



  • Find duplicate files

    7 answers




if the problem could be solved using a series of commands on the command line, it would be better for me than writing a script










share|improve this question

















This question already has an answer here:




  • Can I get the opposite of `diff -q` — matching identical files without printing their contents

    4 answers



  • Find duplicate files

    7 answers




if the problem could be solved using a series of commands on the command line, it would be better for me than writing a script





This question already has an answer here:




  • Can I get the opposite of `diff -q` — matching identical files without printing their contents

    4 answers



  • Find duplicate files

    7 answers








bash shell-script command-line






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 28 at 18:06









Rui F Ribeiro

39.9k1479135




39.9k1479135










asked Jan 28 at 18:00









jospin deekjospin deek

4




4




marked as duplicate by Rui F Ribeiro, Christopher, RalfFriedl, Jeff Schaller, G-Man Jan 28 at 19:01


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Rui F Ribeiro, Christopher, RalfFriedl, Jeff Schaller, G-Man Jan 28 at 19:01


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Hi and welcome to Unix Stack Exchange. I think to do this, you would need to use the diff command. You would probably have to construct a for loop to compare each file in the directory to every other. Could do it with a fairly simple script.

    – Time4Tea
    Jan 28 at 18:05



















  • Hi and welcome to Unix Stack Exchange. I think to do this, you would need to use the diff command. You would probably have to construct a for loop to compare each file in the directory to every other. Could do it with a fairly simple script.

    – Time4Tea
    Jan 28 at 18:05

















Hi and welcome to Unix Stack Exchange. I think to do this, you would need to use the diff command. You would probably have to construct a for loop to compare each file in the directory to every other. Could do it with a fairly simple script.

– Time4Tea
Jan 28 at 18:05





Hi and welcome to Unix Stack Exchange. I think to do this, you would need to use the diff command. You would probably have to construct a for loop to compare each file in the directory to every other. Could do it with a fairly simple script.

– Time4Tea
Jan 28 at 18:05










2 Answers
2






active

oldest

votes


















0














for x in *; do for y in *; do [ "$x" = "$y" ] && continue; cmp -s "$x" "$y" && echo Same: "$x" and "$y"; done; done|head -1


Or, broken up a bit for readability:



for x in *
do
for y in *
do
[ "$x" = "$y" ] && continue
cmp -s "$x" "$y" && echo Same: "$x" and "$y"
done
done | head -1


The head is just to keep the mirror reporting down ("a = b" and "b = a").






share|improve this answer
























  • thank you, that was very helpful

    – jospin deek
    Jan 28 at 18:21



















0














find . -type f -exec md5sum "{}" ; | awk 'seen[$1] { print "Duplicate file "$2" with hash "$1" at "seen[$1]" } ! seen[$1] {seen[$1]=$2}'





share|improve this answer


























  • It says "Duplicate file xxx with hash yyy". That's right. But duplicate to what file? But nicely scripted!

    – Freddy
    Jan 28 at 18:55











  • Tweaked to store the first filename found in the array for reference in the output.

    – DopeGhoti
    Jan 28 at 20:17


















2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














for x in *; do for y in *; do [ "$x" = "$y" ] && continue; cmp -s "$x" "$y" && echo Same: "$x" and "$y"; done; done|head -1


Or, broken up a bit for readability:



for x in *
do
for y in *
do
[ "$x" = "$y" ] && continue
cmp -s "$x" "$y" && echo Same: "$x" and "$y"
done
done | head -1


The head is just to keep the mirror reporting down ("a = b" and "b = a").






share|improve this answer
























  • thank you, that was very helpful

    – jospin deek
    Jan 28 at 18:21
















0














for x in *; do for y in *; do [ "$x" = "$y" ] && continue; cmp -s "$x" "$y" && echo Same: "$x" and "$y"; done; done|head -1


Or, broken up a bit for readability:



for x in *
do
for y in *
do
[ "$x" = "$y" ] && continue
cmp -s "$x" "$y" && echo Same: "$x" and "$y"
done
done | head -1


The head is just to keep the mirror reporting down ("a = b" and "b = a").






share|improve this answer
























  • thank you, that was very helpful

    – jospin deek
    Jan 28 at 18:21














0












0








0







for x in *; do for y in *; do [ "$x" = "$y" ] && continue; cmp -s "$x" "$y" && echo Same: "$x" and "$y"; done; done|head -1


Or, broken up a bit for readability:



for x in *
do
for y in *
do
[ "$x" = "$y" ] && continue
cmp -s "$x" "$y" && echo Same: "$x" and "$y"
done
done | head -1


The head is just to keep the mirror reporting down ("a = b" and "b = a").






share|improve this answer













for x in *; do for y in *; do [ "$x" = "$y" ] && continue; cmp -s "$x" "$y" && echo Same: "$x" and "$y"; done; done|head -1


Or, broken up a bit for readability:



for x in *
do
for y in *
do
[ "$x" = "$y" ] && continue
cmp -s "$x" "$y" && echo Same: "$x" and "$y"
done
done | head -1


The head is just to keep the mirror reporting down ("a = b" and "b = a").







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 28 at 18:11









Jeff SchallerJeff Schaller

41k1056131




41k1056131













  • thank you, that was very helpful

    – jospin deek
    Jan 28 at 18:21



















  • thank you, that was very helpful

    – jospin deek
    Jan 28 at 18:21

















thank you, that was very helpful

– jospin deek
Jan 28 at 18:21





thank you, that was very helpful

– jospin deek
Jan 28 at 18:21













0














find . -type f -exec md5sum "{}" ; | awk 'seen[$1] { print "Duplicate file "$2" with hash "$1" at "seen[$1]" } ! seen[$1] {seen[$1]=$2}'





share|improve this answer


























  • It says "Duplicate file xxx with hash yyy". That's right. But duplicate to what file? But nicely scripted!

    – Freddy
    Jan 28 at 18:55











  • Tweaked to store the first filename found in the array for reference in the output.

    – DopeGhoti
    Jan 28 at 20:17
















0














find . -type f -exec md5sum "{}" ; | awk 'seen[$1] { print "Duplicate file "$2" with hash "$1" at "seen[$1]" } ! seen[$1] {seen[$1]=$2}'





share|improve this answer


























  • It says "Duplicate file xxx with hash yyy". That's right. But duplicate to what file? But nicely scripted!

    – Freddy
    Jan 28 at 18:55











  • Tweaked to store the first filename found in the array for reference in the output.

    – DopeGhoti
    Jan 28 at 20:17














0












0








0







find . -type f -exec md5sum "{}" ; | awk 'seen[$1] { print "Duplicate file "$2" with hash "$1" at "seen[$1]" } ! seen[$1] {seen[$1]=$2}'





share|improve this answer















find . -type f -exec md5sum "{}" ; | awk 'seen[$1] { print "Duplicate file "$2" with hash "$1" at "seen[$1]" } ! seen[$1] {seen[$1]=$2}'






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 28 at 20:17

























answered Jan 28 at 18:22









DopeGhotiDopeGhoti

45.3k55988




45.3k55988













  • It says "Duplicate file xxx with hash yyy". That's right. But duplicate to what file? But nicely scripted!

    – Freddy
    Jan 28 at 18:55











  • Tweaked to store the first filename found in the array for reference in the output.

    – DopeGhoti
    Jan 28 at 20:17



















  • It says "Duplicate file xxx with hash yyy". That's right. But duplicate to what file? But nicely scripted!

    – Freddy
    Jan 28 at 18:55











  • Tweaked to store the first filename found in the array for reference in the output.

    – DopeGhoti
    Jan 28 at 20:17

















It says "Duplicate file xxx with hash yyy". That's right. But duplicate to what file? But nicely scripted!

– Freddy
Jan 28 at 18:55





It says "Duplicate file xxx with hash yyy". That's right. But duplicate to what file? But nicely scripted!

– Freddy
Jan 28 at 18:55













Tweaked to store the first filename found in the array for reference in the output.

– DopeGhoti
Jan 28 at 20:17





Tweaked to store the first filename found in the array for reference in the output.

– DopeGhoti
Jan 28 at 20:17



Popular posts from this blog

How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

is 'sed' thread safe

How to make a Squid Proxy server?