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.