Set date/time of a directory of files

Hi I've got a thumb drive of data from rescuing files off my partners Windows laptop after a crash. After copying, the files assumes the date/time of the copy. Is there a way using a bash command (or script) I can "touch" each file in each folder with its last modification date/time? This will help me rebuild after converting the laptop to linux. regards Ian -- openSUSE Tumbleweed 20250325 kwin 6.3.3 kmail2 6.3.3 (24.12.3) - akonadiserver 6.3.3 (24.12.3) - Kernel: 6.13.7-1- default - kernel-firmware-radeon 20250206

Andrei Borzenkov wrote:
On Thu, Mar 27, 2025 at 4:47 PM Axel Braun <docb@opensuse.org> wrote:
The '-r' was parameter to xargs, not to touch... 'touch -hm' indeed sets modification date to 'now' I'm not sure where the actual modification time is coming from. If the thumbstick has them, one should use 'cp -a'. If it doesn't have them, there's no way to retrieve them (?)

On 2025-03-27 16:31, Pit Suetterlin wrote:
Andrei Borzenkov wrote:
On Thu, Mar 27, 2025 at 4:47 PM Axel Braun <docb@opensuse.org> wrote:
It depends on what filesystem it uses. If it uses FAT, there is only one timestamp. Huh, chatgpt contradicts me. The FAT (File Allocation Table) file system stores timestamps for files in a limited format. Specifically, it keeps track of the following types of timestamps: 1 Creation Time: This timestamp is the date and time when the file was created. 2 Last Access Time: This timestamp reflects the last time the file was accessed. This can include reading or executing the file, though it is sometimes not updated depending on the system configuration. 3 Last Write Time (Modification Time): This timestamp represents the last time the file's contents were modified or written to. If that is so, "stat filename" should give you them all. If not, try "mdir". -- Cheers / Saludos, Carlos E. R. (from 15.6 x86_64 at Telcontar)

On Thursday, 27 March 2025 13:47:23 Greenwich Mean Time Axel Braun wrote:
I got the same results, i'll have to work on it
-- openSUSE Tumbleweed 20250325 kwin 6.3.3 kmail2 6.3.3 (24.12.3) - akonadiserver 6.3.3 (24.12.3) - Kernel: 6.13.7-1- default - kernel-firmware-radeon 20250206

On Thursday, 27 March 2025 13:47:23 Greenwich Mean Time Axel Braun wrote:
No. i tested it out on a folder and got the same results as you, not had time to do anything more with it as yet
Cheers Axel
-- openSUSE Tumbleweed 20250325 kwin 6.3.3 kmail2 6.3.3 (24.12.3) - akonadiserver 6.3.3 (24.12.3) - Kernel: 6.13.7-1- default - kernel-firmware-radeon 20250206

On Thursday, 27 March 2025 13:47:23 Greenwich Mean Time Axel Braun wrote:
No. i tested it out on a folder and got the same results as you, not had time to do anything more with it as yet
Cheers Axel
-- openSUSE Tumbleweed 20250325 kwin 6.3.3 kmail2 6.3.3 (24.12.3) - akonadiserver 6.3.3 (24.12.3) - Kernel: 6.13.7-1- default - kernel-firmware-radeon 20250206

28.03.2025 13:39, Ianseeks wrote:
Where this time is supposed to come from?
That is exactly what this command line does - it sets modification time to "now" (more precisely - time of the each "touch" invocation). If this is not desired, you are using the wrong command line.
i tested it out on a folder and got the same results as you, not had time to do anything more with it as yet

On Thursday, 27 March 2025 13:54:16 Greenwich Mean Time Pit Suetterlin wrote:
it was data recovery software as the main Windows disk was unbootable, (done by my nephew as he had the Windows stuff)
If not, I think you're out of luck. If yes, use rsync, or cp --archive
I generally use rsync for may backups which i can do now i've installed opensuse onto laptop. thanks -- openSUSE Tumbleweed 20250325 kwin 6.3.3 kmail2 6.3.3 (24.12.3) - akonadiserver 6.3.3 (24.12.3) - Kernel: 6.13.7-1- default - kernel-firmware-radeon 20250206

