I have a problem with the timestamps of files copied from my PC or laptop to USB drives: the last modification time of the original file and that of the copied file are different. Therefore, synchronizing files between my PC and my USB drive is quite cumbersome.
A step by step description
I copy an arbitrary file from my PC/laptop to a USB drive using the GUI or with the command
cp -a file.txt /media/gabor/CORSAIR/
I check the last modification time of the original file:
$ ls -l --time-style=full-iso file.txt -rw-rw-r-- 1 gabor gabor 0 2018-09-22 15:09:23.317098281 +0200 file.txt
I check the last modification time of the copied file:
$ ls -l --time-style=full-iso /media/gabor/CORSAIR/file.txt -rw-r--r-- 1 gabor gabor 0 2018-09-22 15:09:23.000000000 +0200 /media/gabor/CORSAIR/file.txt
As you can see, the seconds in the last modification time of the copied file are truncated to zero decimal digits. However, if I enter the command
if ! [ file.txt -nt /media/gabor/CORSAIR/file.txt ] && ! [ file.txt -ot /media/gabor/CORSAIR/file.txt ]; then echo "The last modification times are equal."; fi
I get the output
The last modification times are equal.
The situation changes if I unmount and remount the USB drive and I execute the last two commands again:
$ ls -l --time-style=full-iso /media/gabor/CORSAIR/file.txt -rw-r--r-- 1 gabor gabor 0 2018-09-22 15:09:22.000000000 +0200 /media/gabor/CORSAIR/file.txt $ if [ file.txt -nt /media/gabor/CORSAIR/file.txt ]; then echo "The file is newer on the PC."; fi The file is newer on the PC.
So after remount, the last modification time of the copied file is further reduced by one second. Further unmounting and remounting, however, doesn't affect the last modification time any more. Besides, the test on the files now shows that the file on the PC is newer (although it isn't).
The situation is further complicated by the fact that the last modification time of files is shown differently on my PC and on my laptop, the difference being exactly 2 hours, although the date and time setting is the same on my PC and on my laptop!
Both my PC and laptop show the behaviour, described above. I have Ubuntu 14.04.5 (trusty) on my PC and Ubuntu 16.04.2 (xenial) on my laptop.
My USB drives have vfat file system. The output of
mount | grep CORSAIR on my PC is
/dev/sdb1 on /media/gabor/CORSAIR type vfat (rw,nosuid,nodev,uid=1000,gid=1000,shortname=mixed,dmask=0077,utf8=1,showexec,flush,uhelper=udisks2)
The output of
mount | grep CORSAIR on my laptop is
/dev/sdb1 on /media/gabor/CORSAIR type vfat (rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,showexec,utf8,flush,errors=remount-ro,uhelper=udisks2)
My other USB drives show the same behaviour.
Can the difference in the last modification times be eliminated somehow? For example, using other parameters at mounting/unmounting? Or is it a bug in Ubuntu?
I would like to achieve that the timestamps of the original and copied files are exactly the same, so that synchronization can be done more efficiently. Also, I would like to keep the vfat file system on my USB drives, so that I can use them under Windows, too.