Although you can only use it to recover images files currently but the rest assured it is quite powerful. First you need to install it. For that, if you use Ubuntu then open your terminal and issue the following command....
sudo apt-get install foremost
I'm not quite sure if you can use it on every type of media, but it does work on both HDD's, flash drives and memory cards as far as I know. Let's say that you want to recover some pictures in your flash drive, then all you have to do is...
1. Create folder for storing the recovered images (let's call it "recoverimages" which is located in /media).
2. Now I assume that by default your pen drive is mounted as = /dev/sdb
3. To start recovering your files in the pen drive issue the below command, (you'll need administrative privileges to run it)
sudo foremost -i /dev/sdb -o /media/recoverimages
Depending on the files and their sizes it may take a while. So be patient. But if you want an all purpose file recovering application which is again a command-line one, then I highly recommend TestDisk.