TurnKey Linux Virtual Appliance Library

how to retain Date Modified when copying files in linux?

red_x88's picture

Hi guys!

I got a TKL Fileserver up and running for almost 6 months now. I am using a cron job to create a local backup of samba shares. I have noticed that the Date Modified of created backup files is the date when the files were created.

cron job: cp -R /mnt/fileserver/File-server /mnt/backup

I'm just wondering if I could leave the Dated Modified of the backup files same with the original files.

Thanks in advance!

Jeremy Davis's picture

Not sure how you would do that

No doubt there is a way. Perhaps if you tar the files first (not sure if that'd work?) Another work around may be to rename the file to reflect the backup. Just remember that TKL is Ubuntu under the hood so anything that applies to Ubuntu (and to some extent Debian too) should apply to TKL.

Aris Moratalla's picture

Thanks for the reply Jed! I

Thanks for the reply Jed!

I will try using tar balls.

Guest's picture

Sorry I'm so late (just

Sorry I'm so late (just signed up).

In linux use the "-p' (lower case p) option to retain the date/time on the destination.

ex:  cp -p sourcefile targetfile

Aris Moratalla's picture

Thanks bob! will try it.

Thanks bob! will try it.

Aris Moratalla's picture

not working

Hi Bob!

It's not working. I also check on cp --help... there is no -c described as argument.

I have the command on my cron job.

cp -R /mnt/fileserver/FS_Backup/File-server /mnt/backup

Hope ou can help.


Don Sanderson's picture

As stated...........

in the post by bobmct the '-p' option should preserve ownership and timestamp.

From the man page for cp:

-p     same as --preserve=mode,ownership,timestamps

Aris Moratalla's picture

may bad

sorry...may bad. I thought it was -c.

So in my command.. is it cp -R -c?

Don Sanderson's picture

-p as in 'peter'

'cp -Rp' or 'cp -R -p'

As far as I know there is no -c option.

Aris Moratalla's picture


I am getting these error...


cp -Rp /mnt/fileserver/FS_Backup/File-server/adm/201 /mnt/backup
cp: cannot stat `/mnt/fileserver/FS_Backup/File-server/adm/201': No such file or directory
cp -R -p /mnt/fileserver/FS_Backup/File-server/adm/201 /mnt/backup
cp: cannot stat `/mnt/fileserver/FS_Backup/File-server/adm/201': No such file or directory
Aris Moratalla's picture

my bad again

I was able to sort this out.

case sensitivity caused the error.

cp -R -p /mnt/fileserver/FS_Backup/File-server/ADM/201 /mnt/backup.

Thank you so much Don Sanderson, bob and Jed!

Don Sanderson's picture

CP is confused

You posted as I was writing this, glad you got it sorted. :-)


You will have to examine your file system and see what is wrong with the path:


CP can't find, or understand, what you are asking of it.

Aris Moratalla's picture

Just a tought

Hi again Don!

I know I should create a new topic for this question- but I just want to ask on how I can make 2 local fileserver synchronize... from the filesystem to the mounted partions. What I am trying to do is make an exact replica of my current TKL Fileserver which will synchronize with the original at the end of the day.

I have tried TKLBAM but it did not work for me because the internet here is not that good (the disconnects like every 15 minutes, not to mention a very low bandwidth).

Thanks in advance!

Don Sanderson's picture

See this post:


Make a local backup from the 'original'.

Restore to the 'clone' from that backup.

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong> <font> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <strike> <caption>

More information about formatting options

Leave this field empty. It's part of a security mechanism.
(Dear spammers: moderators are notified of all new posts. Spam is deleted immediately)