DEV Community

Discussion on: Intro To Linux [For Beginners]

Collapse
 
knav2013 profile image
knav2013

Does cp -r preserve directory timestamp or does it restamp with current date/time? Using GUI didn't preserve (was using Ubuntu 16.04.8 lxde desktop). Now I've started using tar to compress then extract with preserve timestamps switch

Collapse
 
kailyons profile image
Loralighte

That is a question I do not know the answer to

Thread Thread
 
knav2013 profile image
knav2013 • Edited

A unix and linux forum had the answer (unix.stackexchange.com/questions/4...

cp -r --preserve=timestamps SOURCE DESTINATION

No need to tar compress then tar extract with preserve time stamp switch.

I tested the above 'cp -r --preserve=timestamps SOURCE DESTINATION' command and it works like a dream.

Thread Thread
 
pgronkievitz profile image
Patryk Gronkiewicz

You also can use rsync

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️ • Edited

I just tried it out and no, apparently it doesn't.

EDIT: man cp and a quick search for timestamp reveals that when copy is called with the -p option, it should preserve timestamps. Not sure if this is a GNU thing though, but even busybox seems to support his flag.