1

Is there an app/script what will peek at file content and try to guess the correct file extension? I have a bunch of files recovered from a backup and it's a mix of images, videos and documents. The filenames are all random and they have no extensions.

It doesn't matter what platform the app/script is for.

I know there are websites which will guess the format of a file if you upload it but i have hundreds of files so i need a batch mode.

1 Answers1

2

In Linux/Unix there is the file command. It will look at the data and then make a guess at which kind of file it is. If there is a limited number of different files, you could write a wrapper script which appends the extension based on the file contents. Quick example to get the idea accross:

#!/bin/bash

filename=$1

filedata=`file $filename`

if [[ $filedata =~ /gzip/ ]];
  mv $filename ${filename}.gz
  exit
fi

if [[ $filedata =~ /PDF document/ ]];
  mv $filename ${filename}.pdf
  exit
fi
mtak
  • 17,262