The photorec terminal program can selectively recover files based on their filetype(s), for example it can recover only .odt documents, but photorec/testdisk can't selectively scan an individual directory for lost files unless you had mounted a whole hard drive partition as this directory. In some cases, the filename is stored in the file itself. PhotoRec tries to recover the filename in this case, but most of the time PhotoRec can't recover the filenames.
photorec is provided by the testdisk package from the default Ubuntu repositories.
Recover files based on filetype using photorec
It is preferable to boot from an Ubuntu live DVD/USB before following these steps, in order to avoid using the operating system in which the deleted file is located.
Install testdisk from the default Ubuntu repositories.
sudo apt-get install testdisk
Open a terminal and launch photorec (as root).
Select hard disk.
Select partition type.
If your hard disk has Linux partitions, then select
Select filetype option.
[File Opt] and press Enter. Here you can disable all file types by pressing s. Use space to toggle the check button. Select filetype(s) to recover.
Photorec also has a list of different options. Under normal circumstances you don’t need to modify them.
Move the selector up or down to the partition from which you have removed the file(s). Then select
[Search] and press Enter.
Select filesystem type.
If you are using Linux, it's going to be ext2/ext3/ext4, so the default selection is
ext2/ext3. Otherwise if you are recovering files from a partition formatted as FAT or NTFS select
Select space for analysis.
Free if you didn’t write to that partition after removing the particular file, otherwise select
Select a directory for the recovered files.
Select the path where the recovered files will be stored. Then press Y.
Photorec will show how many files it has recovered.
Source: revised from How To Recover Deleted Files in Linux Using Photorec