On Thursday, 27 March 2025 13:54:16 Greenwich Mean Time Pit Suetterlin wrote:
it was data recovery software as the main Windows disk was unbootable, (done by my nephew as he had the Windows stuff)
If not, I think you're out of luck. If yes, use rsync, or cp --archive
I generally use rsync for may backups which i can do now i've installed opensuse onto laptop. thanks -- openSUSE Tumbleweed 20250325 kwin 6.3.3 kmail2 6.3.3 (24.12.3) - akonadiserver 6.3.3 (24.12.3) - Kernel: 6.13.7-1- default - kernel-firmware-radeon 20250206

On Fri, 28 Mar 2025, 11:47:08 +0100, Ianseeks wrote:
To be honest I misunderstood you in the beginning, thought you wanted the last modification date/time, ie. the current time when restoring.
rsync really does it. It cannot do this for directories on vfat, though. This command using rsync should do it: $ rm -rf /directory/for/the/restore/{.??,}* $ rsync -x -aHPSEAXOJ /where/your/backup/lives/ /directory/for/the/restore/ -OJ just omit the attempt to restore the time for directories and symlinks. Cheers. l8er manfred

Ian, et al -- This may have been beaten to death already, but I haven't noticed a good answer going by, so here I am ... :-) ...and then Ianseeks said... % Hi Howdy! % % I've got a thumb drive of data from rescuing files off my partners Windows % laptop after a crash. After copying, the files assumes the date/time of the % copy. % % Is there a way using a bash command (or script) I can "touch" each file in each [snip] Unfortunately, Windows and VFAT really stink at this. I don't know of any way to accomplish the INCREDIBLY BASIC task outside of Windows *sigh* What I've had to do is - zip up the file collection from wherever - park the zip file locally - open with Win Explorer - copy from inside the file and Windows-paste them wherever Any other way to extract or copy them has always failed to keep the timestamp :-( HTH & good luck! & HAND :-D -- David T-G See http://justpickone.org/davidtg/email/ See http://justpickone.org/davidtg/tofu.txt

On Monday, 31 March 2025 20:55:02 British Summer Time David T-G wrote:
Thanks. Fortunately I don't have any Windows to worry about anymore
:-D
-- openSUSE Tumbleweed 20250329 kwin 6.3.3 kmail2 6.3.3 (24.12.3) - akonadiserver 6.3.3 (24.12.3) - Kernel: 6.13.8-1- default - kernel-firmware-radeon 20250206

Andrei Borzenkov wrote:
On Thu, Mar 27, 2025 at 4:47 PM Axel Braun <docb@opensuse.org> wrote:
The '-r' was parameter to xargs, not to touch... 'touch -hm' indeed sets modification date to 'now' I'm not sure where the actual modification time is coming from. If the thumbstick has them, one should use 'cp -a'. If it doesn't have them, there's no way to retrieve them (?)

On 2025-03-27 16:31, Pit Suetterlin wrote:
Andrei Borzenkov wrote:
On Thu, Mar 27, 2025 at 4:47 PM Axel Braun <docb@opensuse.org> wrote:
It depends on what filesystem it uses. If it uses FAT, there is only one timestamp. Huh, chatgpt contradicts me. The FAT (File Allocation Table) file system stores timestamps for files in a limited format. Specifically, it keeps track of the following types of timestamps: 1 Creation Time: This timestamp is the date and time when the file was created. 2 Last Access Time: This timestamp reflects the last time the file was accessed. This can include reading or executing the file, though it is sometimes not updated depending on the system configuration. 3 Last Write Time (Modification Time): This timestamp represents the last time the file's contents were modified or written to. If that is so, "stat filename" should give you them all. If not, try "mdir". -- Cheers / Saludos, Carlos E. R. (from 15.6 x86_64 at Telcontar)
participants (8)
-
Andrei Borzenkov
-
Axel Braun
-
Carlos E. R.
-
David T-G
-
Ianseeks
-
Manfred Hollstein
-
Olaf Hering
-
Pit Suetterlin