So by using some info from other threads on this site I have managed to get a script to copy files to another directory, then add the md5sum into the duplicate file names. However, I'm not fully satisfied as I'm still receiving a couple of BASH notifications when I execute the script which I could do with some help understanding/resolving. Firstly here is the script.

cp -r $dir1/* $dir2

cd $dir2  

fdupes -r $dir2 | while read i; do

md5=$(md5sum "$i" | awk '{ print $1 }')

mv -v "$i" "${bn}_${md5}.${ext}"


The messages I am receiving when the script is run are:

md5sum: : No such file or directory
mv: cannot stat ‘’: No such file or directory

As I say, the script does seem to work, but any ideas on why I receiving these messages would be appreciated, as would any suggestion to tweak/improve the script. Thanks

1 Answer 1


From my understanding, i guess there is an issue with fdupes command which output an empty line at the end :

[PRD][]localhost:~ 12:17:09     
$ fdupes -r work/

[PRD][]localhost:~ 12:17:19

Then while processing in the loop, the last element is empty which produces an error in md5sum like when file is nonexistant :

$ md5sum ' ' 
md5sum: : no such file of directory 

And then the script tries to move this empty name file which produces also the mv error.

  • 1
    Immediately below the while read i; do, add this line test -z "$i" && continue Commented Oct 13, 2015 at 10:38
  • roaima- thanks that worked a treat :)))) Don't suppose you could explain why that worked and your logic could you? No worries if not, you've already helped me lots.
    – neilH
    Commented Oct 13, 2015 at 12:04
  • test -z $i will test if Variable i is empty. If not the && continue will continue to loop into the while. Don't forget to accept the answer if you are happy with the outcome.
    – netmonk
    Commented Oct 13, 2015 at 12:08
  • 1
    thanks netmonk, that makes your original answer more understandable to a noob like me, cheers. I've accepted the original answer now I understanding it more.
    – neilH
    Commented Oct 13, 2015 at 13:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .