Script to copy creation date over top of modified date?

Can someone draw up a script that for every file, folder and subfolder and files that will copy the creation date over top of the modified date??

I know how to touch every file recursively, but no idea how to read a files creation date then use that to touch the modification date of that file, then do the same for the next, etc :frowning:

Any help you could provide would be greatly appreciated :slight_smile:

-Jamie M.

OK, one problem after the other:

1) How to get the creation date
Use the command istat . For details see man istat .

2) How to set the date of a file
Use touch -t <time> . See the man page of touch for details.

3) How to circle through a set of files
Use the find -command. Basically, find starts at some "starting point" directory and works its way recursively from there, finding every filesystem entry there is. You can exclude (or include) certain files and/or directories, so that only a part of the whole set is produced. Once the set is what you want you can add a certain action to each item found that way by adding the "-exec"-clause. Here is an example:

find /some/dir -type f -name "AB*" -exec cp {} /other/place \;

This will start in "/some/dir", only include files ("-type f") in the result set, further restrict the result set only to names beginning with "AB" ("-name "AB*") and finally execute the command cp {} /other/place for each file found that way. The "{}" is a placeholder for the respective filename found that way which will be filled in by the find -command.

For details: again, see the man -page.

4) How to change the date from one format to another
You haven't told us which system you are on. If you have the date -utility from GNU: it can do that. If not: you will need to get one of the many solutions already published. Search the forum (or even the internet) for "date calculation" or something such and you will find a myriad of hits.

I hope this helps.

bakunin

Server says: Debian GNU/Linux 8 (jessie)

It doesn't have istat installed and I don't have permission to to use apt-get :frowning:

Any other way to read the creation date?

-Jamie M.

'istat' is part of the sleuthkit.
There is a command 'stat' that will display

veritron jack # cd /etc
veritron etc # stat hosts
  File: οΏ½hosts'
  Size: 242           Blocks: 8          IO Block: 4096   regular file
Device: 801h/2049d    Inode: 9568430     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-04-13 10:46:00.045167230 -0400
Modify: 2015-08-08 11:25:10.182809658 -0400
Change: 2015-08-08 11:25:10.222809658 -0400
 Birth: -
veritron etc # 

However, the Birth date, which I assume is the original creation date, does not seem to be maintained on my system (Linux Mint 17)
The output can be formatted.

veritron etc # stat -c "%x" hosts
2016-04-13 10:46:00.045167230 -0400