#!/bin/sh - # # Copyright (C) 2007 by Oliver Fromme # # adjtouch -- modify the mtime of files, similar to touch(1). # However, in contrast to touch(1), the existing # mtime is adjusted by a given amount. # Please refer to description of the "-v" option # of date(1), because this script uses it! # # Example: "adjtouch -v +1H *" increases the mtime of all # files in the current directory by one hour. # # Important: This script uses FreeBSD-specific features, so # it works only on FreeBSD. # Usage() { echo "Usage: ${0##*/} -v ... ..." >&2 echo "Please read the date(1) manual page for details on the -v option." >&2 exit 1 } while :; do case "$1" in -v) ADJ_ARGS="$ADJ_ARGS -v $2" shift 2 ;; -v*) ADJ_ARGS="$ADJ_ARGS $1" shift ;; --) shift break ;; -) Usage ;; *) break ;; esac done if [ $# -lt 1 ]; then Usage fi # The following shell code looks unnecessarily complicated, # but it's written this way for a reason! # We don't use a "while read" loop because it would break # for file names that contain spaces or tabs. On the other # hand, we don't have to use xargs(1) for the stat(1) call # because the arguments will always fit, because this shell # script was called with the same arguments after all. stat -f%m "$@" \ | for n in "$@"; do read t d=$(date -r $t $ADJ_ARGS +"%Y%m%d%H%M.%S") \ || break touch -t $d "$n" done #--