If you want to apply a relative offset to the modification time of a file, you can do it with a combination of
stat(1). touch supports relative times, but they are relative to now, not the current time on a file. Instead you can use stat to get the current modification time and apply an offset.
For example, to apply a -2 hour offset to the modification time of a file:
touch -m -d @$(( $(stat -c %Y file.txt) - 7200 )) file.txt
stat -c %Y file.txt gets the modification time of
file.txt as seconds since the epoch. Using bash arithmetic expansion, you can perform calculations, which in this case is to subtract 7200 seconds (2 hours). Using touch with
-m to change the modification time and
-d to specify a date, you can set the modification time to what was calculated. The
@ is a time format specifier that says the given time is in seconds since the epoch.
If you put this into a shell script, you can call it from
xargs letting you use find to select the files you want to change.
for file ; do
touch -m -d @$(( $(stat -c %Y "$file") - 7200 )) "$file"
That will apply the change to the modification time of all files passed as arguments.