Comparing files by content in Android
Tags: totalcommander, diff, android
Published: 2019-08-10 22:31:32

---
title: Comparing files by content in Android
published: true
description: How to compare files inside an Android phone.
tags: totalcommander, diff, android
---

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](https://www.ghisler.com/), 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 :smile: . 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:

![](https://thepracticaldev.s3.amazonaws.com/i/9gxlhshbs4i8lt7k8qw5.png)

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](https://play.google.com/store/apps/details?id=jackpal.androidterm&hl=en_US) 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:`

![](https://thepracticaldev.s3.amazonaws.com/i/1hhf0n6qtbg11nkqerk4.png)

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

![](https://thepracticaldev.s3.amazonaws.com/i/02qi1ymx4586htbsiiby.png)

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

![](https://thepracticaldev.s3.amazonaws.com/i/p67e3hcf4mc56fj08bu9.png)

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

![](https://thepracticaldev.s3.amazonaws.com/i/oc6s79l7d9xu39fb5a1l.png)

The result:

![](https://thepracticaldev.s3.amazonaws.com/i/rkwhuk448g3900ei6gv9.png)

This is just GREAT!

## The result on equal files

Now let's go for the similar files:

![](https://thepracticaldev.s3.amazonaws.com/i/74szjz5mnjbfiaqtnjct.png)

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

![](https://thepracticaldev.s3.amazonaws.com/i/kk1egldq0dez1do1vew6.png)

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

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!