LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   I cannot copy with original timestamp! PLEASE HELP (https://www.linuxquestions.org/questions/linux-newbie-8/i-cannot-copy-with-original-timestamp-please-help-4175542978/)

EternalCuriosity 05-19-2015 12:35 AM

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.

AnanthaP 05-19-2015 01:15 AM

touch -r destfile sourcefile

OK

EternalCuriosity 05-19-2015 01:20 AM

This doesn't even come close to my requirement.

AnanthaP 05-19-2015 01:29 AM

My bad I didn't read it carefully.

OK

syg00 05-19-2015 02:19 AM

Quote:

Originally Posted by EternalCuriosity (Post 5364326)
Note: I want to add the timestamp of xyz when it is created not of the time of copy.

How are you planning to obtain this ?.
Were you able to determine the creation time, you'll need to script it.

RMLinux 05-19-2015 02:35 AM

try cp -p

EternalCuriosity 05-19-2015 03:02 AM

Quote:

How are you planning to obtain this ?.
Were you able to determine the creation time, you'll need to script it.
Each of the files have their unique creation time if that's what you mean. I was planning for a single command but can you suggest a script that can meet my requirement here?

EternalCuriosity 05-19-2015 03:05 AM

Quote:

Originally Posted by RMLinux (Post 5364366)
try cp -p

Thanks but I've already considered that. It preserves the timestamp of the file you are copying but it cannot deal with overwrite issue.

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.

syg00 05-19-2015 03:16 AM

Quote:

Originally Posted by EternalCuriosity (Post 5364375)
Each of the files have their unique creation time if that's what you mean.

It was what I was asking, yes.
Most in fact don't have a creation time. Better be sure you have what you appear to think you have.

pan64 05-19-2015 04:11 AM

We have no idea how those xyz files were created, but if you want
Quote:

to add the timestamp of xyz when it is created not of the time of copy
you need to implement that.

fatmac 05-19-2015 07:03 AM

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

jpollard 05-19-2015 08:05 AM

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

Shadow_7 05-19-2015 12:22 PM

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.

EternalCuriosity 05-19-2015 11:45 PM

Quote:

Originally Posted by syg00 (Post 5364383)
It was what I was asking, yes.
Most in fact don't have a creation time. Better be sure you have what you appear to think you have.

Quote:

Basically, "creation date" is a myth. That is an "inode modification date".
I'm sure of it since each files are created in unique date through cronjob and haven't been modified. That's the main reason why there are multiple xyz file in different folders.

EternalCuriosity 05-19-2015 11:49 PM

Quote:

Originally Posted by fatmac (Post 5364465)
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.)

That's the new measure i've taken. But placing the already existing files(and there are lots of them to go through manual rename, which i've considered last resort!:banghead:) in a folder on the basis of their timestamp is what i'm trying to achieve.


All times are GMT -5. The time now is 02:15 AM.