I cannot copy with original timestamp! PLEASE HELP
Hi all,
I've knowledge about timestamp and i'm trying to use it in a particular scenario. I've multiple folders inside which are different files. Now I'm trying to copy one file (say xyz) which is present in all the folders but has variation in it's content and time of creation into a let's say foldernew. I'm trying to do this by copying the file xyz from each folders with the new name xyz_(it's orginal timestamp) into folder new. Can this be done with a single command or do what should I write in a script to execute this? Note: I want to add the timestamp of xyz when it is created not of the time of copy. |
touch -r destfile sourcefile
OK |
This doesn't even come close to my requirement.
|
My bad I didn't read it carefully.
OK |
Quote:
Were you able to determine the creation time, you'll need to script it. |
try cp -p
|
Quote:
|
Quote:
Since the destination folder will already have a file with same name from first copy, all other files from other folders cannot be copied to the destination folder. |
Quote:
Most in fact don't have a creation time. Better be sure you have what you appear to think you have. |
We have no idea how those xyz files were created, but if you want
Quote:
|
Not sure if it will help or not, but if you used the date in the filename when creating files it would make this sort of task easier.
(Maybe just add the creation date to your present filenames, & then copy them over.) |
Basically, "creation date" is a myth. That is an "inode modification date".
Some filesystems have extended date capability, but those capabilities are not fully supported (I believe Ext4 and Btrfs). |
So something like.
MYFILENAME=ThisFile.EXT MYTIMESTAMP=$(ls -l --full-time $MYFILENAME | awk '{ print $6; }') cp -a $MYFILENAME TempFile.EXT mv TempFILE.EXT "$MYFILENAME""_""$MYTIMESTAMP" You could probably skip the TempFile.EXT middleman and use sed to segment the extension to after the timestamp. Lots of ways, some simpler than others. |
Quote:
Quote:
|
Quote:
|
All times are GMT -5. The time now is 02:15 AM. |