Script to copy creation date over top of modified date?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to copy creation date over top of modified date?
# 1  
Old 04-14-2016
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 Smilie

Any help you could provide would be greatly appreciated Smilie

-Jamie M.
# 2  
Old 04-14-2016
Quote:
Originally Posted by toysareforboys
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
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:
Code:
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
# 3  
Old 04-14-2016
Server says: Debian GNU/Linux 8 (jessie)

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

Any other way to read the creation date?

-Jamie M.
# 4  
Old 04-14-2016
'istat' is part of the sleuthkit.
There is a command 'stat' that will display
Code:
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.
Code:
veritron etc # stat -c "%x" hosts
2016-04-13 10:46:00.045167230 -0400

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to print file name and its creation date

Hello , I am looking for a script to print file name and its last updated time. FILE CREATION-TIME FILE-NAME 24/10/2017 12:34 TDR-IU-8-2017.10.24.07:40:00-2017.10.24.07:45:00 when we run l command it print the directory and the files with details like permission,... (1 Reply)
Discussion started by: sadique.manzar
1 Replies

2. UNIX for Beginners Questions & Answers

Copy files in order of creation date

Hi everyone :-) I ran into a small issue. I would like to copy some files in the precise order they were created. So the oldest files should be copied first and the newest ones last. I tried cp -r $(ls -1t) ./destination but the files are still not sorted properly. I was thinking, that... (11 Replies)
Discussion started by: officiallyme
11 Replies

3. UNIX for Dummies Questions & Answers

Copy log based on from-date and to-date

Hi all, i go a customer support requirement where i need to scan several files based on from/to date like 1-oct to 2-oct please help... (3 Replies)
Discussion started by: AbhiJ
3 Replies

4. UNIX for Dummies Questions & Answers

Script to copy files from a certain date

I need to copy files from a directory that has a lot of files in it. However I only want to copy them from a certain date. My thoughts so far are to use ls -l and to pipe this into awk and print out tokens 6 (month)and 7 (day). $ ls -l -rw-r--r-- 1 prodqual tst 681883 Jun 12... (2 Replies)
Discussion started by: millsy5
2 Replies

5. Shell Programming and Scripting

Help with script to copy/rename files, then delete by date

Hi All, I am new to scripting and am looking for some assistance setting up a script. Basically I need the script to scan a folder for the newest files and make a copy of those files, adding a month to the date stamp. I also need this script to delete the previously copied files to save space.... (4 Replies)
Discussion started by: Lucid13
4 Replies

6. Shell Programming and Scripting

mp3 tag/rename based on creation (last modified date)

Arg, I'm trying to figure out how to create a album tag based on the last modified date stamp for files which don't have a corresponding .talk file. IE. 2009 12 10 - Talk Radio.mp3 is how I want them structured, they should all have a corresponding .talk file so my mp3 player can speak the name ie... (0 Replies)
Discussion started by: mrplow
0 Replies

7. Shell Programming and Scripting

Script to copy log files with today's date

I am a newbie to scripting. I need a korn shell script to copy log files of current day to archive folder and rename with current days date stamp. I would really appreciate your help. File structure is as follows. Everyday files get overwritten, so I need copy to a archive directory and... (3 Replies)
Discussion started by: mdncan
3 Replies

8. UNIX for Dummies Questions & Answers

script to rename files with current date and copy it.

I have few webservers logs like access.log. which would be growing everyday. what i do everyday is, take the backup of access.log as access.log_(currentdate) and nullify the access.log. So thought of writing a script... but stuck up in middle. My requirement: to take the backup and nullify... (6 Replies)
Discussion started by: logic0
6 Replies

9. UNIX for Dummies Questions & Answers

Changing Creation Date to a Prespecified Date of a File In Unix

Dear Expert, Is there a command to do that in Unix? In such a way that we don't need to actually "write" or modified the content. -- monkfan (4 Replies)
Discussion started by: monkfan
4 Replies
Login or Register to Ask a Question