5

Is there a way to show the progress when running the cmp command?

Comparing large files or partitions using cmp can take a while.

I have searched google and used man cmp, but failed to find any useful information.

With the 'dd' command for example executing

kill -USR1 [pid_of_dd]

makes dd output its status in the console.

Is there a way to make cmp do something similar?

Cfinley
  • 1,435
  • 3
  • 14
  • 20
Iljaas
  • 155
  • 1
  • 2
  • 5

2 Answers2

12

You can use PipeViewer for this

pv firstfile | cmp -l secondfile > output
Alex
  • 1,387
  • 2
  • 18
  • 29
  • 1
    Thanks! Your answer is really useful for other commandline stuff as well. – Iljaas Nov 24 '11 at 08:34
  • 1
    Using "-l" (--verbose) slows it down a lot for large files. "pv firstfile | cmp secondfile" is faster if you don't need the verbose output. – KIAaze Aug 27 '23 at 13:47
9
$ cmp -l firstfile secondfile &
[1] pid_of_cmp
$ ls -l /proc/pid_of_cmp/fd/
lrwx------ 1 user group 64 datetime 0 -> /dev/console
lrwx------ 1 user group 64 datetime 1 -> /dev/console
lrwx------ 1 user group 64 datetime 2 -> /dev/console
lr-x------ 1 user group 64 datetime 3 -> /path/to/firstfile
lr-x------ 1 user group 64 datetime 4 -> /path/to/secondfile
$ cat /proc/pid_of_cmp/fdinfo/0
pos:    25952256
flags:  0100000
$ cat /proc/pid_of_cmp/fdinfo/1
pos:    122650624
flags:  0100000

Compare pos to the size of the files.

ephemient
  • 24,884
  • 4
  • 30
  • 20
  • This option is very useful in some cases: you don't have the pv or bar commands; you don't have control over the command (for example a GUI program launches it); or the command doesn't support pipes. – golimar Feb 28 '13 at 17:59