0

I came across touch's option -B from this resource. According to the resource, by using the -B option of touch alongside reference (-r) option we can achieve the following:

The -B option modifies the timestamps by going back the specified number of seconds, and the -F option modifies the time by going forward the specified number of seconds. For example, the following command would make file7 30 seconds older than file6.

touch -r file6 -B 30 file7

But when I attempted this command, the option seems to be unavailable. The help page also does not mention either the forward (-F) or backward (-B). I get the following error:

touch: invalid option -- 'B'
Try 'touch --help' for more information.

Are these options removed or are there any other ways I can achieve these?

muru
  • 207,228
Chiranga Alwis
  • 113
  • 1
  • 8

1 Answers1

3

I'm unaware of the -B switch, but it can be accomplished with the -d option which can be used get a relative time from an existing file.

Example

touch -r temp.txt -d '-30 seconds' temp.txt.touch

Output Log

ubuntu@fmdev:~/t$ stat temp.txt
  File: 'temp.txt'
  Size: 2732        Blocks: 8          IO Block: 4096   regular file
Device: 801h/2049d  Inode: 293005      Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/  ubuntu)   Gid: ( 1000/  ubuntu)
Access: 2016-12-22 17:57:48.354526423 +0000
Modify: 2016-12-22 17:56:52.682704422 +0000
Change: 2016-12-22 17:56:52.682704422 +0000

ubuntu@fmdev:~/t$ touch -r temp.txt -d '-30 seconds' temp.txt.touch
ubuntu@fmdev:~/t$ stat temp.txt.touch
  File: 'temp.txt.touch'
  Size: 0           Blocks: 0          IO Block: 4096   regular empty file
Device: 801h/2049d  Inode: 256151      Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/  ubuntu)   Gid: ( 1000/  ubuntu)
Access: 2016-12-22 17:57:18.354526423 +0000
Modify: 2016-12-22 17:56:22.682704422 +0000
Change: 2017-02-10 14:34:22.805519094 +0000