Cheksum On Linux and Windows

Hello Folks,

When you transfer files from Windows to Linux or vice versa, checksum of these files will be changed unless you transfer it in binary mode(in FTP terminology). It is normal because representation of  new line in Linux differ from the Windows system. In Unix systems new line represented by \n [line feed] whereas, DOS uses \r\n [carriage return + line feed]. In this blog post, we will overcome this situation with sed while checking the checksum of the files in two different systems.

 

Finding Checksum of a files in Unix(AIX)

#Default is MD5
AIX# csum mytest.txt

#csum with stdin
AIX# echo "Hello World!" | csum -

#Cleaning the hypen
AIX# echo "Hello" | csum - | awk '{print $1}'

Finding Checksum of a file in Linux

gokay@ankara:~$ md5sum avr.c
59035261ec34eea166fcc65e06966128  avr.c

gokay@ankara:~$ echo hello | md5sum -

Finding Checksum of a file in Windows:

It is very useful script in terms of DOS  systems. You can also run it from the command line by removing the statement powershell -command

C:\Users\ankara>powershell -command "Write-Host -NoNewline CKSUM_OF_BALANCE_EXT
RACT_FROM_DST:";"$(CertUtil -hashfile C:\SIL MD5)[1] -replace ' ',''"
CKSUM_OF_BALANCE_EXTRACT_FROM_DST:2737efbe44922560dc5be9d0ab98a6c4

How can we check checksum of the files after transferring it from Linux to Windows ?

One of the very easy way to do it is, installing unix2dos utility. But you can not always find this  utility in a system as it is not base system package. Workaround is the sed.

unix2dos with sed.

#Thanks to nixCraft author. I take it  from the nixCraft.
gokay@ankara:~$ sed 's/$'"/`echo \\\r`/" mytest.txt  | md5sum| awk '{print $1}'