0

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".

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Dustin Soodak
  • 553
  • 5
  • 15
  • 2
    `Apr 26` is not creation date. – Cyrus Apr 29 '20 at 23:56
  • And you need to think how you will treat two directories with same date. And do you consider a tar-file a directory? – Quasímodo Apr 29 '20 at 23:57
  • 2
    There's no such thing as a "creation" time in Linux. Some unix like OSes do have a "birth" timestamp – tink Apr 30 '20 at 00:00
  • 1
    Whether a creation date is available to you depends on used filesystem. See: [What file systems on Linux store the creation time?](https://unix.stackexchange.com/q/7562/74329) – Cyrus Apr 30 '20 at 00:07
  • @Cyrus - but as long as a `cp`,`mv` or `tar` ignores that the thing is still completely academic ... it only has validity if the file remains on the FS it was created on, and in the case of `ext4`, for instance, you need debug tools to get at that value ... while my statement above is an oversimplification I still think it's valid ;) – tink Apr 30 '20 at 00:16
  • 1
    sorry...meant modification time (in my case it won't be modified otherwise) – Dustin Soodak May 04 '20 at 15:34

1 Answers1

2

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.

U880D
  • 8,601
  • 6
  • 24
  • 40