What does Linux touch -h option do?

By default, touch command updates the timestamp of the actual file reference by a symbolic link instead of the symbolic link itself. But you can override this behavior using touch -h option to update the timestamp of the symbolic link itself.

Example:

Create an empty file

Create a symbolic link referencing the newly created file

Get the timestamp of the new file and symbolic link pointing to the new file

Observe, both the files have same timestamp

touch -h option example

Get the timestamp of the new file and symbolic link pointing to the new file

Observe, only the symbolic link timestamp got updated

touch default behavior

Get the timestamp of the new file and symbolic link pointing to the new file

Observe, only the actual file timestamp the symbolic link is pointing to got updated.

Leave a Reply