Score:8

Search for file by the name it had before being renamed

cn flag

I have some hundreds of thousands of files, personal stuff like photos, videos and documents gathered and stored during the years. Most of them are organized by type, dates and topics... But some (like 10k files) are not organized and have been moving around from directory to directory and renamed several times about 2 years ago. I am looking for (the path of) some of these files (hoping I haven't deleted them accidentally).

  1. Do file renamings get saved in any log or metadata somewhere?

  2. Is there a way to search for old files using their pre-rename name? If yes, what command or tool do I use?

I know the file type, the approximate dimension and some possibile names but still haven't found anything with the find command.

  1. Is there a way I could search the hard drive (SSD) for (probably) deleted files in a specific path without rebuilding the file layout table of the whole partition (that could take an eternity!?) ?
Score:7
cn flag
  1. Do file renamings get saved in any log or metadata somewhere?

Practically speaking, no. File names are a single record in the file system. In Linux, a file name points to an inode, which is the real unique identifier of a file. That way, a single file can exist in multiple places in a linux file system. If you rename a file, the new name takes the place of the old in the file system.

That is a simplification: modern file systems are complex. For example, they usually also have journalling, where an old name temporarily may be kept. This, however, has a time scale of only minutes, certainly not two years.

  1. Is there a way to search for old files using their pre-rename name? If yes, what command or tool do I use?

Because of 1, no. A renamed filename is overwritten.

  1. Is there a way I could search the hard drive (SSD) for (probably) deleted files in a specific path without rebuilding the file layout table of the whole partition (that could take an eternity!?) ?

You are in the area of data recovery now. Data recovery is quite difficult in modern linux file system, because of the way they work. There is a tool photorec (and its accompagnying tool testdisk) that allows some rescuing of deleted file - photorec will, however, not work based on file names, but will carve the digital data, recovering blocks when it recognized digital data that resemble a known file format.

Moving and especially deleting data is to be considered an irreversible process for practical purposes. The only precaution against undesired or erroneous file operations is to maintain a backup, in your case preferably with versioning (i.e. keeping very old version around).

cn flag
photorec is great, but doesn't even get you the current filename because it works at too low a level for that
Score:0
cn flag
Joe

As @vanadium says, there's no way to do exactly what you want.

The only thing I can think of that's remotely close to this would be if you had an old copy of (some of) the file(s). Then, you could do an rsync from that file's directory onto the rest of your system specifying --fuzzy --fuzzy (twice) and --dry-run to get rsync to look for the same file that might have a different name in a different directory and just tell you what it was going to do without actually writing anything to your current system.

If the file isn't binary (e.g. text or a document), you could use a tool such as recoll to index and search your current system. It performs simple searches easily, but also has advanced queries to search more precisely. It does take a while and builds a moderately large database when you first run it. It has a target file type of "media", but I've never explicitly tried using it.

grep will also search for specific content in non-binary files for you, but it will search everything in the path you give it each time, so if you're looking for a lot of things, then letting recoll build and search an index may be worth it - and it may be handy to have around in the future for other searches. I don't use it very often, but when I do, it's a life saver.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.