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 $.gz exit fi if [[ $filedata =~ /PDF document/ ]]; mv $filename $.pdf exit fi