#!/bin/sh ## Loop examining file until it stops changing (better than `watch ls -l FILE') ## Usage: ls_looped [-TIME] FILE ## TIME is the wait time (default: 10s) between checks (see `sleep --help') ## Example: ls_looped -5m foobar ## ls_looped v 0.2, (c) 2005-8 Adam Katz , license: GPL v2+ if [ $# = 0 ] || [ "$1" != "${1#-[-hHVv]}" ]; then sed -e '/^## /!d' -e 's///' "`which $0 2>/dev/null || echo $0`" # --help exit 0 fi [ "$1" != "${1#-}" ] && [ -n "$2" ] && time="${1##[-a-z]}" && shift while [ -n "$1" ]; do listing=`ls -lphd ${LS_COLORS:+--color=always} "$1"` printf "\r$(echo $listing)" # sleep for specified time; if it failed, reset time to 10s and use that if sleep $time 2>/dev/null; then true; else time=10; sleep $time; fi listing=`ls -l --full-time "$1" 2>/dev/null || ls -l "$1"` # ns (w/ failover) old2="$old1" # (keep track of extra instance in case full-time doesn't work) old1="$listing" [ "$listing" = "$old2" ] && break # assume we're done after 3 of the same done echo "" # the \n to end the last line