From owner-freebsd-questions@FreeBSD.ORG  Wed Aug 25 00:56:07 2004
Return-Path: <owner-freebsd-questions@FreeBSD.ORG>
Delivered-To: freebsd-questions@freebsd.org
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 0016416A4CE
	for <freebsd-questions@freebsd.org>;
	Wed, 25 Aug 2004 00:56:06 +0000 (GMT)
Received: from kane.otenet.gr (kane.otenet.gr [195.170.0.27])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 46D6C43D1D
	for <freebsd-questions@freebsd.org>;
	Wed, 25 Aug 2004 00:56:05 +0000 (GMT)
	(envelope-from keramida@ceid.upatras.gr)
Received: from gothmog.gr (patr530-a049.otenet.gr [212.205.215.49])
	i7P0twNV008806;	Wed, 25 Aug 2004 03:55:59 +0300
Received: from gothmog.gr (gothmog [127.0.0.1])
	by gothmog.gr (8.13.1/8.13.1) with ESMTP id i7P0sVRv028003;
	Wed, 25 Aug 2004 03:54:31 +0300 (EEST)
	(envelope-from keramida@ceid.upatras.gr)
Received: (from giorgos@localhost)
	by gothmog.gr (8.13.1/8.13.1/Submit) id i7P0sUau028002;
	Wed, 25 Aug 2004 03:54:30 +0300 (EEST)
	(envelope-from keramida@ceid.upatras.gr)
Date: Wed, 25 Aug 2004 03:54:30 +0300
From: Giorgos Keramidas <keramida@ceid.upatras.gr>
To: Joachim Dagerot <freebsd@dagerot.nu>
Message-ID: <20040825005430.GA27797@gothmog.gr>
References: <000001c489ff$1ab67f10$4b592650@yd5esbzvskxjc0a>
	<200408242216.i7OMGIp05050@thunder.trej.net>
	<20040824231510.GS3767@gentoo-npk.bmp.ub>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20040824231510.GS3767@gentoo-npk.bmp.ub>
Phone: +30-2610-312145
Mobile: +30-6944-116520
cc: freebsd-questions@freebsd.org
Subject: Re: Bash programming, copy only onefile?
X-BeenThere: freebsd-questions@freebsd.org
X-Mailman-Version: 2.1.1
Precedence: list
List-Id: User questions <freebsd-questions.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-questions>,
	<mailto:freebsd-questions-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-questions>
List-Post: <mailto:freebsd-questions@freebsd.org>
List-Help: <mailto:freebsd-questions-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-questions>,
	<mailto:freebsd-questions-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Wed, 25 Aug 2004 00:56:07 -0000

On 2004-08-24 17:15, Nathan Kinkade <nkinkade@ub.edu.bz> 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