Skip to content
Advertisement

Recursively replace linux file and folder names such as “%m-%d-%y.tar” with their actual creation month/day/year

I’m looking for something like this but with its original creation date instead of the current date.

Example: This folder (output below is from Linux command ls -ltr)

drwxrwxr-x 2 backup_user backup_user 4096 Apr 26 01:06 "%m-%d-%y" 

would have its file name changed to “04-26-20”.

Advertisement

Answer

Since there are some information missing I try to make assumptions and show a possible solution approach in general.

As already mentioned within the comments, for a filesystem like EXT3 there would be no creation time. It might be possible to use the modification time which could be gathered via the stat command, i.e.

MTIME=$(stat --format="%y" "%m-%d-%y" | cut -d " " -f 1)

… or even access time or change time.

The date of MTIME is given in format %Y-%m-%d and can be changed for the new file name via

FNAME=$(date -d ${MTIME} +%m-%d-%y)

Than it it is possible to rename the directory, i.e.

mv "%m-%d-%y" ${FNAME}

which will of course change the timestamps within the filesystem for the directory.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement