New Sorting By Extension Script For Linux/Mac?

Using PhotoRec to recover lost data
Forum rules
When asking for technical support:
- Search for posts on the same topic before posting a new question.
- Give clear, specific information in the title of your post.
- Include as many details as you can, MOST POSTS WILL GET ONLY ONE OR TWO ANSWERS.
- Post a follow up with a "Thank you" or "This worked!"
- When you learn something, use that knowledge to HELP ANOTHER USER LATER.
Before posting, please read https://www.cgsecurity.org/testdisk.pdf
Post Reply
Message
Author
AthenaShikata
Posts: 1
Joined: 12 Nov 2023, 07:05

New Sorting By Extension Script For Linux/Mac?

#1 Post by AthenaShikata »

Download on Github: https://github.com/AthenaShikata/Random ... tension.sh

The scripts photorec provides on their site to sort their output by file extension didn't work for me. The python and bash scripts both gave me errors, so I learned a bit of bash and wrote my own script using linux commands.

sudo bash /path/to/photorecSortByExtension.sh (number of files per subfolder) /path/to/photorec/output /path/to/script/output (optional: select file type (i.e. jpg))

The Unix file system assigns all files and folders within a directory an identifier called an inode. There are only so many inodes before the system refuses to create more files in a directory. To counteract this, my script separates the files of one file type into subfolders with a limited number of files. Before I implemented this, I ran out of inodes around 20k files, so I am personally running at 5000. The scripts on photorec's website default to 500.

/path/to/photorec/output should be the folder containing recup_dir.1, recup_dir.2, etc. I recommend duplicating the original folder and using the duplicate to ensure the original's integrity in case something goes wrong.

/path/to/script/output will be created if it doesn't already. It will contain folders called txt, jpg, png, etc which will contain 1, 2, 3, 4, etc which will contain the recovered files.

If you only want certain file extensions, the 4th argument can specify the file extension. Do not include the . only what comes after (jpg not .jpg and zip not .zip). Leave this option blank if you want to sort all files.

This script cannot pause and continue. If you need to stop, either change the script output folder or delete the previous contents before beginning again.

If a file of the same name is detected in the same subfolder, it will not be overwritten and the second will will be appended with the number of copies -1 (i.e foo.txt foo(1).txt foo(2).txt). If this fails and the script tries to use the same name for 2 files, the script will pause and prompt the user if it should overwrite or not (I don't know how it would but I left it in as a precaution by adding the -i argument to the cp command).

Only tested on Linux, but all the commands used are simple unix command line commands that should allow this script to work on mac.

Currently no jpg renaming to the date because I haven't done that yet, but will edit when I finish renaming all of my files. I will not add this to the original script, but if I need to create my own I will add a download link to this post. If I was successful with one of the scripts provided by photorec, I will add that here as well.

Download on Github: https://github.com/AthenaShikata/Random ... tension.sh

recuperation
Posts: 2737
Joined: 04 Jan 2019, 09:48
Location: Hannover, Deutschland (Germany, Allemagne)

Re: New Sorting By Extension Script For Linux/Mac?

#2 Post by recuperation »

Thank for providing sorting options to Photorec!

The easiest way around the issue with the inode limitation is to use NTFS under Linux.
Ever since the Paragon NTFS code has been integrated (into the kernel?) the NTFS support under linux should be pretty reliable.

Post Reply