Skip to content

Instantly share code, notes, and snippets.

@joeperpetua
Created January 8, 2024 12:23

Revisions

  1. joeperpetua created this gist Jan 8, 2024.
    18 changes: 18 additions & 0 deletions increment_subdir_mtime.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    #!/bin/bash

    ####
    # Usage
    # ./increment_subdir_mtime.sh "path/to/parent/folder" increment_in_seconds:INT
    # eg:
    # ./increment_subdir_mtime.sh "/volume1/DATA/" 5
    ####

    TARGET_PATH=$(realpath "$1")
    INCREMENT=$2

    for folder in $(find "$TARGET_PATH" -mindepth 1 -type d)
    do
    current_mtime=$(stat -c %Y "$folder")
    let "new_mtime = current_mtime + $INCREMENT"
    touch -t $(date -d "@$new_mtime" +%Y%m%d%H%M.%S) "$folder"
    done