On 2004-08-24 17:15, Nathan Kinkade <[EMAIL PROTECTED]> wrote: > On Wed, Aug 25, 2004 at 12:16:17AM +0200, Joachim Dagerot wrote: > > A quiz easy to write, hard to answer? > > > > In bash, how can I write a command that moves the oldest file in a > > directory to a new direction? > > Here is one possible way, certainly there are many others: > > # ls -t /path/to/dir | tail -n 1 | xargs -i{} cp {} /path/to/location
In FreeBSD 5.X there's also stat(1) which can print the modification time of files in a numeric format and can be used in pipes like this: % stat -f '%m %N' * | sort -n | head -1 | cut -d ' ' -f 2- This should print the filename of the file with the oldest modification time. Access time or creation time can also be shown using the -f 'fmt' argument of stat(1) but details about that can be found in the stat(1) manpage. - Giorgos _______________________________________________ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"