I have data recovered from a backup and the data recovered has multiple versions of the same folders/files. The folders/files have been named with _000 _001 _002 etc on the files and folders. All modified time stamps are the same. So the folders/fileslook like this
[PATH ~/Folder/9] (VERSION 1) EMPTY - and can be deleted [PATH ~/Folder/9_000] (VERSION 2) EMPTY - and can be deleted [PATH ~/Folder/9_001] (VERSION 3) Data is in this last one FILEA.TXT (VERSION 1) remove/delete this one FILEA_000.TXT (VERSION 2) remove/delete this one FILEA_001.TXT (VERSION 3) remove/delete this one FILEA_002.TXT (VERSION 4) I need to keep this one and then rename FILEB.TXT (VERSION 1) remove/delete this one FILEB_000.TXT (VERSION 2) I need to keep this one and then rename
Some of these folders go 6+ deep. The pattern I have found is that the last file or folder version for each folder/file is the good one and the folders that are unwanted are empty. The bad thing is not all files/folders have the same number of versions. So just because FILEA.TXT has 4 versions (FILEA.TXT to FILEA_002.TXT) FILEB.TXT only has 2 versions (FILEB.TXT & FILEB_000.TXT). So I can't search all files with
_002 and move or delete. I was easily able to delete all the unwanted empty folders with bash (
find . -type d -empty -delete) which takes care of part of my problem on the folders except for renaming back.
I need to remove all the files that are unwanted and THEN remove the version numbers on folders/files so my software can correctly import the recovered data. Here is a example of a path and the files and folders in the path.
[PATH ~/Folder/9] EMPTY - and can be deleted [PATH ~/Folder/9_000] EMPTY - and can be deleted [PATH ~/Folder/9_001] Data is in this last one [PATH ~/Folder/9_001/62BF7CA1] EMPTY - and can be deleted [PATH ~/Folder/9_001/62BF7CA1_000] EMPTY - and can be deleted [PATH ~/Folder/9_001/62BF7CA1_001] Data is in the last one [ FOLDERS/FILES IN "~/Folder/9_001/62BF7CA1_001" ] Archive - unwanted deleted it Archive_000 - unwanted deleted it Archive_001 - unwanted deleted it Archive_002 - unwanted deleted it Archive_003 - keep Documents - unwanted deleted it Documents_000 - keep FolderX - unwanted deleted it FolderX_000 - unwanted deleted it FolderX_001 - unwanted deleted it FolderX_002 - keep 62BF7CA1.PDF - unwanted deleted it 62BF7CA1_000.PDF - unwanted deleted it 62BF7CA1_001.PDF - unwanted deleted it 62BF7CA1_002.PDF - keep 62BF7CA1.TXT- keep 62BF7CA1.DOC - unwanted deleted it 62BF7CA1_000.DOC - unwanted deleted it 62BF7CA1_001.DOC - unwanted deleted it 62BF7CA1_002.DOC - keep 62BF7CA1.QIF - unwanted deleted it 62BF7CA1_000.QIF - unwanted deleted it 62BF7CA1_001.QIF - unwanted deleted it 62BF7CA1_002.QIF - keep
The files and folders in this path to keep would be
Archive_003 Documents_000 FolderX_002 62BF7CA1_002.PDF 62BF7CA1.TXT 62BF7CA1_002.DOC 62BF7CA1_002.QIF
... and then I need to drop any _000 _001 _002 etc if it exist on each file folder
Archive Documents FolderX 62BF7CA1.PDF 62BF7CA1.TXT 62BF7CA1.DOC 62BF7CA1.QIF
Probably easy with things like sed and pipes but I have no idea.