Skip to content

fix(touch): touch -t does not set file modification time #1157

@chaliy

Description

@chaliy

Summary

`touch -t TIMESTAMP FILE` exits successfully but does not actually modify the file's mtime. The file retains its original (current) timestamp.

Reproduction

echo "test" > /tmp/test.txt
touch -t 202604061200.00 /tmp/test.txt
date -r /tmp/test.txt +"%Y%m%d%H%M.%S"
# Expected: 202604061200.00
# Actual: current timestamp (e.g. 202604090246.10)

Context

Bashblog uses `touch -t` to preserve original post timestamps after rebuilding:

touch_timestamp=$(LC_ALL=C date -r "${1%%.*}.html" +"$date_format_timestamp")
# ... rebuild the file ...
touch -t "$touch_timestamp" "$filename"

Without working `touch -t`, post timestamps reset to the rebuild time, breaking chronological ordering of posts.

Expected behavior

`touch -t CCYYMMDDhhmm.ss FILE` should set the file's modification time to the specified timestamp.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions