LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-19-2015, 12:35 AM   #1
EternalCuriosity
LQ Newbie
 
Registered: Sep 2014
Location: Nepal
Distribution: RHEL
Posts: 16

Rep: Reputation: Disabled
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.

Last edited by EternalCuriosity; 05-19-2015 at 12:37 AM.
 
Old 05-19-2015, 01:15 AM   #2
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
touch -r destfile sourcefile

OK

Last edited by AnanthaP; 05-19-2015 at 01:23 AM.
 
Old 05-19-2015, 01:20 AM   #3
EternalCuriosity
LQ Newbie
 
Registered: Sep 2014
Location: Nepal
Distribution: RHEL
Posts: 16

Original Poster
Rep: Reputation: Disabled
This doesn't even come close to my requirement.
 
Old 05-19-2015, 01:29 AM   #4
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
My bad I didn't read it carefully.

OK
 
Old 05-19-2015, 02:19 AM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,103

Rep: Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117
Quote:
Originally Posted by EternalCuriosity View Post
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.
 
Old 05-19-2015, 02:35 AM   #6
RMLinux
Member
 
Registered: Jul 2006
Posts: 260

Rep: Reputation: 37
try cp -p
 
Old 05-19-2015, 03:02 AM   #7
EternalCuriosity
LQ Newbie
 
Registered: Sep 2014
Location: Nepal
Distribution: RHEL
Posts: 16

Original Poster
Rep: Reputation: Disabled
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?
 
Old 05-19-2015, 03:05 AM   #8
EternalCuriosity
LQ Newbie
 
Registered: Sep 2014
Location: Nepal
Distribution: RHEL
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by RMLinux View Post
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.
 
Old 05-19-2015, 03:16 AM   #9
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,103

Rep: Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117
Quote:
Originally Posted by EternalCuriosity View Post
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.
 
Old 05-19-2015, 04:11 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,691

Rep: Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274
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.
 
Old 05-19-2015, 07:03 AM   #11
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan with some Tiny Core, Fatdog, Haiku, & BSD thrown in.
Posts: 5,443

Rep: Reputation: Disabled
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.)
 
Old 05-19-2015, 08:05 AM   #12
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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).
 
Old 05-19-2015, 12:22 PM   #13
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
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.
 
Old 05-19-2015, 11:45 PM   #14
EternalCuriosity
LQ Newbie
 
Registered: Sep 2014
Location: Nepal
Distribution: RHEL
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by syg00 View Post
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.
 
Old 05-19-2015, 11:49 PM   #15
EternalCuriosity
LQ Newbie
 
Registered: Sep 2014
Location: Nepal
Distribution: RHEL
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by fatmac View Post
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!) in a folder on the basis of their timestamp is what i'm trying to achieve.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
script to timestamp files with timestamp from directory eRJe Programming 4 11-13-2013 06:52 PM
LXer: Fancy winning a copy of the original Postal game for Linux? LXer Syndicated Linux News 0 05-01-2013 09:31 PM
find, grep and copy based on timestamp rootaccess Linux - General 14 03-20-2013 09:09 PM
How to copy, then delete original of whatever log(s) that would help debug crashes... BigSmellyMonkey Linux - Newbie 2 10-02-2011 07:36 AM
how to retain an original copy of mail in internet while fetching to Sendmail server deepugopi Linux - Server 0 06-26-2007 03:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration