P i
P i

Reputation: 30774

BASH script to find files that match by content

I have several thousand .wav files, spanning several levels of subfolders.

A few months back I selected 12 of these and copied them in another folder.

In this new folder, I renamed them 01.wav to 12.wav.

Now I need to figure out what the original files were.

How can I go about doing this?

Upvotes: 0

Views: 73

Answers (1)

ooga
ooga

Reputation: 15511

Go to the directory where the 12 wav files are and execute:

cksum {01..12}.wav > cksum.txt

Then move cksum.txt to the top directory of your wav files and cd to that directory. Then execute this pipeline:

find . -name '*.wav' -exec cksum '{}' + |
awk 'NR == FNR {ck[$1] = $3; next} {if ($1 in ck) print ck[$1], $3}' cksum.txt -

This also prints the 12 wav files as duplicates of themselves but I left that in for simplicity (although it would be easy to remove them).

Upvotes: 3

Related Questions