Users of various Unix implementations including Linux and FreeBSD are probably used to seeing checksum numbers that correspond to the Md5sum or Sha256sum standards. You’ve probably downloaded an ISO and run the md5sum command on it to make sure that you’ve downloaded it right. These hex numbers are sums of all the bits in a file, which tell you if it’s been tampered with or not. You can actually compute sums for your own files, which will tell you if anything went corrupt and if you need to replace it from backups.
You’ll have to work from a command line for this task. You could do it on a headless Linux server system, which means holding down Ctrl, Alt and F2 to get to a virtual terminal then logged in. However, you can also open a graphical terminal by holding down Ctrl, Alt and T or clicking on the Applications menu and clicking the Terminal link under System Tools. Ubuntu Unity users can search Terminal on the Dash. We tested it from a graphical terminal.
Method 1: Calculating an Md5sum
To calculate a sum, type md5sum followed by the name of the file you want to check. If the file isn’t in the current directory, then you’ll need to type the full path name. For instance, we were in the ~/Documents directory and typed md5sum /lib/xtables/libxt_cpu.so to find the md5sum of that library file. It’s really that easy and it only takes a moment to process. You can take down this number and check it again later if you’ve assumed it’s changed.
Many users get tripped up by the fact that the md5sum command in GNU/Linux offers a -b switch to read binary mode files and a -t switch to read text files. These text to binary switches are included for backwards compatibility. Today, running md5sum on GNU/Linux doesn’t produce anything different for the -b switch than it would for the -t switch, but they’re still included so if you wrote an old bash or Almquist script it would still run fine.
Method 2: Recursively Calculate Md5sum Digests
If you type md5sum * and push enter, then it will give you an MD5 message digest for every file sitting in the current directory. You can also type md5sum –tag * > checkSums to get a file that features the sum of every file in the directory. It’s useful if you want to take a look later on and see if anything changed. You might get a few warnings about something being a directory, which is safe to ignore. Directories can’t be summed up by themselves.
You might want to take an entire file system’s worth of sums, which is useful if you want to make sure nothing changes on backups on thumb drives or SD cards. Type cd followed by the highest directory in a system. While we used the root directory, you might want to cd to something in /mnt or /media if you’re working with a mounted partition.
Once you’re there, type find . -type f -exec md5sum –tag {} \; and push enter to get a huge list of data. This will quickly scroll of the screen, but once it’s done you can scroll up in a graphical terminal. If you’d prefer to keep a record or perhaps if you’re working on a terminal you can’t scroll on, then type find . -type f -exec md5sum –tag {} \; > checkSums.txt and let the system roll. Keep in mind that you can always change the file name so you don’t overwrite an older one. These commands are kind of long, so you might want to copy and paste them into your terminal. Remember that you’ll need to either click Edit and then click on Paste or hold down Shift, Ctrl and V since the regular Ctrl+V shortcut won’t work. Users who are working with the miniature busybox version of md5sum should remove the –tag part of that command, since it doesn’t support it.
If you’re interested in using a stronger algorithm for security reasons, then you can replace md5sum with any of a number of other commands. You can use sha1sum, sha224sum, sha256sum, sha384sum or sha512sum depending on how much protection you need. Each of those numbers represents how secure it is. While md5sum is perfectly fine for checking for file corruption, some security-minded users are concerned about people tampering with their files and would rather use an even stronger algorithm to make sure no cracking occurred. If you’re just worried about making sure copied files were transferred correctly, then md5sum may still do the trick. For security purposes, sha256sum is generally preferred.
The post How to Compute Md5sum Lists appeared first on Appuals.com.