DEV Community


Comparing files by content in Android

I'm a loving husband and father, catholic christian. Software dev and engineer for Greatest God's Glory. Inlove with Freedom & heavy metal. En todo amar y servir
・3 min read

This is the story of a need:

I had a simple problem, a lot of files (not images) that looked the same and needed to be sure I wasn't going to loose anything if I deleted them.

I use Linux for several years now, but when I'm on Windows I never hang around without using Total Commander, a great side by side FS explorer tool. Is full of useful stuff. One of them is Compare by content. I'll compare 2 files and state they are identical or show the diff output on a special interface for that.

On Android, gladly, we have Total Commander as well 😄 . Is a must have, seriously. But is now as packed as the original version. Anyway, is powerfull enough to solve my dilema.

The dilema: bunch of unknown files that looked the same

I was browsing and doing some cleaning in the internal when I found this:

A lot of files that looked the same, judging by their size. But how to be sure they were the same.

If I were in Windows I'll had the tools; If I were on Linux, I would have diff, but I'm on Android... wait... Isn't Android a form of Linux?

Diff on Android, which is a sort of Linux (awwwwww, so cool!)

So I went to my trusted Terminal app and issue the command:

$ diff
See diff --help
diff: Need 2 arguments

Wow, there it is. So, just need to use this to compare the files and get the results. But there are a few of them.

Total Commander to the rescue!

Total Commander has the capability of adding buttons to its toolbar (you can see it at the bottom of the image). Pressing the + sign you'll get a dialog like the next one, where you'll press the Function type:

Of many things you can choose there is a choice to pass arguments to a command. Selecting Send shell command:

Once there is time to tweak on the Parameters: field. If you hit the ? button you'll find the explanation, but to resume:

  • The field is a multiline field: one parameter per line
  • If the first parameter is an * it will output the results in a dialog that can be copied to clipboard.
  • Using %S will include the names of selected files in parameter line

So, knowing this the Parameteres field goes like this:

diff %S

So, lets select 2 obviusly different files and try it:

The result:

This is just GREAT!

The result on equal files

Now let's go for the similar files:

Now pay attention because the result will be showed on screen for a short period of time and is:

Wow, you were lucky to be looking at an static image, otherwise you'll had miss it 😆.

In this case when files are identical the output of the diff command is null, nada, zero. You get me? That's why it prints nothing to a dialog, just the Function succeeded! overlay message.

Well, that's about it. Be carefull when comparing coding files, because the whole diff output will be on the dialog, and you know it can get long.

If you like this post hit the like or heart or you know button. Thank you all!

Discussion (0)